On Thu, 18 Dec 2025, Qing Zhao wrote: > > > On Dec 18, 2025, at 14:33, Joseph Myers <[email protected]> wrote: > > > > On Thu, 11 Dec 2025, Qing Zhao wrote: > > > >> diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc > >> index 0a368e410e5..35a70414cff 100644 > >> --- a/gcc/c/c-decl.cc > >> +++ b/gcc/c/c-decl.cc > >> @@ -9083,6 +9083,11 @@ grokfield (location_t loc, > >> width ? &width : NULL, decl_attrs, expr, NULL, > >> DEPRECATED_NORMAL); > >> > >> + /* When this field has name, its type is a top level type, we should > >> + call verify_counted_by_for_top_anonymous_type. */ > >> + if (DECL_NAME (value) != NULL_TREE) > >> + verify_counted_by_for_top_anonymous_type (TREE_TYPE (value)); > > > > So this is using the type of the field, as opposed to the type from the > > declaration specifiers. > > So, for the following: > > struct s { struct { int a; char b[] __attribute__ ((counted_by (a))); } *x; } > *y; > > When the routine “grokfield” is handling the field “x”, the declspecs->type > points to the anonymous structure, > But the TREE_TYPE(value) is the "pointer to the anonymous structure"?
Yes. > Okay, I just read the routine “grokdeclarator” in more details, and see that > the final type for the declarator is build from > > declspecs->type + declarator->kind (which might be one of cdk_attrs, > cdk_array, cdk_function, or cdk_pointer) > > So, checking “declspecs->type” directly will avoid to track POINTER_TYPE_P, > FUNCTION_TYPE, ARRAY_TYPE, etc. > > Is this understanding correct? Yes. grokdeclarator processes all the nested declarators to determine the type resulting from the combination of declarator and declaration specifiers. -- Joseph S. Myers [email protected]
