> On Sep 17, 2024, at 07:05, Jakub Jelinek <ja...@redhat.com> wrote: > > On Tue, Sep 17, 2024 at 11:13:09AM +0200, Jakub Jelinek wrote: >> So maybe better >> tree arg = e_p->value; >> tree f; >> if ((in_typeof || in_alignof) >> && TREE_CODE (arg) == COMPONENT_REF >> && (f = TREE_OPERAND (arg, 1)) >> && TREE_CODE (f) == FIELD_DECL >> && c_flexible_array_member_type_p (TREE_TYPE (f)) >> && lookup_attribute ("counted_by", DECL_ATTRIBUTES (f)) >> && DECL_NAME (f)) > > Of course with > { > auto save_in_typeof = in_typeof; > auto save_in_alignof = in_alignof; > in_typeof = 0; > in_alignof = 0; >> arg = build_component_ref (EXPR_LOCATION (arg), >> TREE_OPERAND (arg, 0), >> DECL_NAME (f), UNKNOWN_LOCATION, >> UNKNOWN_LOCATION, true); > in_typeof = save_in_typeof; > in_alignof = save_in_alignof; > }
Yeah, the “save_in_typeof/alignof” is needed. -:) > Why don't we have the sentinel classes C++ FE has in the C FE? Sorry for the stupid question: could you please explain the above a little bit more? What’s the sentinel classes? And how should we use it here? > > Or outline the counted_by specific part of build_component_ref into > a separate function and call just that. Yeah, this looks like a good idea to me, I will try to split the counted_by specific part of build_component_ref into a separate function, that might make the code cleaner and also get rid of the unnecessary global variable “in_builtin_counted_by_ref”. >> if (has_counted_by_object (arg)) >> expr.value = get_counted_by_ref (arg); >> else >> expr.value = null_pointer_node; > > BTW, concerning just counted_by attribute, how does it play together > with _Atomic on the size member? > Perhaps it should be disallowed. Do you mean for the following: struct t { _Atomic int size; char array[] __attribute__ ((counted_by (size)) }; We should emit error and disallow it at this moment? Thanks. Qing > > The thing is that _Atomic access lowering is done in the FE, so too > early for tree-object-size, which would either need to reimplement it by > hand (sure, not that difficult, it needs to just atomically load). > > Jakub >