]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gimplify: Don't add GIMPLE_ASSUME if errors were seen [PR107369]
authorJakub Jelinek <jakub@redhat.com>
Tue, 25 Oct 2022 08:39:20 +0000 (10:39 +0200)
committerJakub Jelinek <jakub@redhat.com>
Tue, 25 Oct 2022 08:39:20 +0000 (10:39 +0200)
The FEs emit errors about jumps into assume attribute conditions,
but when we add GIMPLE_ASSUME for the condition which is reachable
through those jumps, we can run into cfg verification diagnostics.

Fixed by throwing the IFN_ASSUME away during gimplification if
seen_error () - like we already do for -O0.  GIMPLE_ASSUME in the middle-end
is a pure optimization thing and if errors were reported, the optimizations
will not be beneficial for anything.

2022-10-25  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/107369
* gimplify.cc (gimplify_call_expr): If seen_error, handle complex
IFN_ASSUME the same as for -O0.

* gcc.dg/attr-assume-4.c: New test.
* g++.dg/cpp23/attr-assume8.C: New test.

gcc/gimplify.cc
gcc/testsuite/g++.dg/cpp23/attr-assume8.C [new file with mode: 0644]
gcc/testsuite/gcc.dg/attr-assume-4.c [new file with mode: 0644]

index 69bad340d2edea470647654a74d48d1aa730d694..44cc9e6677ba124321e79ee1205663a31bace626 100644 (file)
@@ -3568,7 +3568,7 @@ gimplify_call_expr (tree *expr_p, gimple_seq *pre_p, bool want_value)
              return GS_OK;
            }
          /* If not optimizing, ignore the assumptions.  */
-         if (!optimize)
+         if (!optimize || seen_error ())
            {
              *expr_p = NULL_TREE;
              return GS_ALL_DONE;
diff --git a/gcc/testsuite/g++.dg/cpp23/attr-assume8.C b/gcc/testsuite/g++.dg/cpp23/attr-assume8.C
new file mode 100644 (file)
index 0000000..3c7a62f
--- /dev/null
@@ -0,0 +1,12 @@
+// PR tree-optimization/107369
+// { dg-do compile { target c++11 } }
+// { dg-options "-O1" }
+
+void
+foo (int x)
+{
+  if (x == 1)
+    goto l1;                   // { dg-message "from here" }
+
+  [[assume (({ l1:; 1; }))]];  // { dg-error "jump to label 'l1'" }
+}                              // { dg-message "enters statement expression" "" { target *-*-* } .-1 }
diff --git a/gcc/testsuite/gcc.dg/attr-assume-4.c b/gcc/testsuite/gcc.dg/attr-assume-4.c
new file mode 100644 (file)
index 0000000..e8a2b8d
--- /dev/null
@@ -0,0 +1,12 @@
+/* PR tree-optimization/107369 */
+/* { dg-do compile } */
+/* { dg-options "-std=c2x -O1" } */
+
+void
+foo (int x)
+{
+  if (x == 1)
+    goto l1;                           /* { dg-error "jump into statement expression" } */
+
+  [[gnu::assume (({ l1:; 1; }))]];     /* { dg-message "label 'l1' defined here" } */
+}