r328406 - [analyzer] Do not crash in CallEvent.getReturnType()
George Karpenkov via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 23 18:53:12 PDT 2018
Author: george.karpenkov
Date: Fri Mar 23 18:53:12 2018
New Revision: 328406
URL: http://llvm.org/viewvc/llvm-project?rev=328406&view=rev
Log:
[analyzer] Do not crash in CallEvent.getReturnType()
When the call expression is not available.
Added:
cfe/trunk/test/Analysis/Inputs/system-header-simulator-for-nullability-cxx.h
cfe/trunk/test/Analysis/trustnonnullchecker_test.mm
Modified:
cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
Modified: cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp?rev=328406&r1=328405&r2=328406&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp Fri Mar 23 18:53:12 2018
@@ -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
Added: cfe/trunk/test/Analysis/Inputs/system-header-simulator-for-nullability-cxx.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/Inputs/system-header-simulator-for-nullability-cxx.h?rev=328406&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/Inputs/system-header-simulator-for-nullability-cxx.h (added)
+++ cfe/trunk/test/Analysis/Inputs/system-header-simulator-for-nullability-cxx.h Fri Mar 23 18:53:12 2018
@@ -0,0 +1,9 @@
+#pragma clang system_header
+
+struct S {
+ ~S(){}
+};
+
+void foo() {
+ S s;
+}
Added: cfe/trunk/test/Analysis/trustnonnullchecker_test.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/trustnonnullchecker_test.mm?rev=328406&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/trustnonnullchecker_test.mm (added)
+++ cfe/trunk/test/Analysis/trustnonnullchecker_test.mm Fri Mar 23 18:53:12 2018
@@ -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
+}
More information about the cfe-commits
mailing list