Skip to content
This repository has been archived by the owner on Apr 23, 2020. It is now read-only.

Commit

Permalink
[analyzer] PR43551: Do not dereferce void* in UndefOrNullArgVisitor.
Browse files Browse the repository at this point in the history
Patch by Kristóf Umann!

Differential Revision: https://reviews.llvm.org/D68591

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@375329 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
haoNoQ committed Oct 19, 2019
1 parent e8e2927 commit 9504ebb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
8 changes: 5 additions & 3 deletions lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
Expand Up @@ -2034,8 +2034,6 @@ bool bugreporter::trackExpressionValue(const ExplodedNode *InputNode,

// Is it a symbolic value?
if (auto L = V.getAs<loc::MemRegionVal>()) {
report.addVisitor(std::make_unique<UndefOrNullArgVisitor>(L->getRegion()));

// FIXME: this is a hack for fixing a later crash when attempting to
// dereference a void* pointer.
// We should not try to dereference pointers at all when we don't care
Expand All @@ -2056,10 +2054,14 @@ bool bugreporter::trackExpressionValue(const ExplodedNode *InputNode,
else if (CanDereference)
RVal = LVState->getSVal(L->getRegion());

if (CanDereference)
if (CanDereference) {
report.addVisitor(
std::make_unique<UndefOrNullArgVisitor>(L->getRegion()));

if (auto KV = RVal.getAs<KnownSVal>())
report.addVisitor(std::make_unique<FindLastStoreBRVisitor>(
*KV, L->getRegion(), EnableNullFPSuppression, TKind, SFC));
}

const MemRegion *RegionRVal = RVal.getAsRegion();
if (RegionRVal && isa<SymbolicRegion>(RegionRVal)) {
Expand Down
29 changes: 24 additions & 5 deletions test/Analysis/novoidtypecrash.c
@@ -1,8 +1,27 @@
// RUN: %clang_analyze_cc1 -analyzer-checker=core %s
x;
y(void **z) { // no-crash
*z = x;
int *w;
y(&w);
*w;
}

a;
b(void **c) { // no-crash
*c = a;
int *d;
b(&d);
*d;
b(*c) {}
e(*c) {
void *d = f();
b(d);
*c = d;
}
void *g() {
e(&a);
return a;
}
j() {
int h;
char i = g();
if (i)
for (; h;)
;
}

0 comments on commit 9504ebb

Please sign in to comment.