aboutsummaryrefslogtreecommitdiff
path: root/gcc/gimple.c
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2013-01-07 15:34:43 +0000
committerRichard Biener <rguenth@gcc.gnu.org>2013-01-07 15:34:43 +0000
commit3626621a07bd682cb31ea832d2034776dde4e780 (patch)
tree4175c00ea44d892ce1035c8ff1cbaf29665e98fe /gcc/gimple.c
parent8b2ea410c7d5ccc14b94447d449abdc0b4d547ac (diff)
downloadgcc-3626621a07bd682cb31ea832d2034776dde4e780.zip
gcc-3626621a07bd682cb31ea832d2034776dde4e780.tar.gz
gcc-3626621a07bd682cb31ea832d2034776dde4e780.tar.bz2
re PR tree-optimization/55890 (calling a builtin func through a cast triggers an ICE)
2013-01-07 Richard Biener <rguenther@suse.de> PR middle-end/55890 * gimple.h (gimple_call_builtin_p): New overload. * gimple.c (validate_call): New function. (gimple_call_builtin_p): Likewise. * tree-ssa-structalias.c (find_func_aliases_for_builtin_call): Use gimple_call_builtin_p. (find_func_clobbers): Likewise. * tree-ssa-strlen.c (adjust_last_stmt): Likewise. (strlen_optimize_stmt): Likewise. * gcc.dg/torture/pr55890-1.c: New testcase. * gcc.dg/torture/pr55890-2.c: Likewise. From-SVN: r194975
Diffstat (limited to 'gcc/gimple.c')
-rw-r--r--gcc/gimple.c54
1 files changed, 49 insertions, 5 deletions
diff --git a/gcc/gimple.c b/gcc/gimple.c
index 5a53e00..4f4bac8 100644
--- a/gcc/gimple.c
+++ b/gcc/gimple.c
@@ -4137,16 +4137,60 @@ is_gimple_builtin_call (gimple stmt)
return false;
}
-/* Return true when STMT is builtins call to CODE. */
+/* Return true when STMTs arguments match those of FNDECL. */
+
+static bool
+validate_call (gimple stmt, tree fndecl)
+{
+ tree targs = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
+ unsigned nargs = gimple_call_num_args (stmt);
+ for (unsigned i = 0; i < nargs; ++i)
+ {
+ /* Variadic args follow. */
+ if (!targs)
+ return true;
+ tree arg = gimple_call_arg (stmt, i);
+ if (INTEGRAL_TYPE_P (TREE_TYPE (arg))
+ && INTEGRAL_TYPE_P (TREE_VALUE (targs)))
+ ;
+ else if (POINTER_TYPE_P (TREE_TYPE (arg))
+ && POINTER_TYPE_P (TREE_VALUE (targs)))
+ ;
+ else if (TREE_CODE (TREE_TYPE (arg))
+ != TREE_CODE (TREE_VALUE (targs)))
+ return false;
+ targs = TREE_CHAIN (targs);
+ }
+ if (targs && !VOID_TYPE_P (TREE_VALUE (targs)))
+ return false;
+ return true;
+}
+
+/* Return true when STMT is builtins call to CLASS. */
+
+bool
+gimple_call_builtin_p (gimple stmt, enum built_in_class klass)
+{
+ tree fndecl;
+ if (is_gimple_call (stmt)
+ && (fndecl = gimple_call_fndecl (stmt)) != NULL_TREE
+ && DECL_BUILT_IN_CLASS (fndecl) == klass)
+ return validate_call (stmt, fndecl);
+ return false;
+}
+
+/* Return true when STMT is builtins call to CODE of CLASS. */
bool
gimple_call_builtin_p (gimple stmt, enum built_in_function code)
{
tree fndecl;
- return (is_gimple_call (stmt)
- && (fndecl = gimple_call_fndecl (stmt)) != NULL
- && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL
- && DECL_FUNCTION_CODE (fndecl) == code);
+ if (is_gimple_call (stmt)
+ && (fndecl = gimple_call_fndecl (stmt)) != NULL_TREE
+ && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL
+ && DECL_FUNCTION_CODE (fndecl) == code)
+ return validate_call (stmt, fndecl);
+ return false;
}
/* Return true if STMT clobbers memory. STMT is required to be a