[clang] Fix ForStmt mustprogress handling
authorAtmn Patel <a335pate@uwaterloo.ca>
Mon, 9 Nov 2020 13:19:44 +0000 (08:19 -0500)
committerAtmn Patel <a335pate@uwaterloo.ca>
Mon, 9 Nov 2020 16:38:06 +0000 (11:38 -0500)
D86841 had an error where for statements with no conditional were
required to make progress. This is not true, this patch removes that
line, and adds regression tests.

Differential Revision: https://reviews.llvm.org/D91075

clang/lib/CodeGen/CGStmt.cpp
clang/test/CodeGen/attr-mustprogress-1.c
clang/test/CodeGen/attr-mustprogress-1.cpp

index 972da3d..d8be0ef 100644 (file)
@@ -947,7 +947,6 @@ void CodeGenFunction::EmitForStmt(const ForStmt &S,
   Expr::EvalResult Result;
   if (LanguageRequiresProgress()) {
     if (!S.getCond()) {
-      LoopMustProgress = true;
       FnIsMustProgress = false;
     } else if (!S.getCond()->EvaluateAsInt(Result, getContext())) {
       LoopMustProgress = true;
index a5a8595..2ff068b 100644 (file)
@@ -8,6 +8,17 @@ int a = 0;
 int b = 0;
 
 // CHECK: Function Attrs: noinline nounwind optnone
+// CHECK-LABEL: @f0(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    br label [[FOR_COND:%.*]]
+// CHECK:       for.cond:
+// CHECK-NOT:    br label [[FOR_COND]], !llvm.loop !{{.*}}
+//
+void f0() {
+  for (; ;) ;
+}
+
+// CHECK: Function Attrs: noinline nounwind optnone
 // CHECK-LABEL: @f1(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:    br label [[FOR_COND:%.*]]
index 6d53d2d..945d746 100644 (file)
@@ -8,6 +8,16 @@ int a = 0;
 int b = 0;
 
 // CHECK: Function Attrs: noinline nounwind optnone
+// CHECK-LABEL: @_Z2f0v(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    br label [[FOR_COND:%.*]]
+// CHECK:       for.cond:
+// CHECK-NOT:    br label [[FOR_COND]], !llvm.loop !{{.*}}
+void f0() {
+  for (; ;) ;
+}
+
+// CHECK: Function Attrs: noinline nounwind optnone
 // CHECK-LABEL: @_Z2f1v(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:    br label [[FOR_COND:%.*]]