gimple.cc: Adjust gimple_call_builtin_p and gimple_call_combined_fn [PR105150]
On Tue, Apr 05, 2022 at 11:28:53AM +0200, Richard Biener wrote: > > In GIMPLE, we call: > > && gimple_builtin_call_types_compatible_p (stmt, fndecl) > > but that is insufficient, that verifies whether the arguments passed to > > GIMPLE_CALL match the fndecl argument types. But that fndecl may very well > > be the user declaration, so doesn't have to match exactly the builtin > > as predeclared by builtins.def etc. (though, there is the cotcha that say > > for FILE * we just use void * etc.). So e.g. in tree-ssa-strlen.cc > > we use additional: > > tree callee = gimple_call_fndecl (stmt); > > tree decl = builtin_decl_explicit (DECL_FUNCTION_CODE (callee)); > > if (decl > > && decl != callee > > && !gimple_builtin_call_types_compatible_p (stmt, decl)) > > return false; > > Yeah, I think we should use that (and only that) function decl > in get_call_combined_fn and gimple_call_combined_fn until the > frontend stops slapping wrong BUILT_IN_* on random decls. So, as a preparation step, this patch adjusts gimple_call_builtin_p and gimple_call_combined_fn so that they check argument types against the builtin_decl_explicit TYPE_ARG_TYPES rather than against the actual used fndecl. 2022-04-06 Jakub Jelinek <jakub@redhat.com> PR tree-optimization/105150 * gimple.cc (gimple_call_builtin_p, gimple_call_combined_fn): For BUILT_IN_NORMAL calls, call gimple_builtin_call_types_compatible_p preferrably on builtin_decl_explicit decl rather than fndecl. * tree-ssa-strlen.cc (valid_builtin_call): Don't call gimple_builtin_call_types_compatible_p here.
This commit is contained in:
parent
d037d9ad32
commit
71770a0ea9
|
@ -2841,7 +2841,12 @@ gimple_call_builtin_p (const gimple *stmt)
|
|||
if (is_gimple_call (stmt)
|
||||
&& (fndecl = gimple_call_fndecl (stmt)) != NULL_TREE
|
||||
&& DECL_BUILT_IN_CLASS (fndecl) != NOT_BUILT_IN)
|
||||
return gimple_builtin_call_types_compatible_p (stmt, fndecl);
|
||||
{
|
||||
if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)
|
||||
if (tree decl = builtin_decl_explicit (DECL_FUNCTION_CODE (fndecl)))
|
||||
fndecl = decl;
|
||||
return gimple_builtin_call_types_compatible_p (stmt, fndecl);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -2854,7 +2859,12 @@ gimple_call_builtin_p (const gimple *stmt, enum built_in_class klass)
|
|||
if (is_gimple_call (stmt)
|
||||
&& (fndecl = gimple_call_fndecl (stmt)) != NULL_TREE
|
||||
&& DECL_BUILT_IN_CLASS (fndecl) == klass)
|
||||
return gimple_builtin_call_types_compatible_p (stmt, fndecl);
|
||||
{
|
||||
if (klass == BUILT_IN_NORMAL)
|
||||
if (tree decl = builtin_decl_explicit (DECL_FUNCTION_CODE (fndecl)))
|
||||
fndecl = decl;
|
||||
return gimple_builtin_call_types_compatible_p (stmt, fndecl);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -2867,7 +2877,11 @@ gimple_call_builtin_p (const gimple *stmt, enum built_in_function code)
|
|||
if (is_gimple_call (stmt)
|
||||
&& (fndecl = gimple_call_fndecl (stmt)) != NULL_TREE
|
||||
&& fndecl_built_in_p (fndecl, code))
|
||||
return gimple_builtin_call_types_compatible_p (stmt, fndecl);
|
||||
{
|
||||
if (tree decl = builtin_decl_explicit (DECL_FUNCTION_CODE (fndecl)))
|
||||
fndecl = decl;
|
||||
return gimple_builtin_call_types_compatible_p (stmt, fndecl);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -2884,10 +2898,14 @@ gimple_call_combined_fn (const gimple *stmt)
|
|||
return as_combined_fn (gimple_call_internal_fn (call));
|
||||
|
||||
tree fndecl = gimple_call_fndecl (stmt);
|
||||
if (fndecl
|
||||
&& fndecl_built_in_p (fndecl, BUILT_IN_NORMAL)
|
||||
&& gimple_builtin_call_types_compatible_p (stmt, fndecl))
|
||||
return as_combined_fn (DECL_FUNCTION_CODE (fndecl));
|
||||
if (fndecl && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL))
|
||||
{
|
||||
tree decl = builtin_decl_explicit (DECL_FUNCTION_CODE (fndecl));
|
||||
if (!decl)
|
||||
decl = fndecl;
|
||||
if (gimple_builtin_call_types_compatible_p (stmt, decl))
|
||||
return as_combined_fn (DECL_FUNCTION_CODE (fndecl));
|
||||
}
|
||||
}
|
||||
return CFN_LAST;
|
||||
}
|
||||
|
|
|
@ -1736,12 +1736,6 @@ valid_builtin_call (gimple *stmt)
|
|||
return false;
|
||||
|
||||
tree callee = gimple_call_fndecl (stmt);
|
||||
tree decl = builtin_decl_explicit (DECL_FUNCTION_CODE (callee));
|
||||
if (decl
|
||||
&& decl != callee
|
||||
&& !gimple_builtin_call_types_compatible_p (stmt, decl))
|
||||
return false;
|
||||
|
||||
switch (DECL_FUNCTION_CODE (callee))
|
||||
{
|
||||
case BUILT_IN_MEMCMP:
|
||||
|
|
Loading…
Reference in New Issue