================
@@ -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;
----------------
Sirraide wrote:

I think `getNamedLoopOrSwitch()` returning nullptr when `hasLabelTarget()` is 
true can only happen during constant evaluation, because we try and evaluate an 
expression that contains a labelled `break`/`continue` whose `LabelDecl` hasn’t 
been created yet. 

During codegen or after we’re done w/ Sema, this shouldn’t really ever happen. 
Perhaps renaming `hasLabelTarget()` to `isNamed()` or sth like that might make 
it clearer what that function actually checks for.

> `std::pair<bool, *>`? (a more general, well out of scope for this PR, option 
> would be a result type)

I’d go with `std::optional<Stmt *>` if we want to do that, along w/ a comment 
that explains the three possible states are (1. not labelled, 2. labelled, but 
the LabelDecl doesn’t exist yet, 3. labelled and it does exist).

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

Reply via email to