On Thu, 24 Oct 2024, alfie.richa...@arm.com wrote:

> -      if (DECL_INITIAL (newdecl))
> +      if ((DECL_INITIAL (newdecl) || DECL_EXTERNAL (newdecl))
> +       && (DECL_INITIAL (olddecl) || DECL_EXTERNAL (olddecl))
> +       && targetm.target_option.function_versions (newdecl, olddecl))
> +     {
> +       /* Check if we are dealing with Function Multi Versioning using
> +        the 'target_version' attribute.  */
> +       tree olddecl_args = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
> +       tree newdecl_args = TYPE_ARG_TYPES (TREE_TYPE (newdecl));
> +       /* Function Multi Versioned functions need to have the same
> +          prototype and the target must support these too, otherwise
> +          error.
> +          TODO: should we be checking any other properties?  */
> +       if (!comptypes (TREE_TYPE (olddecl), TREE_TYPE (newdecl))
> +           || !comptypes (olddecl_args, newdecl_args))

olddecl_args and newdecl_args are lists, not types; you can't call 
comptypes on them.  comptypes_internal eventually calls 
function_types_compatible_p to check compatibility of function types; you 
should probably use comptypes on the types as a whole rather than 
reimplementing the various checks it does.  Note that you need to consider 
if e.g. you want to allow one function being prototyped and the other 
unprototyped (but compatible) - whether you want something stricter than 
compatibility (e.g. the "same type" notion).

Whatever the conclusion, please make sure there is thorough testsuite 
coverage for the various cases of types that might be the same, or 
compatible but not the same (one prototyped and one unprototyped; both 
prototyped but one having more information than the other, e.g. parameter 
pointing to an array where the array size is specified for only one), as 
well as cases that are not compatible.  I don't see any dg-error tests in 
this patch, so testsuite coverage needs to be expanded.

> @@ -3191,6 +3240,14 @@ duplicate_decls (tree newdecl, tree olddecl)
>        return false;
>      }
>  
> +  /* If both new and old are Function Multi Versioned functions then they are
> +     not duplicates.  */
> +  if (TREE_CODE (newdecl) == FUNCTION_DECL
> +      && TREE_CODE (olddecl) == FUNCTION_DECL
> +      && DECL_FUNCTION_VERSIONED (newdecl)
> +      && DECL_FUNCTION_VERSIONED (olddecl))
> +    return false;

Is that really the case?  I'd expect duplicates to be possible if there 
are multiple declarations of the same version of the function.  So there 
should be tests in the testsuite both for valid cases of declaring the 
same version multiple times, in the same or different scopes, and invalid 
cases that define the same version multiple times.

-- 
Joseph S. Myers
josmy...@redhat.com

Reply via email to