> On Oct 4, 2022, at 1:37 PM, Joseph Myers <jos...@codesourcery.com> wrote:
> 
> On Tue, 4 Oct 2022, Qing Zhao via Gcc-patches wrote:
> 
>> +  { "strict_flex_array",      1, 1, false, false, false, false,
>> +                          handle_strict_flex_array_attribute, NULL },
> 
> You're not requiring that the attribute be applied to a declaration here.

Okay, so, you mean I need to require the attribute to be applied to a 
declaration as following:

 { "strict_flex_array",      1, 1, true, false, false, false,
                              handle_strict_flex_array_attribute, NULL },

?

Then when the attribute is attached to the type of the decl, the ICE will not 
happen? (Yes, I tried, and the ICE was replaced with the following warning:

/home/opc/Install/lates/bin/gcc t.c
t.c:1:1: warning: ‘strict_flex_array’ attribute does not apply to types 
[-Wattributes]
    1 | int [[gnu::strict_flex_array(1)]] x;
      | ^~~

Thanks, I will update the patch with this.

Let me know if you have more comments.

Qing

> 
>> +static tree
>> +handle_strict_flex_array_attribute (tree *node, tree name,
>> +                                tree args, int ARG_UNUSED (flags),
>> +                                bool *no_add_attrs)
>> +{
>> +  tree decl = *node;
>> +  tree argval = TREE_VALUE (args);
>> +
>> +  /* This attribute only applies to field decls of a structure.  */
>> +  if (TREE_CODE (decl) != FIELD_DECL)
>> +    {
>> +      error_at (DECL_SOURCE_LOCATION (decl),
>> +            "%qE attribute may not be specified for %q+D", name, decl);
> 
> But here you're using DECL_SOURCE_LOCATION on what might be a type, not a 
> DECL.  So if you have a test such as
> 
> int [[gnu::strict_flex_array(1)]] x;
> 
> that applies the attribute to a type, you get an ICE:
> 
> t.c:1:1: internal compiler error: tree check: expected tree that contains 
> 'decl minimal' structure, have 'integer_type' in 
> handle_strict_flex_array_attribute, at c-family/c-attribs.cc:2526
>    1 | int [[gnu::strict_flex_array(1)]] x;
>      | ^~~
> 
> -- 
> Joseph S. Myers
> jos...@codesourcery.com

Reply via email to