[clang] [clang][AST] Fix crash on labeled break/continue within switch condition statement expression (PR #228655)
Oliver Hunt via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 6 23:57:01 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;
----------------
ojhunt wrote:
Yeah, I've got `optional<T*>` returns in a number of places but every time someone complains that `optional<T*>` should just be `T*` with value vs nullptr :-/ (this is one of those places where the lack of an code level "can this be pointer be null" in many of our APIs is annoying)
https://github.com/llvm/llvm-project/pull/228655
More information about the cfe-commits
mailing list