Hi! The 3 functions in builtins.c that dispatch builtin folding give up if avoid_folding_inline_builtin (fndecl) returns true, because we want to wait with those functions until they are inlined (which for -D_FORTIFY_SOURCE contains security checks). Unfortunately gimple_fold_builtin calls fold_builtin_str* etc. directly and thus bypasses this check. This didn't show up often because most of the inlines have __restrict arguments and restrict casts weren't considered useless.
Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, preapproved by richi on IRC, will commit to trunk momentarily. 2011-10-06 Jakub Jelinek <ja...@redhat.com> * tree.h (avoid_folding_inline_builtin): New prototype. * builtins.c (avoid_folding_inline_builtin): No longer static. * gimple-fold.c (gimple_fold_builtin): Give up if avoid_folding_inline_builtin returns true. --- gcc/tree.h.jj 2011-10-03 14:27:50.000000000 +0200 +++ gcc/tree.h 2011-10-06 13:26:32.000000000 +0200 @@ -5352,6 +5352,7 @@ fold_build_pointer_plus_hwi_loc (locatio fold_build_pointer_plus_hwi_loc (UNKNOWN_LOCATION, p, o) /* In builtins.c */ +extern bool avoid_folding_inline_builtin (tree); extern tree fold_call_expr (location_t, tree, bool); extern tree fold_builtin_fputs (location_t, tree, tree, bool, bool, tree); extern tree fold_builtin_strcpy (location_t, tree, tree, tree, tree); --- gcc/builtins.c.jj 2011-10-05 08:13:55.000000000 +0200 +++ gcc/builtins.c 2011-10-06 13:25:39.000000000 +0200 @@ -10360,7 +10360,7 @@ fold_builtin_varargs (location_t loc, tr been inlined, otherwise e.g. -D_FORTIFY_SOURCE checking might not be performed. */ -static bool +bool avoid_folding_inline_builtin (tree fndecl) { return (DECL_DECLARED_INLINE_P (fndecl) --- gcc/gimple-fold.c.jj 2011-10-06 09:14:17.000000000 +0200 +++ gcc/gimple-fold.c 2011-10-06 13:29:08.000000000 +0200 @@ -828,6 +828,11 @@ gimple_fold_builtin (gimple stmt) if (DECL_BUILT_IN_CLASS (callee) == BUILT_IN_MD) return NULL_TREE; + /* Give up for always_inline inline builtins until they are + inlined. */ + if (avoid_folding_inline_builtin (callee)) + return NULL_TREE; + /* If the builtin could not be folded, and it has no argument list, we're done. */ nargs = gimple_call_num_args (stmt); Jakub