Skip to content

Commit

Permalink
rs6000, add argument to function find_instance
Browse files Browse the repository at this point in the history
GCC maintainers:

The rs6000 function find_instance assumes that it is called for built-
ins with only two arguments.  There is no checking for the actual
number of aruguments used in the built-in.  This patch adds an
additional parameter to the function call containing the number of
aruguments in the built-in.  The function will now do the needed checks
for all of the arguments.

This fix is needed for the next patch in the series that fixes the
vec_replace_unaligned built-in.c test.

Please let me know if this patch is acceptable for mainline.  Thanks.

                        Carl

--------------------------------------------
rs6000, add argument to function find_instance

The function find_instance assumes it is called to check a built-in  with
only two arguments.  Ths patch extends the function by adding a parameter
specifying the number of buit-in arguments to check.

gcc/ChangeLog:
	* config/rs6000/rs6000-c.cc (find_instance): Add new parameter that
	specifies the number of built-in arguments to check.
	(altivec_resolve_overloaded_builtin): Update calls to find_instance
	to pass the number of built-in argument to be checked.
  • Loading branch information
carlelove authored and ouuleilei-bot committed Jul 17, 2023
1 parent c2d62cd commit 52a4c22
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions gcc/config/rs6000/rs6000-c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1674,7 +1674,7 @@ tree
find_instance (bool *unsupported_builtin, ovlddata **instance,
rs6000_gen_builtins instance_code,
rs6000_gen_builtins fcode,
tree *types, tree *args)
tree *types, tree *args, int nargs)
{
while (*instance && (*instance)->bifid != instance_code)
*instance = (*instance)->next;
Expand All @@ -1686,17 +1686,28 @@ find_instance (bool *unsupported_builtin, ovlddata **instance,
if (!inst->fntype)
return error_mark_node;
tree fntype = rs6000_builtin_info[inst->bifid].fntype;
tree parmtype0 = TREE_VALUE (TYPE_ARG_TYPES (fntype));
tree parmtype1 = TREE_VALUE (TREE_CHAIN (TYPE_ARG_TYPES (fntype)));
tree argtype = TYPE_ARG_TYPES (fntype);
tree parmtype;
int args_compatible = true;

if (rs6000_builtin_type_compatible (types[0], parmtype0)
&& rs6000_builtin_type_compatible (types[1], parmtype1))
for (int i = 0; i <nargs; i++)
{
parmtype = TREE_VALUE (argtype);
if (! rs6000_builtin_type_compatible (types[i], parmtype))
{
args_compatible = false;
break;
}
argtype = TREE_CHAIN (argtype);
}

if (args_compatible)
{
if (rs6000_builtin_decl (inst->bifid, false) != error_mark_node
&& rs6000_builtin_is_supported (inst->bifid))
{
tree ret_type = TREE_TYPE (inst->fntype);
return altivec_build_resolved_builtin (args, 2, fntype, ret_type,
return altivec_build_resolved_builtin (args, nargs, fntype, ret_type,
inst->bifid, fcode);
}
else
Expand Down Expand Up @@ -1916,7 +1927,7 @@ altivec_resolve_overloaded_builtin (location_t loc, tree fndecl,
instance_code = RS6000_BIF_CMPB_32;

tree call = find_instance (&unsupported_builtin, &instance,
instance_code, fcode, types, args);
instance_code, fcode, types, args, nargs);
if (call != error_mark_node)
return call;
break;
Expand Down Expand Up @@ -1949,7 +1960,7 @@ altivec_resolve_overloaded_builtin (location_t loc, tree fndecl,
}

tree call = find_instance (&unsupported_builtin, &instance,
instance_code, fcode, types, args);
instance_code, fcode, types, args, nargs);
if (call != error_mark_node)
return call;
break;
Expand Down

0 comments on commit 52a4c22

Please sign in to comment.