[clang] 6dc9a48 - [clang][bytecode] Handle missing target label in break statement (#180532)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 9 21:55:15 PST 2026
Author: Timm Baeder
Date: 2026-02-10T06:55:10+01:00
New Revision: 6dc9a484fde9378d466b5626687197924f66115c
URL: https://github.com/llvm/llvm-project/commit/6dc9a484fde9378d466b5626687197924f66115c
DIFF: https://github.com/llvm/llvm-project/commit/6dc9a484fde9378d466b5626687197924f66115c.diff
LOG: [clang][bytecode] Handle missing target label in break statement (#180532)
Happens in error cases.
Added:
Modified:
clang/lib/AST/ByteCode/Compiler.cpp
clang/test/AST/ByteCode/invalid.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 05941649c73be..b4af1c80b1f36 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -6042,7 +6042,9 @@ bool Compiler<Emitter>::visitBreakStmt(const BreakStmt *S) {
}
}
- assert(TargetLabel);
+ // Faulty break statement (e.g. label redefined or named loops disabled).
+ if (!TargetLabel)
+ return false;
for (VariableScope<Emitter> *C = this->VarScope; C != BreakScope;
C = C->getParent()) {
diff --git a/clang/test/AST/ByteCode/invalid.cpp b/clang/test/AST/ByteCode/invalid.cpp
index c8298fa2c2b9b..f7d11a9be3f8e 100644
--- a/clang/test/AST/ByteCode/invalid.cpp
+++ b/clang/test/AST/ByteCode/invalid.cpp
@@ -151,3 +151,16 @@ namespace NullRecord {
};
S2 s = S2();
}
+
+namespace NamedLoops {
+ constexpr int foo() {
+ bar: // both-note {{previous definition is here}} \
+ // both-warning {{use of this statement in a constexpr function is a C++23 extension}}
+ return 0;
+
+ bar: // both-error {{redefinition of label 'bar'}}
+ do {
+ break bar; // both-error {{named 'break' is only supported in C2y}}
+ } while (0);
+ }
+}
More information about the cfe-commits
mailing list