https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/180532
Happens in error cases. >From 14524c4d3bfebb8b9bc1693c609371be10e8e5db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]> Date: Mon, 9 Feb 2026 15:35:36 +0100 Subject: [PATCH] [clang][bytecode] Handle missing target label in break statement --- clang/lib/AST/ByteCode/Compiler.cpp | 4 +++- clang/test/AST/ByteCode/invalid.cpp | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index a0138c402e143..58871fe79b36d 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -6036,7 +6036,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); + } +} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
