From patchwork Mon Dec 10 23:30:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 1010781 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-492036-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="nAGV+Nwo"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="HmgplKqh"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43DK8F6by6z9s3q for ; Tue, 11 Dec 2018 10:31:07 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:message-id:date:mime-version:content-type; q=dns; s= default; b=qJAy5s5/0iApTf8Jukuc4SsK9LDj3sNUFDM/1WVUA1mR5fuJE0dTF NlQhK/HpOTTuwt2aMJWNaUerUg+X/lrrsiEiEGWQ0+s5rN89Ruym99EUxTXFYwGp dvbkBJVGv2Mv4QmXViO6e1ohx2O4n8sCq2gekzfmGajdVSyGt2JVJQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:message-id:date:mime-version:content-type; s= default; bh=tYallWFhdkCmB28iWtRJBHzjeKM=; b=nAGV+Nwo+N9Xg0XK2Wuu HuuIAMGC3o2VKXmUrbt3OxyCz01Vlc9GXc6VUg3hMs7Lx9iW6dS/6HwvgJdABGme /qjU85O2byc9ZYwgSEoNBr1dhYPit5tGf8HErLL2YxCI/Qa/AWejKo0+LfbXhLJu zwpj8BmLhfUYYXoqJHQuerc= Received: (qmail 96907 invoked by alias); 10 Dec 2018 23:30:59 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 96786 invoked by uid 89); 10 Dec 2018 23:30:42 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-16.9 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS, TIME_LIMIT_EXCEEDED autolearn=unavailable version=3.3.2 spammy=exposed, 9s, referred, nonetheless X-HELO: mail-qt1-f175.google.com Received: from mail-qt1-f175.google.com (HELO mail-qt1-f175.google.com) (209.85.160.175) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 10 Dec 2018 23:30:22 +0000 Received: by mail-qt1-f175.google.com with SMTP id e5so14391899qtr.12 for ; Mon, 10 Dec 2018 15:30:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:subject:to:message-id:date:user-agent:mime-version :content-language; bh=Mkv7Ry+zPwIY+nszVUyu/vFerN2rVN5cBP1ILA2zycU=; b=HmgplKqhe8W8+0HvBhoz4t/LifRlOjY10Yj/moKd++WFdSrv9We7h6mDJUYmL9zDkV LW2TsN/Y7db8r9rq9DdSxe1iJ9cwr10hujvjX4plwznS6FJTAmBCGknZBXmGvQrjtwBZ s8G3g0HHPPSTzfm0tduO9TsmC09pBcg6IskgVUeUSKLLg6vWS0CQuqsz8StcjvrxAKfb PJ3VQvJdVbSOfJZutS8AwPfnufJgdFKQ3kg7OF9rqLKVph3WdgXdYZb1NsIe9ZTbf2Uf YVvlhU7hEn6j8MHdDYunQnPM+vrdTKjvfdNd6di/Maqi6YTdGLjn+qMag39Xl/44I2Bu OdVg== Received: from localhost.localdomain (97-118-99-160.hlrn.qwest.net. [97.118.99.160]) by smtp.gmail.com with ESMTPSA id b17sm7316528qkj.69.2018.12.10.15.30.12 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Dec 2018 15:30:12 -0800 (PST) From: Martin Sebor Subject: [PATCH] accept all C integer types in function parameters referenced by alloc_align (PR 88363) To: Gcc Patch List Message-ID: <0f3f1395-adac-8b5f-82e4-e656bf1207fb@gmail.com> Date: Mon, 10 Dec 2018 16:30:11 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.1 MIME-Version: 1.0 X-IsSubscribed: yes Some of my testing exposed a minor problem in GCC 9's validation of the type of function parameters referred to by attribute positional arguments. Whereas GCC 8 accepts all C integer types, including enumerated types, such as: enum AllocAlign { Align16 = 16, Align32 = 32 }; __attribute__ ((alloc_align (1))) void* alloc (size_t, enum AllocAlign) GCC 9 only accepts signed and unsigned integer types. This change (introduced by myself) was unintentional, and a fix for it is in the attached trivial patch. I plan to commit it without approval in the next day or so unless any concerns or suggestions come up. Tested on x86_64-linux. Martin PR c/88363 - alloc_align attribute doesn't accept enumerated arguments gcc/c-family/ChangeLog: PR c/88363 * c-attribs.c (positional_argument): Also accept enumerated types. gcc/testsuite/ChangeLog: PR c/88363 * c-c++-common/attributes-4.c: New test. gcc/ChangeLog: PR c/88363 * doc/extend.texi (attribute alloc_align, alloc_size): Update. Index: gcc/c-family/c-attribs.c =================================================================== --- gcc/c-family/c-attribs.c (revision 266963) +++ gcc/c-family/c-attribs.c (working copy) @@ -630,11 +630,11 @@ positional_argument (const_tree fntype, const_tree return NULL_TREE; } - /* Where the expected code is STRING_CST accept any pointer - to a narrow character type, qualified or otherwise. */ bool type_match; if (code == STRING_CST && POINTER_TYPE_P (argtype)) { + /* Where the expected code is STRING_CST accept any pointer + to a narrow character type, qualified or otherwise. */ tree type = TREE_TYPE (argtype); type = TYPE_MAIN_VARIANT (type); type_match = (type == char_type_node @@ -641,6 +641,10 @@ positional_argument (const_tree fntype, const_tree || type == signed_char_type_node || type == unsigned_char_type_node); } + else if (code == INTEGER_TYPE) + /* For integers, accept bool, enums, and other types that + match INTEGRAL_TYPE_P. */ + type_match = INTEGRAL_TYPE_P (argtype); else type_match = TREE_CODE (argtype) == code; Index: gcc/doc/extend.texi =================================================================== --- gcc/doc/extend.texi (revision 266963) +++ gcc/doc/extend.texi (working copy) @@ -2471,7 +2471,8 @@ The @code{aligned} attribute can also be used for @item alloc_align (@var{position}) @cindex @code{alloc_align} function attribute The @code{alloc_align} attribute may be applied to a function that -returns a pointer and takes at least one argument of an integer type. +returns a pointer and takes at least one argument of an integer or +enumerated type. It indicates that the returned pointer is aligned on a boundary given by the function argument at @var{position}. Meaningful alignments are powers of 2 greater than one. GCC uses this information to improve @@ -2495,7 +2496,8 @@ given by parameter 1. @itemx alloc_size (@var{position-1}, @var{position-2}) @cindex @code{alloc_size} function attribute The @code{alloc_size} attribute may be applied to a function that -returns a pointer and takes at least one argument of an integer type. +returns a pointer and takes at least one argument of an integer or +enumerated type. It indicates that the returned pointer points to memory whose size is given by the function argument at @var{position-1}, or by the product of the arguments at @var{position-1} and @var{position-2}. Meaningful Index: gcc/testsuite/c-c++-common/attributes-4.c =================================================================== --- gcc/testsuite/c-c++-common/attributes-4.c (nonexistent) +++ gcc/testsuite/c-c++-common/attributes-4.c (working copy) @@ -0,0 +1,46 @@ +/* PR c/88363 - alloc_align attribute doesn't accept enumerated arguments + Verify that attribute positional arguments can refer to all C integer + types in both C and C++. + { dg-do compile } + { dg-options "-Wall" } + { dg-options "-Wall -Wno-c++-compat" { target c } } */ + +#define ATTR(...) __attribute__ ((__VA_ARGS__)) + +#if __cplusplus == 199711L +typedef __CHAR16_TYPE__ char16_t; +typedef __CHAR32_TYPE__ char32_t; +#elif !__cplusplus +typedef _Bool bool; +typedef __CHAR16_TYPE__ char16_t; +typedef __CHAR32_TYPE__ char32_t; +typedef __WCHAR_TYPE__ wchar_t; +#endif + +enum A { A0 }; + +/* Using bool here is of marginal utility but it's accepted nonetheless. */ +ATTR (alloc_align (1)) void* falloc_align_bool (bool); +ATTR (alloc_align (1)) void* falloc_align_char (char); +ATTR (alloc_align (1)) void* falloc_align_char16 (char16_t); +ATTR (alloc_align (1)) void* falloc_align_char32 (char32_t); +ATTR (alloc_align (1)) void* falloc_align_wchar (wchar_t); +/* Using an enum might make sense in an API that limits the alignments + it accepts to just the set of the defined enumerators. */ +ATTR (alloc_align (1)) void* falloc_align_enum (enum A); +ATTR (alloc_align (1)) void* falloc_align_int128 (__int128_t); + +ATTR (alloc_size (1)) void* falloc_size_bool (bool); +ATTR (alloc_align (1)) void* falloc_size_char (char); +ATTR (alloc_size (1)) void* falloc_size_char16 (char16_t); +ATTR (alloc_size (1)) void* falloc_size_char32 (char32_t); +ATTR (alloc_size (1)) void* falloc_size_wchar (wchar_t); +ATTR (alloc_size (1)) void* falloc_size_enum (enum A); +ATTR (alloc_align (1)) void* falloc_size_int128 (__int128_t); + + +typedef struct { int i; } S; + +ATTR (alloc_align (1)) void* falloc_align_float (float); /* { dg-warning "attribute argument value .1. refers to parameter type .float" } */ +ATTR (alloc_align (1)) void* falloc_align_voidp (void*); /* { dg-warning "attribute argument value .1. refers to parameter type .void ?\\\*" } */ +ATTR (alloc_align (1)) void* falloc_align_struct (S); /* { dg-warning "attribute argument value .1. refers to parameter type .S" } */