Skip to content

Commit 388e19f

Browse files
committed
[analyzer] PR41239: Fix a crash on invalid source location in NoStoreFuncVisitor.
It turns out that SourceManager::isInSystemHeader() crashes when an invalid source location is passed into it. Invalid source locations are relatively common: not only they come from body farms, but also, say, any function in C that didn't come with a forward declaration would have an implicit forward declaration with invalid source locations. There's a more comfy API for us to use in the Static Analyzer: CallEvent::isInSystemHeader(), so just use that. Differential Revision: https://reviews.llvm.org/D59901 llvm-svn: 357329
1 parent e3a845e commit 388e19f

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ class NoStoreFuncVisitor final : public BugReporterVisitor {
322322
CallEventRef<> Call =
323323
BR.getStateManager().getCallEventManager().getCaller(SCtx, State);
324324

325-
if (SM.isInSystemHeader(Call->getDecl()->getSourceRange().getBegin()))
325+
if (Call->isInSystemHeader())
326326
return nullptr;
327327

328328
// Region of interest corresponds to an IVar, exiting a method

clang/test/Analysis/diagnostics/no-store-func-path-notes.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// RUN: %clang_analyze_cc1 -x c -analyzer-checker=core -analyzer-output=text -verify %s
1+
// RUN: %clang_analyze_cc1 -w -x c -analyzer-checker=core -analyzer-output=text\
2+
// RUN: -verify %s
23

34
typedef __typeof(sizeof(int)) size_t;
45
void *memset(void *__s, int __c, size_t __n);
@@ -244,3 +245,12 @@ int useInitializeMaybeInStruct() {
244245
return z; // expected-warning{{Undefined or garbage value returned to caller}}
245246
// expected-note@-1{{Undefined or garbage value returned to caller}}
246247
}
248+
249+
void test_implicit_function_decl(int *x) {
250+
if (x) {} // expected-note{{Assuming 'x' is null}}
251+
// expected-note@-1{{Taking false branch}}
252+
implicit_function(x);
253+
*x = 4; // expected-warning{{Dereference of null pointer (loaded from variable 'x')}}
254+
// expected-note@-1{{Dereference of null pointer (loaded from variable 'x')}}
255+
}
256+
int implicit_function(int *y) {}

0 commit comments

Comments
 (0)