[analyzer] Do not crash in CallEvent.getReturnType()

When the call expression is not available.

llvm-svn: 328406
This commit is contained in:
George Karpenkov 2018-03-24 01:53:12 +00:00
parent 2c0a62ab9a
commit 405fdfc34c
3 changed files with 24 additions and 4 deletions

View File

@ -67,11 +67,13 @@ using namespace clang;
using namespace ento;
QualType CallEvent::getResultType() const {
const Expr *E = getOriginExpr();
assert(E && "Calls without origin expressions do not have results");
QualType ResultTy = E->getType();
ASTContext &Ctx = getState()->getStateManager().getContext();
const Expr *E = getOriginExpr();
if (!E)
return Ctx.VoidTy;
assert(E);
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

View File

@ -0,0 +1,9 @@
#pragma clang system_header
struct S {
~S(){}
};
void foo() {
S s;
}

View File

@ -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
}