diff options
| author | George Karpenkov <ekarpenkov@apple.com> | 2018-03-24 01:53:12 +0000 | 
|---|---|---|
| committer | George Karpenkov <ekarpenkov@apple.com> | 2018-03-24 01:53:12 +0000 | 
| commit | 405fdfc34c4e3496dc72a7679e896f9cd198b192 (patch) | |
| tree | 8e705fd489275ebb869084b8ddd7addcab794d9a | |
| parent | 2c0a62ab9afe781d886e9d37e0811846abc0cffe (diff) | |
| download | bcm5719-llvm-405fdfc34c4e3496dc72a7679e896f9cd198b192.tar.gz bcm5719-llvm-405fdfc34c4e3496dc72a7679e896f9cd198b192.zip  | |
[analyzer] Do not crash in CallEvent.getReturnType()
When the call expression is not available.
llvm-svn: 328406
| -rw-r--r-- | clang/lib/StaticAnalyzer/Core/CallEvent.cpp | 8 | ||||
| -rw-r--r-- | clang/test/Analysis/Inputs/system-header-simulator-for-nullability-cxx.h | 9 | ||||
| -rw-r--r-- | clang/test/Analysis/trustnonnullchecker_test.mm | 9 | 
3 files changed, 23 insertions, 3 deletions
diff --git a/clang/lib/StaticAnalyzer/Core/CallEvent.cpp b/clang/lib/StaticAnalyzer/Core/CallEvent.cpp index 3ff02f17d03..dab5335ae09 100644 --- a/clang/lib/StaticAnalyzer/Core/CallEvent.cpp +++ b/clang/lib/StaticAnalyzer/Core/CallEvent.cpp @@ -67,11 +67,13 @@ using namespace clang;  using namespace ento;  QualType CallEvent::getResultType() const { +  ASTContext &Ctx = getState()->getStateManager().getContext();    const Expr *E = getOriginExpr(); -  assert(E && "Calls without origin expressions do not have results"); -  QualType ResultTy = E->getType(); +  if (!E) +    return Ctx.VoidTy; +  assert(E); -  ASTContext &Ctx = getState()->getStateManager().getContext(); +  QualType ResultTy = E->getType();    // A function that returns a reference to 'int' will have a result type    // of simply 'int'. Check the origin expr's value kind to recover the diff --git a/clang/test/Analysis/Inputs/system-header-simulator-for-nullability-cxx.h b/clang/test/Analysis/Inputs/system-header-simulator-for-nullability-cxx.h new file mode 100644 index 00000000000..fe620c9ff19 --- /dev/null +++ b/clang/test/Analysis/Inputs/system-header-simulator-for-nullability-cxx.h @@ -0,0 +1,9 @@ +#pragma clang system_header + +struct S { +  ~S(){} +}; + +void foo() { +  S s; +} diff --git a/clang/test/Analysis/trustnonnullchecker_test.mm b/clang/test/Analysis/trustnonnullchecker_test.mm new file mode 100644 index 00000000000..fa84673492b --- /dev/null +++ b/clang/test/Analysis/trustnonnullchecker_test.mm @@ -0,0 +1,9 @@ +// RUN: %clang_analyze_cc1 -fblocks -analyze -analyzer-checker=core,nullability,apiModeling  -verify %s + +#include "Inputs/system-header-simulator-for-nullability-cxx.h" + +// expected-no-diagnostics + +void blah() { +  foo(); // no-crash +}  | 

