From: Martin Sebor <msebor@gmail.com>
To: Jeff Law <law@redhat.com>, Gcc Patch List <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] handle expressions in __builtin_has_attribute (PR 88383)
Date: Thu, 13 Dec 2018 19:21:00 -0000 [thread overview]
Message-ID: <5599edd4-61ad-24ce-d19e-376dd9398183@gmail.com> (raw)
In-Reply-To: <6b1f15b6-1446-21a2-54aa-b92ec6b5541f@redhat.com>
On 12/13/18 11:59 AM, Jeff Law wrote:
> On 12/5/18 8:55 PM, Martin Sebor wrote:
>> The __builtin_has_attribute function fails with an ICE when
>> its first argument is an expression such as INDIRECT_REF, or
>> many others.  The code simply assumes it's either a type or
>> a decl.  The attached patch corrects this oversight.
>>
>> While testing the fix I also noticed the C++ front end expects
>> the first operand to be a unary expression, which causes most
>> other kinds of expressions to be rejected.  The patch fixes
>> that as well.
>>
>> Finally, while testing the fix even more I realized that
>> the built-in considers the underlying array itself in ARRAY_REF
>> expressions rather than its type, which leads to inconsistent
>> results for overaligned arrays (it's the array itself that's
>> overaligned, not its elements).  So I fixed that too and
>> adjusted the one test designed to verify this.
>>
>> Tested on x86_64-linux.
>>
>> Martin
>>
>> gcc-88383.diff
>>
>> PR c/88383 - ICE calling __builtin_has_attribute on a reference
>>
>> gcc/c-family/ChangeLog:
>>
>> PR c/88383
>> * c-attribs.c (validate_attribute): Handle expressions.
>> (has_attribute): Handle types referenced by expressions.
>> Avoid considering array attributes in ARRAY_REF expressions .
>>
>> gcc/cp/ChangeLog:
>>
>> PR c/88383
>> * parser.c (cp_parser_has_attribute_expression): Handle assignment
>> expressions.
>>
>> gcc/testsuite/ChangeLog:
>>
>> PR c/88383
>> * c-c++-common/builtin-has-attribute-4.c: Adjust expectations.
>> * c-c++-common/builtin-has-attribute-6.c: New test.
> Well, the high level question here is do we want to support this builtin
> on expressions at all. Generally attributes apply to types and decls,
> not expressions.
>
> Clearly we shouldn't fault, but my first inclination is that the
> attribute applies to types or decls, not expressions. In that case we
> should just be issuing an error.
>
> I could be convinced otherwise, so if you think we should support
> passing expressions to this builtin, make your case.
The support is necessary in order to determine the attributes
in expressions such as:
struct S { __attribute__ ((packed)) int a[32]; };
extern struct S s;
_Static_assert (__builtin_has_attribute (s.a, packed));
Martin
next prev parent reply other threads:[~2018-12-13 19:21 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-06 3:56 Martin Sebor
2018-12-13 18:59 ` Jeff Law
2018-12-13 19:21 ` Martin Sebor [this message]
2018-12-13 19:48 ` Martin Sebor
2018-12-13 19:56 ` Jakub Jelinek
2018-12-13 22:22 ` Martin Sebor
2018-12-13 23:40 ` Jakub Jelinek
2018-12-14 4:04 ` Martin Sebor
2018-12-14 7:41 ` Jakub Jelinek
2018-12-15 0:18 ` Martin Sebor
2018-12-21 2:56 ` Martin Sebor
2019-01-03 22:22 ` PING " Martin Sebor
2019-01-08 0:32 ` PING #2 " Martin Sebor
2019-01-15 16:31 ` Martin Sebor
2019-01-17 1:16 ` Jeff Law
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5599edd4-61ad-24ce-d19e-376dd9398183@gmail.com \
--to=msebor@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=law@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).