]> granicus.if.org Git - clang/commitdiff
[analyzer] Do not crash in CallEvent.getReturnType()
authorGeorge Karpenkov <ekarpenkov@apple.com>
Sat, 24 Mar 2018 01:53:12 +0000 (01:53 +0000)
committerGeorge Karpenkov <ekarpenkov@apple.com>
Sat, 24 Mar 2018 01:53:12 +0000 (01:53 +0000)
When the call expression is not available.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@328406 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Core/CallEvent.cpp
test/Analysis/Inputs/system-header-simulator-for-nullability-cxx.h [new file with mode: 0644]
test/Analysis/trustnonnullchecker_test.mm [new file with mode: 0644]

index 3ff02f17d032c23bb778a0e9e30f683c83b13836..dab5335ae093c15a0fd44e8e73e44950ba0c3aa9 100644 (file)
@@ -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/test/Analysis/Inputs/system-header-simulator-for-nullability-cxx.h b/test/Analysis/Inputs/system-header-simulator-for-nullability-cxx.h
new file mode 100644 (file)
index 0000000..fe620c9
--- /dev/null
@@ -0,0 +1,9 @@
+#pragma clang system_header
+
+struct S {
+  ~S(){}
+};
+
+void foo() {
+  S s;
+}
diff --git a/test/Analysis/trustnonnullchecker_test.mm b/test/Analysis/trustnonnullchecker_test.mm
new file mode 100644 (file)
index 0000000..fa84673
--- /dev/null
@@ -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
+}