[backport gcc-4.8/trunk r194316, there was no ChangeLog entry for the new test case ] gcc/cp/ 2012-12-07 Aldy Hernandez PR c++/55513 * semantics.c (cxx_eval_builtin_function_call): Set non_constant_p after folding. --- gcc-4.7.2/gcc/cp/semantics.c.~1~ 2012-09-13 17:15:06.000000000 +0200 +++ gcc-4.7.2/gcc/cp/semantics.c 2012-12-09 11:52:18.000000000 +0100 @@ -46,6 +46,13 @@ along with GCC; see the file COPYING3. #include "gimple.h" #include "bitmap.h" +static bool verify_constant (tree, bool, bool *); +#define VERIFY_CONSTANT(X) \ +do { \ + if (verify_constant ((X), allow_non_constant, non_constant_p)) \ + return t; \ + } while (0) + /* There routines provide a modular interface to perform many parsing operations. They may therefore be used during actual parsing, or during template instantiation, which may be regarded as a @@ -6383,7 +6390,9 @@ cxx_eval_builtin_function_call (const co return t; new_call = build_call_array_loc (EXPR_LOCATION (t), TREE_TYPE (t), CALL_EXPR_FN (t), nargs, args); - return fold (new_call); + new_call = fold (new_call); + VERIFY_CONSTANT (new_call); + return new_call; } /* TEMP is the constant value of a temporary object of type TYPE. Adjust @@ -6687,11 +6696,6 @@ verify_constant (tree t, bool allow_non_ } return *non_constant_p; } -#define VERIFY_CONSTANT(X) \ -do { \ - if (verify_constant ((X), allow_non_constant, non_constant_p)) \ - return t; \ - } while (0) /* Subroutine of cxx_eval_constant_expression. Attempt to reduce the unary expression tree T to a compile time value. --- gcc-4.7.2/gcc/testsuite/g++.dg/pr55513.C.~1~ 1970-01-01 01:00:00.000000000 +0100 +++ gcc-4.7.2/gcc/testsuite/g++.dg/pr55513.C 2012-12-09 12:01:31.000000000 +0100 @@ -0,0 +1,12 @@ +// { dg-do compile } +// { dg-options "-O0 -fdump-tree-gimple" } + +main () +{ + char s[10]; + const int t = (__builtin_memcpy (s, "Hello", 6), 777); + __builtin_printf ("%d %s\n", t, s); +} + +// { dg-final { scan-tree-dump-times "memcpy" 1 "gimple" } } +// { dg-final { cleanup-tree-dump "gimple" } }