[PATCH] D153296: [AST] Stop evaluate constant expression if the condition expression which in switch statement contains errors

Shafik Yaghmour via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 22 20:31:13 PDT 2023


shafik added inline comments.


================
Comment at: clang/lib/AST/ExprConstant.cpp:4988
+      if (SS->getCond()->containsErrors() ||
+          !EvaluateDependentExpr(SS->getCond(), Info))
         return ESR_Failed;
----------------
yronglin wrote:
> erichkeane wrote:
> > It seems to me that the 'better' solution is to make EvaluateDependentExpr (or one of its children) be RecoveryExpr aware, and result in a failed value instead.  That way we get this 'fix' for more than just switch statements.
> Thanks for your review!
Erich so there are places in `ExprConstant.cpp` where if we  `isValueDependent()` we bail out like in the `Stmt::ReturnStmtClass` case inside `EvaluateStmt1()`. The gist I get from the comment there is 

```cpp
// We know we returned, but we don't know what the value is.
```

Is that not correct or does it depend on each specific case?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153296/new/

https://reviews.llvm.org/D153296



More information about the cfe-commits mailing list