summaryrefslogtreecommitdiffstats
path: root/clang/lib/StaticAnalyzer/Core/ProgramState.cpp
diff options
context:
space:
mode:
authorGeorge Karpenkov <ekarpenkov@apple.com>2017-11-09 21:49:38 +0000
committerGeorge Karpenkov <ekarpenkov@apple.com>2017-11-09 21:49:38 +0000
commitd860e7a6b842956b5fab2528d80775f991d26c7f (patch)
treee58266e0305661e3a079677770109343286839e1 /clang/lib/StaticAnalyzer/Core/ProgramState.cpp
parent39f457b36fc7aa90d457231dec26984c5e203d02 (diff)
downloadbcm5719-llvm-d860e7a6b842956b5fab2528d80775f991d26c7f.tar.gz
bcm5719-llvm-d860e7a6b842956b5fab2528d80775f991d26c7f.zip
[analyzer] do not crash when trying to convert an APSInt to an unexpected type
This is the issue breaking the postgresql bot, purely by chance exposed through taint checker, somehow appearing after https://reviews.llvm.org/D38358 got committed. The backstory is that the taint checker requests SVal for the value of the pointer, and analyzer has a "fast path" in the getter to return a constant when we know that the value is constant. Unfortunately, the getter requires a cast to get signedness correctly, and for the pointer `void *` the cast crashes. This is more of a band-aid patch, as I am not sure what could be done here "correctly", but it should be applied in any case to avoid the crash. Differential Revision: https://reviews.llvm.org/D39862 llvm-svn: 317839
Diffstat (limited to 'clang/lib/StaticAnalyzer/Core/ProgramState.cpp')
-rw-r--r--clang/lib/StaticAnalyzer/Core/ProgramState.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/clang/lib/StaticAnalyzer/Core/ProgramState.cpp b/clang/lib/StaticAnalyzer/Core/ProgramState.cpp
index 3215c3ccd21..5b6b7339697 100644
--- a/clang/lib/StaticAnalyzer/Core/ProgramState.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ProgramState.cpp
@@ -260,7 +260,9 @@ SVal ProgramState::getSVal(Loc location, QualType T) const {
// be a constant value, use that value instead to lessen the burden
// on later analysis stages (so we have less symbolic values to reason
// about).
- if (!T.isNull()) {
+ // We only go into this branch if we can convert the APSInt value we have
+ // to the type of T, which is not always the case (e.g. for void).
+ if (!T.isNull() && (T->isIntegralOrEnumerationType() || Loc::isLocType(T))) {
if (SymbolRef sym = V.getAsSymbol()) {
if (const llvm::APSInt *Int = getStateManager()
.getConstraintManager()
OpenPOWER on IntegriCloud