Author: erichkeane
Date: 2025-05-20T06:31:13-07:00
New Revision: 2f66e5fcbad211e0d71b1a533071d31b36f088ec

URL: 
https://github.com/llvm/llvm-project/commit/2f66e5fcbad211e0d71b1a533071d31b36f088ec
DIFF: 
https://github.com/llvm/llvm-project/commit/2f66e5fcbad211e0d71b1a533071d31b36f088ec.diff

LOG: [OpenACC] Fixed error recovery during jump diagnostics for OpenACC

We didn't consider/test a case where the structured block/loop would be
empty, which happens when the body is ONLY a break.

Fixes: #140712

Added: 
    clang/test/SemaOpenACC/gh140712.cpp

Modified: 
    clang/lib/Sema/JumpDiagnostics.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/JumpDiagnostics.cpp 
b/clang/lib/Sema/JumpDiagnostics.cpp
index a852a950b47f4..36704c3826dfd 100644
--- a/clang/lib/Sema/JumpDiagnostics.cpp
+++ b/clang/lib/Sema/JumpDiagnostics.cpp
@@ -602,7 +602,10 @@ void JumpScopeChecker::BuildScopeInformation(Stmt *S,
     Scopes.push_back(GotoScope(
         ParentScope, diag::note_acc_branch_into_compute_construct,
         diag::note_acc_branch_out_of_compute_construct, CC->getBeginLoc()));
-    BuildScopeInformation(CC->getStructuredBlock(), NewParentScope);
+    // This can be 'null' if the 'body' is a break that we diagnosed, so no
+    // reason to put the scope into place.
+    if (CC->getStructuredBlock())
+      BuildScopeInformation(CC->getStructuredBlock(), NewParentScope);
     return;
   }
 
@@ -612,7 +615,10 @@ void JumpScopeChecker::BuildScopeInformation(Stmt *S,
     Scopes.push_back(GotoScope(
         ParentScope, diag::note_acc_branch_into_compute_construct,
         diag::note_acc_branch_out_of_compute_construct, CC->getBeginLoc()));
-    BuildScopeInformation(CC->getLoop(), NewParentScope);
+    // This can be 'null' if the 'body' is a break that we diagnosed, so no
+    // reason to put the scope into place.
+    if (CC->getLoop())
+      BuildScopeInformation(CC->getLoop(), NewParentScope);
     return;
   }
 

diff  --git a/clang/test/SemaOpenACC/gh140712.cpp 
b/clang/test/SemaOpenACC/gh140712.cpp
new file mode 100644
index 0000000000000..ca1b6234be72d
--- /dev/null
+++ b/clang/test/SemaOpenACC/gh140712.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 %s -fopenacc -verify
+
+void foo() {
+  switch (int x = 0) {
+    case 0:
+#pragma acc parallel
+      break; // expected-error{{invalid branch out of OpenACC Compute/Combined 
Construct}}
+  }
+}


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to