[clang] [clang][AST] Fix crash on labeled break/continue within switch condition statement expression (PR #228655)

Timm Baeder via cfe-commits cfe-commits at lists.llvm.org
Sat Oct 3 21:43:05 PDT 2026


================
@@ -1533,9 +1533,9 @@ const Stmt *LabelStmt::getInnermostLabeledStmt() const {
 }
 
 const Stmt *LoopControlStmt::getNamedLoopOrSwitch() const {
-  if (!hasLabelTarget())
-    return nullptr;
-  return getLabelDecl()->getStmt()->getInnermostLabeledStmt();
+  assert(hasLabelTarget());
+  LabelStmt *Label = getLabelDecl()->getStmt();
+  return Label ? Label->getInnermostLabeledStmt() : nullptr;
----------------
tbaederr wrote:

So this function may return null anyway, what's the point of adding all the `hasLabelTarget` checks?

https://github.com/llvm/llvm-project/pull/228655


More information about the cfe-commits mailing list