diff options
author | Jakub Jelinek <jakub@redhat.com> | 2008-12-10 00:01:15 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2008-12-10 00:01:15 +0100 |
commit | 0889e9bc6841c76484e029eeed31f85a35ae4e55 (patch) | |
tree | f58c3d091da63db8a731136167c34e30bcf310d2 /gcc/builtins.c | |
parent | 218d1c24bb8bd00b49a4c9097b5777a2c25ba231 (diff) | |
download | gcc-0889e9bc6841c76484e029eeed31f85a35ae4e55.zip gcc-0889e9bc6841c76484e029eeed31f85a35ae4e55.tar.gz gcc-0889e9bc6841c76484e029eeed31f85a35ae4e55.tar.bz2 |
re PR middle-end/38454 (memcpy folding breaks -D_FORTIFY_SOURCE=2 protection)
PR middle-end/38454
* function.h (struct function): Add always_inline_functions_inlined.
* ipa-inline.c (cgraph_early_inlining): Set it to true.
* tree-optimize.c (execute_fixup_cfg): Likewise.
* builtins.c (avoid_folding_inline_builtin): New function.
(fold_call_expr): Don't optimize always_inline builtins before
inlining.
(fold_call_stmt): Likewise.
(fold_builtin_call_array): Likewise. Don't call
fold_builtin_varargs for BUILT_IN_MD builtins.
* gcc.dg/memset-1.c: New test.
* gcc.dg/memcpy-2.c: New test.
From-SVN: r142617
Diffstat (limited to 'gcc/builtins.c')
-rw-r--r-- | gcc/builtins.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/gcc/builtins.c b/gcc/builtins.c index 745a125..afb3b3f 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -10797,6 +10797,22 @@ fold_builtin_varargs (tree fndecl, tree exp, bool ignore ATTRIBUTE_UNUSED) return NULL_TREE; } +/* Return true if FNDECL shouldn't be folded right now. + If a built-in function has an inline attribute always_inline + wrapper, defer folding it after always_inline functions have + been inlined, otherwise e.g. -D_FORTIFY_SOURCE checking + might not be performed. */ + +static bool +avoid_folding_inline_builtin (tree fndecl) +{ + return (DECL_DECLARED_INLINE_P (fndecl) + && DECL_DISREGARD_INLINE_LIMITS (fndecl) + && cfun + && !cfun->always_inline_functions_inlined + && lookup_attribute ("always_inline", DECL_ATTRIBUTES (fndecl))); +} + /* A wrapper function for builtin folding that prevents warnings for "statement without effect" and the like, caused by removing the call node earlier than the warning is generated. */ @@ -10829,6 +10845,9 @@ fold_call_expr (tree exp, bool ignore) return NULL_TREE; } + if (avoid_folding_inline_builtin (fndecl)) + return NULL_TREE; + /* FIXME: Don't use a list in this interface. */ if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_MD) return targetm.fold_builtin (fndecl, CALL_EXPR_ARGS (exp), ignore); @@ -10931,6 +10950,8 @@ fold_builtin_call_array (tree type, && DECL_FUNCTION_CODE (fndecl2) == BUILT_IN_VA_ARG_PACK) return build_call_array (type, fn, n, argarray); } + if (avoid_folding_inline_builtin (fndecl)) + return build_call_array (type, fn, n, argarray); if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_MD) { tree arglist = NULL_TREE; @@ -10939,6 +10960,7 @@ fold_builtin_call_array (tree type, ret = targetm.fold_builtin (fndecl, arglist, false); if (ret) return ret; + return build_call_array (type, fn, n, argarray); } else if (n <= MAX_ARGS_TO_FOLD_BUILTIN) { @@ -13647,6 +13669,8 @@ fold_call_stmt (gimple stmt, bool ignore) { int nargs = gimple_call_num_args (stmt); + if (avoid_folding_inline_builtin (fndecl)) + return NULL_TREE; /* FIXME: Don't use a list in this interface. */ if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_MD) { |