Patchwork PR c++/55513: do not fold away builtins in COMPOUND_EXPRs

login
register
mail settings
Submitter Aldy Hernandez
Date Dec. 7, 2012, 8:43 p.m.
Message ID <50C254E2.6080508@redhat.com>
Download mbox | patch
Permalink /patch/204606/
State New
Headers show

Comments

Aldy Hernandez - Dec. 7, 2012, 8:43 p.m.
On 12/07/12 14:28, Jason Merrill wrote:
> On 12/07/2012 01:08 PM, Aldy Hernandez wrote:
>> +  if (!TREE_CONSTANT (new_call))
>> +    *non_constant_p = true;
>
> You can use VERIFY_CONSTANT here instead.  OK with that change.
>
> Jason
>

VERIFY_CONSTANT is defined further down, so I moved things around.

OK with these changes, or would you rather me rearrange things differently?
commit 7ba66e780950761d286ce40db8c457d9d8bfd744
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Fri Dec 7 10:40:25 2012 -0600

    	PR c++/55513
    	* semantics.c (cxx_eval_builtin_function_call): Set non_constant_p
    	after folding.
Jason Merrill - Dec. 8, 2012, 12:31 a.m.
OK.

Jason

Patch

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 491d97c..92b4a2b 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -45,6 +45,13 @@  along with GCC; see the file COPYING3.  If not see
 #include "bitmap.h"
 #include "hash-table.h"
 
+static bool verify_constant (tree, bool, bool *, bool *);
+#define VERIFY_CONSTANT(X)						\
+do {									\
+  if (verify_constant ((X), allow_non_constant, non_constant_p, overflow_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
@@ -6437,7 +6444,9 @@  cxx_eval_builtin_function_call (const constexpr_call *call, tree t,
     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
@@ -6738,11 +6747,6 @@  verify_constant (tree t, bool allow_non_constant, bool *non_constant_p,
     }
   return *non_constant_p;
 }
-#define VERIFY_CONSTANT(X)						\
-do {									\
-  if (verify_constant ((X), allow_non_constant, non_constant_p, overflow_p)) \
-    return t;								\
- } while (0)
 
 /* Subroutine of cxx_eval_constant_expression.
    Attempt to reduce the unary expression tree T to a compile time value.
diff --git a/gcc/testsuite/g++.dg/pr55513.C b/gcc/testsuite/g++.dg/pr55513.C
new file mode 100644
index 0000000..06eedee
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr55513.C
@@ -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" } }