aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaChecking.cpp
diff options
context:
space:
mode:
authorMark de Wever <koraq@xs4all.nl>2020-08-16 18:32:38 +0200
committerMark de Wever <koraq@xs4all.nl>2020-08-16 18:32:38 +0200
commit827ba67e383313b05e9b10c8215e501530d6c9e3 (patch)
treec6791b7450a49c3585fd705a54e0dd1acddf5459 /clang/lib/Sema/SemaChecking.cpp
parentf25d47b7ed3e2e9ddb121471c5d4af76642cd48c (diff)
downloadllvm-827ba67e383313b05e9b10c8215e501530d6c9e3.zip
llvm-827ba67e383313b05e9b10c8215e501530d6c9e3.tar.gz
llvm-827ba67e383313b05e9b10c8215e501530d6c9e3.tar.bz2
[Sema] Validate calls to GetExprRange.
When a conditional expression has a throw expression it called GetExprRange with a void expression, which caused an assertion failure. This approach was suggested by Richard Smith. Fixes PR46484: Clang crash in clang/lib/Sema/SemaChecking.cpp:10028 Differential Revision: https://reviews.llvm.org/D85601
Diffstat (limited to 'clang/lib/Sema/SemaChecking.cpp')
-rw-r--r--clang/lib/Sema/SemaChecking.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index bbd856e..4efd62f 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -10368,10 +10368,16 @@ static IntRange GetExprRange(ASTContext &C, const Expr *E, unsigned MaxWidth,
MaxWidth, InConstantContext);
// Otherwise, conservatively merge.
- IntRange L =
- GetExprRange(C, CO->getTrueExpr(), MaxWidth, InConstantContext);
- IntRange R =
- GetExprRange(C, CO->getFalseExpr(), MaxWidth, InConstantContext);
+ // GetExprRange requires an integer expression, but a throw expression
+ // results in a void type.
+ Expr *E = CO->getTrueExpr();
+ IntRange L = E->getType()->isVoidType()
+ ? IntRange{0, true}
+ : GetExprRange(C, E, MaxWidth, InConstantContext);
+ E = CO->getFalseExpr();
+ IntRange R = E->getType()->isVoidType()
+ ? IntRange{0, true}
+ : GetExprRange(C, E, MaxWidth, InConstantContext);
return IntRange::join(L, R);
}