diff options
| author | Timm Baeder <tbaeder@redhat.com> | 2025-11-06 12:52:11 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-11-06 12:52:11 +0100 |
| commit | e4467fbf3077ff0d2ae9f600df129dc11fa35c0f (patch) | |
| tree | 8eeb0cbdf0b4d3921f3f0a87362b0ed99b3bd5cd /clang/lib/AST/ExprConstant.cpp | |
| parent | ee0818a1f1fab4303eeb1263ac1f6b22f3fe2110 (diff) | |
[clang][ExprConst] Handle dependent switch case statements (#166533)
By rejecting them.
Fixes https://github.com/llvm/llvm-project/issues/165555
Diffstat (limited to 'clang/lib/AST/ExprConstant.cpp')
| -rw-r--r-- | clang/lib/AST/ExprConstant.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 8fab6efafb98..193f87ca1807 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -5452,10 +5452,13 @@ static EvalStmtResult EvaluateSwitch(StmtResult &Result, EvalInfo &Info, } const CaseStmt *CS = cast<CaseStmt>(SC); - APSInt LHS = CS->getLHS()->EvaluateKnownConstInt(Info.Ctx); - APSInt RHS = CS->getRHS() ? CS->getRHS()->EvaluateKnownConstInt(Info.Ctx) - : LHS; - if (LHS <= Value && Value <= RHS) { + const Expr *LHS = CS->getLHS(); + const Expr *RHS = CS->getRHS(); + if (LHS->isValueDependent() || (RHS && RHS->isValueDependent())) + return ESR_Failed; + APSInt LHSValue = LHS->EvaluateKnownConstInt(Info.Ctx); + APSInt RHSValue = RHS ? RHS->EvaluateKnownConstInt(Info.Ctx) : LHSValue; + if (LHSValue <= Value && Value <= RHSValue) { Found = SC; break; } |
