https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/168332

Fixes https://github.com/llvm/llvm-project/issues/156801

We can't return a `RecoveryExpr` here since the functions returns a 
`StmtResult`. Just add those statements to the AST without the target.

I'm not entirely sure if we should do the same thing in `Sema::ActOnBreakStmt`, 
but I think so.

>From 1a20b18ce796488e72808887b259a473fcc5ef10 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]>
Date: Mon, 17 Nov 2025 09:17:16 +0100
Subject: [PATCH] [clang] Add break/continue stmts with missing lable to the
 AST

Fixes https://github.com/llvm/llvm-project/issues/156801
---
 clang/lib/Parse/ParseStmt.cpp                          |  4 +---
 .../test/SemaCXX/labeled-break-continue-constexpr.cpp  | 10 +++++++++-
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp
index 7e73d89c2a18c..f9141cabf0e6a 100644
--- a/clang/lib/Parse/ParseStmt.cpp
+++ b/clang/lib/Parse/ParseStmt.cpp
@@ -2313,10 +2313,8 @@ StmtResult Parser::ParseBreakOrContinueStatement(bool 
IsContinue) {
       // TODO: Make this a compatibility/extension warning instead once the
       // syntax of this feature is finalised.
       Diag(LabelLoc, diag::err_c2y_labeled_break_continue) << IsContinue;
-    if (!Target) {
+    if (!Target)
       Diag(LabelLoc, diag::err_break_continue_label_not_found) << IsContinue;
-      return StmtError();
-    }
   }
 
   if (IsContinue)
diff --git a/clang/test/SemaCXX/labeled-break-continue-constexpr.cpp 
b/clang/test/SemaCXX/labeled-break-continue-constexpr.cpp
index d1b57adca91c1..cc45887ab3817 100644
--- a/clang/test/SemaCXX/labeled-break-continue-constexpr.cpp
+++ b/clang/test/SemaCXX/labeled-break-continue-constexpr.cpp
@@ -1,6 +1,5 @@
 // RUN: %clang_cc1 -fnamed-loops -std=c++23 -fsyntax-only -verify %s
 // RUN: %clang_cc1 -fnamed-loops -std=c++23 -fsyntax-only -verify %s 
-fexperimental-new-constant-interpreter
-// expected-no-diagnostics
 
 struct Tracker {
   bool& destroyed;
@@ -168,3 +167,12 @@ constexpr T f12() {
 }
 static_assert(f12<int>() == 93);
 static_assert(f12<unsigned>() == 93u);
+
+
+constexpr int labelNotFound() {
+  a: for (;;) {
+    break azzz; // expected-error {{'break' label does not name an enclosing 
loop or 'switch'}}
+  }
+  return 1;
+}
+static_assert(labelNotFound() == 1);

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to