From a1923b264588a391a9b5b66669f502c515eec81f Mon Sep 17 00:00:00 2001 From: Artem Dergachev Date: Fri, 29 Mar 2019 22:57:49 +0000 Subject: [PATCH] [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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@357329 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/StaticAnalyzer/Core/BugReporterVisitors.cpp | 2 +- test/Analysis/diagnostics/no-store-func-path-notes.c | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp b/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp index 1bbc0dbc02..1576c09e42 100644 --- a/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp +++ b/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp @@ -322,7 +322,7 @@ public: CallEventRef<> Call = BR.getStateManager().getCallEventManager().getCaller(SCtx, State); - if (SM.isInSystemHeader(Call->getDecl()->getSourceRange().getBegin())) + if (Call->isInSystemHeader()) return nullptr; // Region of interest corresponds to an IVar, exiting a method diff --git a/test/Analysis/diagnostics/no-store-func-path-notes.c b/test/Analysis/diagnostics/no-store-func-path-notes.c index 2050f6217c..c0208214cc 100644 --- a/test/Analysis/diagnostics/no-store-func-path-notes.c +++ b/test/Analysis/diagnostics/no-store-func-path-notes.c @@ -1,4 +1,5 @@ -// RUN: %clang_analyze_cc1 -x c -analyzer-checker=core -analyzer-output=text -verify %s +// RUN: %clang_analyze_cc1 -w -x c -analyzer-checker=core -analyzer-output=text\ +// RUN: -verify %s typedef __typeof(sizeof(int)) size_t; void *memset(void *__s, int __c, size_t __n); @@ -244,3 +245,12 @@ int useInitializeMaybeInStruct() { return z; // expected-warning{{Undefined or garbage value returned to caller}} // expected-note@-1{{Undefined or garbage value returned to caller}} } + +void test_implicit_function_decl(int *x) { + if (x) {} // expected-note{{Assuming 'x' is null}} + // expected-note@-1{{Taking false branch}} + implicit_function(x); + *x = 4; // expected-warning{{Dereference of null pointer (loaded from variable 'x')}} + // expected-note@-1{{Dereference of null pointer (loaded from variable 'x')}} +} +int implicit_function(int *y) {} -- 2.40.0