aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2022-04-06 10:07:26 +0200
committerJakub Jelinek <jakub@redhat.com>2022-04-06 10:07:26 +0200
commit71770a0ea920641c53912f725f5abd4413b38fd5 (patch)
tree9eafdc174f3c4a47617cd40723939fd1f858793f
parentd037d9ad323ec9eef3e50c6e2cbc1e31191daa5d (diff)
downloadgcc-71770a0ea920641c53912f725f5abd4413b38fd5.zip
gcc-71770a0ea920641c53912f725f5abd4413b38fd5.tar.gz
gcc-71770a0ea920641c53912f725f5abd4413b38fd5.tar.bz2
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.
-rw-r--r--gcc/gimple.cc32
-rw-r--r--gcc/tree-ssa-strlen.cc6
2 files changed, 25 insertions, 13 deletions
diff --git a/gcc/gimple.cc b/gcc/gimple.cc
index 5559e56..4953bf4 100644
--- a/gcc/gimple.cc
+++ b/gcc/gimple.cc
@@ -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;
}
diff --git a/gcc/tree-ssa-strlen.cc b/gcc/tree-ssa-strlen.cc
index b255636..9ae25d1 100644
--- a/gcc/tree-ssa-strlen.cc
+++ b/gcc/tree-ssa-strlen.cc
@@ -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: