re PR c++/13239 (Assertion does not seem to work correctly anymore)
authorJakub Jelinek <jakub@redhat.com>
Fri, 19 Dec 2003 13:39:05 +0000 (14:39 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 19 Dec 2003 13:39:05 +0000 (14:39 +0100)
PR c++/13239
* builtins.c (expand_builtin_expect_jump): Update
TREE_VALUE (arglist) if unsave_expr_now langhook
created a new tree.

* g++.dg/opt/expect1.C: New test.

From-SVN: r74832

gcc/ChangeLog
gcc/builtins.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/opt/expect1.C [new file with mode: 0644]

index f2865dcbb40a6c8953b033057079e16fedda67f4..dec8a807a4b7aa46465dfd7b836c3a74c124c428 100644 (file)
@@ -1,3 +1,10 @@
+2003-12-19  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/13239
+       * builtins.c (expand_builtin_expect_jump): Update
+       TREE_VALUE (arglist) if unsave_expr_now langhook
+       created a new tree.
+
 2003-12-19  Richard Earnshaw  <rearnsha@arm.com>
 
        * arm.c (thumb_base_register_rtx_p): Use regno in comparison against
index ba6244636600728ea178f283cccfb0ed2bef84a4..d3dfb8824d75f38aa4d254abb63ce4b823485ddb 100644 (file)
@@ -4460,6 +4460,14 @@ expand_builtin_expect_jump (tree exp, rtx if_false_label, rtx if_true_label)
       ret = get_insns ();
       end_sequence ();
 
+      /* For mildly unsafe builtin jump's, if unsave_expr_now
+        creates a new tree instead of changing the old one
+        TREE_VALUE (arglist) needs to be updated.  */
+      if (arg0 != TREE_VALUE (arglist)
+         && TREE_CODE (arg0) == UNSAVE_EXPR
+         && TREE_OPERAND (arg0, 0) != TREE_VALUE (arglist))
+       TREE_VALUE (arglist) = TREE_OPERAND (arg0, 0);
+
       /* Now that the __builtin_expect has been validated, go through and add
         the expect's to each of the conditional jumps.  If we run into an
         error, just give up and generate the 'safe' code of doing a SCC
index 073216aba1bc00d605081925c0bc02a5e2304395..3010412fce19b631322831608df82fe28a77658b 100644 (file)
@@ -1,3 +1,8 @@
+2003-12-19  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/13239
+       * g++.dg/opt/expect1.C: New test.
+
 2003-12-19  Hartmut Penner  <hpenner@de.ibm.com>
 
        * gcc.dg/altivec-varargs-1.c: Enable testcase on ppc linux.
diff --git a/gcc/testsuite/g++.dg/opt/expect1.C b/gcc/testsuite/g++.dg/opt/expect1.C
new file mode 100644 (file)
index 0000000..90a871f
--- /dev/null
@@ -0,0 +1,17 @@
+// PR c++/13239
+// { dg-do run }
+// { dg-options "-O2" }
+
+extern "C" void abort (void);
+
+struct Y {
+  int i;
+};
+
+bool foo () { return true; }
+Y bar () { Y y = {0}; return y; }
+
+int main ()
+{
+  __builtin_expect (foo () && (bar ().i) == 0, 0) ? 0 : (abort (), 1);
+}