On Fri, 22 Aug 2025, David Faust wrote:

> +    {
> +      /* Treat btf_type_tag applied to a function type as applying to the
> +      return type instead.  Otherwise with GNU syntax there is no way to
> +      apply type_tag to the return type; the parser always associates it
> +      to the function_type node.  btf_decl_tag can (should) be used to
> +      annotate the function itself.  */
> +      tree ret_type = TREE_TYPE (*node);
> +      tree new_attrs = tree_cons (name, args, TYPE_ATTRIBUTES (ret_type));
> +      tree new_type = build_type_attribute_qual_variant (ret_type,
> +                                                      new_attrs,
> +                                                      TYPE_QUALS (ret_type));
> +      *node = lang_hooks.types.reconstruct_complex_type (*node, new_type);

I don't think reconstruct_complex_type is actually right here; at least 
the C version is quite specific to vector attributes and will recurse down 
when given a pointer type, which is not what's wanted here (if the 
function returns a pointer, I think you want to stop at that point, not 
recurse down and end up replacing the innermost type).  So you should be 
reconstructing the function type directly given the new return type rather 
than doing something that would do more reconstruction within the return 
type.  Now c_reconstruct_complex_type does

      outer = c_build_function_type (inner, TYPE_ARG_TYPES (type),
                                     TYPE_NO_NAMED_ARGS_STDARG_P (type));

for its reconstruction of a function type, which is using a function 
c_build_function_type not available for C++; I don't know what you should 
do here (apart from adding another language hook) to ensure the 
appropriate language-specific function type construction in this c-family 
code.

-- 
Joseph S. Myers
[email protected]

Reply via email to