This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH v2][RFC] Canonize names of attributes.
- From: Jason Merrill <jason at redhat dot com>
- To: Martin Liška <mliska at suse dot cz>
- Cc: Joseph Myers <joseph at codesourcery dot com>, gcc-patches List <gcc-patches at gcc dot gnu dot org>, Richard Biener <richard dot guenther at gmail dot com>
- Date: Fri, 4 Aug 2017 12:53:39 -0400
- Subject: Re: [PATCH v2][RFC] Canonize names of attributes.
- Authentication-results: sourceware.org; auth=none
- References: <d34360a3-c245-7525-03e7-99a9ba8830e6@suse.cz> <CADzB+2mSLts01iKWZQ-dzZCEjZA-wX96_OHhd-6dmf4PrLVBNQ@mail.gmail.com> <1856059e-e9b1-63d2-717f-e20ec171b329@suse.cz> <alpine.DEB.2.20.1706281605270.25698@digraph.polyomino.org.uk> <CADzB+2nMBvm3vxJ59uCmVJpZEgrf3W6q17Q=DD9uhUbzeTvpDg@mail.gmail.com> <4cf00ee9-4cd7-1806-481f-966611768a15@suse.cz> <CADzB+2my3MZap45Bpb_sH7=j+JsBf2R2+S+7ETDdSW8yhBmDRA@mail.gmail.com> <8a0b2ff0-50f9-771d-fb63-01d17cb06b46@suse.cz> <CADzB+2=o6Wr1jyhk3P2JNYP92B0W6iLcZdgcb8GK3hdMTSjW4Q@mail.gmail.com> <669c960e-f4a8-eae3-efd2-f8c29477a817@suse.cz> <CADzB+2kHe_XW-7jqLNJN5RHgVp2y4TsrK_387yaFb8qSpQY1RA@mail.gmail.com> <e3bb65b3-38f7-08d1-05ab-629fdd9affc3@suse.cz> <alpine.DEB.2.20.1708021117180.19718@digraph.polyomino.org.uk> <2ea77331-480f-14f0-4d8c-20c10a127416@suse.cz>
On Fri, Aug 4, 2017 at 9:42 AM, Martin Liška <mliska@suse.cz> wrote:
> On 08/02/2017 01:25 PM, Joseph Myers wrote:
>> On Thu, 13 Jul 2017, Martin Liška wrote:
>>
>>> +/* For a given IDENTIFIER_NODE, strip leading and trailing '_' characters
>>> + so that we have a canonical form of attribute names. */
>>> +
>>> +static inline tree
>>> +canonicalize_attr_name (tree attr_name)
>>> +{
>>> + const size_t l = IDENTIFIER_LENGTH (attr_name);
>>> + const char *s = IDENTIFIER_POINTER (attr_name);
>>> +
>>> + if (l > 4 && s[0] == '_')
>>> + {
>>> + gcc_checking_assert (s[l - 2] == '_');
>>> + return get_identifier_with_length (s + 2, l - 4);
>>> + }
>>> +
>>> + return attr_name;
>>
>> For this to (a) be correct, (b) not trigger the assertion, there must be a
>> precondition that attr_name either starts and ends with __, or does not
>> start with _, or has length 4 or less. I don't see anything in the
>> callers to ensure this precondition holds, so that, for example,
>> __attribute__ ((_foobar)) does not trigger the assertion, and
>> __attribute__ ((_xformat__)) is not wrongly interpreted as a format
>> attribute (and similarly for attribute arguments when those are
>> canonicalized).
>
> Thanks for the review. I've updated to to canonicalize just __.+__.
> I added test-case for that: gcc/testsuite/gcc.dg/Wattributes-5.c.
>
>>
>>> +/* Compare attribute identifiers ATTR1 and ATTR2 with length ATTR1_LEN and
>>> + ATTR2_LEN. */
>>> +
>>> +static inline bool
>>> +cmp_attribs (const char *attr1, size_t attr1_len,
>>> + const char *attr2, size_t attr2_len)
>>> +{
>>> + gcc_checking_assert (attr1_len == 0 || attr1[0] != '_');
>>> + gcc_checking_assert (attr2_len == 0 || attr2[0] != '_');
>
> And I removed these asserts.
>
> Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.
>
> Ready to be installed?
OK.
Jason