Path: blob/main/contrib/llvm-project/clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
35266 views
//===--- CallAndMessageChecker.cpp ------------------------------*- C++ -*--==//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This defines CallAndMessageChecker, a builtin checker that checks for various9// errors of call and objc message expressions.10//11//===----------------------------------------------------------------------===//1213#include "clang/AST/ExprCXX.h"14#include "clang/AST/ParentMap.h"15#include "clang/Basic/TargetInfo.h"16#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"17#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"18#include "clang/StaticAnalyzer/Core/Checker.h"19#include "clang/StaticAnalyzer/Core/CheckerManager.h"20#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"21#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"22#include "llvm/ADT/SmallString.h"23#include "llvm/ADT/StringExtras.h"24#include "llvm/Support/Casting.h"25#include "llvm/Support/raw_ostream.h"2627using namespace clang;28using namespace ento;2930namespace {3132class CallAndMessageChecker33: public Checker<check::PreObjCMessage, check::ObjCMessageNil,34check::PreCall> {35mutable std::unique_ptr<BugType> BT_call_null;36mutable std::unique_ptr<BugType> BT_call_undef;37mutable std::unique_ptr<BugType> BT_cxx_call_null;38mutable std::unique_ptr<BugType> BT_cxx_call_undef;39mutable std::unique_ptr<BugType> BT_call_arg;40mutable std::unique_ptr<BugType> BT_cxx_delete_undef;41mutable std::unique_ptr<BugType> BT_msg_undef;42mutable std::unique_ptr<BugType> BT_objc_prop_undef;43mutable std::unique_ptr<BugType> BT_objc_subscript_undef;44mutable std::unique_ptr<BugType> BT_msg_arg;45mutable std::unique_ptr<BugType> BT_msg_ret;46mutable std::unique_ptr<BugType> BT_call_few_args;4748public:49// These correspond with the checker options. Looking at other checkers such50// as MallocChecker and CStringChecker, this is similar as to how they pull51// off having a modeling class, but emitting diagnostics under a smaller52// checker's name that can be safely disabled without disturbing the53// underlaying modeling engine.54// The reason behind having *checker options* rather then actual *checkers*55// here is that CallAndMessage is among the oldest checkers out there, and can56// be responsible for the majority of the reports on any given project. This57// is obviously not ideal, but changing checker name has the consequence of58// changing the issue hashes associated with the reports, and databases59// relying on this (CodeChecker, for instance) would suffer greatly.60// If we ever end up making changes to the issue hash generation algorithm, or61// the warning messages here, we should totally jump on the opportunity to62// convert these to actual checkers.63enum CheckKind {64CK_FunctionPointer,65CK_ParameterCount,66CK_CXXThisMethodCall,67CK_CXXDeallocationArg,68CK_ArgInitializedness,69CK_ArgPointeeInitializedness,70CK_NilReceiver,71CK_UndefReceiver,72CK_NumCheckKinds73};7475bool ChecksEnabled[CK_NumCheckKinds] = {false};76// The original core.CallAndMessage checker name. This should rather be an77// array, as seen in MallocChecker and CStringChecker.78CheckerNameRef OriginalName;7980void checkPreObjCMessage(const ObjCMethodCall &msg, CheckerContext &C) const;8182/// Fill in the return value that results from messaging nil based on the83/// return type and architecture and diagnose if the return value will be84/// garbage.85void checkObjCMessageNil(const ObjCMethodCall &msg, CheckerContext &C) const;8687void checkPreCall(const CallEvent &Call, CheckerContext &C) const;8889ProgramStateRef checkFunctionPointerCall(const CallExpr *CE,90CheckerContext &C,91ProgramStateRef State) const;9293ProgramStateRef checkCXXMethodCall(const CXXInstanceCall *CC,94CheckerContext &C,95ProgramStateRef State) const;9697ProgramStateRef checkParameterCount(const CallEvent &Call, CheckerContext &C,98ProgramStateRef State) const;99100ProgramStateRef checkCXXDeallocation(const CXXDeallocatorCall *DC,101CheckerContext &C,102ProgramStateRef State) const;103104ProgramStateRef checkArgInitializedness(const CallEvent &Call,105CheckerContext &C,106ProgramStateRef State) const;107108private:109bool PreVisitProcessArg(CheckerContext &C, SVal V, SourceRange ArgRange,110const Expr *ArgEx, int ArgumentNumber,111bool CheckUninitFields, const CallEvent &Call,112std::unique_ptr<BugType> &BT,113const ParmVarDecl *ParamDecl) const;114115static void emitBadCall(BugType *BT, CheckerContext &C, const Expr *BadE);116void emitNilReceiverBug(CheckerContext &C, const ObjCMethodCall &msg,117ExplodedNode *N) const;118119void HandleNilReceiver(CheckerContext &C,120ProgramStateRef state,121const ObjCMethodCall &msg) const;122123void LazyInit_BT(const char *desc, std::unique_ptr<BugType> &BT) const {124if (!BT)125BT.reset(new BugType(OriginalName, desc));126}127bool uninitRefOrPointer(CheckerContext &C, SVal V, SourceRange ArgRange,128const Expr *ArgEx, std::unique_ptr<BugType> &BT,129const ParmVarDecl *ParamDecl, const char *BD,130int ArgumentNumber) const;131};132} // end anonymous namespace133134void CallAndMessageChecker::emitBadCall(BugType *BT, CheckerContext &C,135const Expr *BadE) {136ExplodedNode *N = C.generateErrorNode();137if (!N)138return;139140auto R = std::make_unique<PathSensitiveBugReport>(*BT, BT->getDescription(), N);141if (BadE) {142R->addRange(BadE->getSourceRange());143if (BadE->isGLValue())144BadE = bugreporter::getDerefExpr(BadE);145bugreporter::trackExpressionValue(N, BadE, *R);146}147C.emitReport(std::move(R));148}149150static void describeUninitializedArgumentInCall(const CallEvent &Call,151int ArgumentNumber,152llvm::raw_svector_ostream &Os) {153switch (Call.getKind()) {154case CE_ObjCMessage: {155const ObjCMethodCall &Msg = cast<ObjCMethodCall>(Call);156switch (Msg.getMessageKind()) {157case OCM_Message:158Os << (ArgumentNumber + 1) << llvm::getOrdinalSuffix(ArgumentNumber + 1)159<< " argument in message expression is an uninitialized value";160return;161case OCM_PropertyAccess:162assert(Msg.isSetter() && "Getters have no args");163Os << "Argument for property setter is an uninitialized value";164return;165case OCM_Subscript:166if (Msg.isSetter() && (ArgumentNumber == 0))167Os << "Argument for subscript setter is an uninitialized value";168else169Os << "Subscript index is an uninitialized value";170return;171}172llvm_unreachable("Unknown message kind.");173}174case CE_Block:175Os << (ArgumentNumber + 1) << llvm::getOrdinalSuffix(ArgumentNumber + 1)176<< " block call argument is an uninitialized value";177return;178default:179Os << (ArgumentNumber + 1) << llvm::getOrdinalSuffix(ArgumentNumber + 1)180<< " function call argument is an uninitialized value";181return;182}183}184185bool CallAndMessageChecker::uninitRefOrPointer(186CheckerContext &C, SVal V, SourceRange ArgRange, const Expr *ArgEx,187std::unique_ptr<BugType> &BT, const ParmVarDecl *ParamDecl, const char *BD,188int ArgumentNumber) const {189190// The pointee being uninitialized is a sign of code smell, not a bug, no need191// to sink here.192if (!ChecksEnabled[CK_ArgPointeeInitializedness])193return false;194195// No parameter declaration available, i.e. variadic function argument.196if(!ParamDecl)197return false;198199// If parameter is declared as pointer to const in function declaration,200// then check if corresponding argument in function call is201// pointing to undefined symbol value (uninitialized memory).202SmallString<200> Buf;203llvm::raw_svector_ostream Os(Buf);204205if (ParamDecl->getType()->isPointerType()) {206Os << (ArgumentNumber + 1) << llvm::getOrdinalSuffix(ArgumentNumber + 1)207<< " function call argument is a pointer to uninitialized value";208} else if (ParamDecl->getType()->isReferenceType()) {209Os << (ArgumentNumber + 1) << llvm::getOrdinalSuffix(ArgumentNumber + 1)210<< " function call argument is an uninitialized value";211} else212return false;213214if(!ParamDecl->getType()->getPointeeType().isConstQualified())215return false;216217if (const MemRegion *SValMemRegion = V.getAsRegion()) {218const ProgramStateRef State = C.getState();219const SVal PSV = State->getSVal(SValMemRegion, C.getASTContext().CharTy);220if (PSV.isUndef()) {221if (ExplodedNode *N = C.generateErrorNode()) {222LazyInit_BT(BD, BT);223auto R = std::make_unique<PathSensitiveBugReport>(*BT, Os.str(), N);224R->addRange(ArgRange);225if (ArgEx)226bugreporter::trackExpressionValue(N, ArgEx, *R);227228C.emitReport(std::move(R));229}230return true;231}232}233return false;234}235236namespace {237class FindUninitializedField {238public:239SmallVector<const FieldDecl *, 10> FieldChain;240241private:242StoreManager &StoreMgr;243MemRegionManager &MrMgr;244Store store;245246public:247FindUninitializedField(StoreManager &storeMgr, MemRegionManager &mrMgr,248Store s)249: StoreMgr(storeMgr), MrMgr(mrMgr), store(s) {}250251bool Find(const TypedValueRegion *R) {252QualType T = R->getValueType();253if (const RecordType *RT = T->getAsStructureType()) {254const RecordDecl *RD = RT->getDecl()->getDefinition();255assert(RD && "Referred record has no definition");256for (const auto *I : RD->fields()) {257const FieldRegion *FR = MrMgr.getFieldRegion(I, R);258FieldChain.push_back(I);259T = I->getType();260if (T->getAsStructureType()) {261if (Find(FR))262return true;263} else {264SVal V = StoreMgr.getBinding(store, loc::MemRegionVal(FR));265if (V.isUndef())266return true;267}268FieldChain.pop_back();269}270}271272return false;273}274};275} // namespace276277bool CallAndMessageChecker::PreVisitProcessArg(CheckerContext &C,278SVal V,279SourceRange ArgRange,280const Expr *ArgEx,281int ArgumentNumber,282bool CheckUninitFields,283const CallEvent &Call,284std::unique_ptr<BugType> &BT,285const ParmVarDecl *ParamDecl286) const {287const char *BD = "Uninitialized argument value";288289if (uninitRefOrPointer(C, V, ArgRange, ArgEx, BT, ParamDecl, BD,290ArgumentNumber))291return true;292293if (V.isUndef()) {294if (!ChecksEnabled[CK_ArgInitializedness]) {295C.addSink();296return true;297}298if (ExplodedNode *N = C.generateErrorNode()) {299LazyInit_BT(BD, BT);300// Generate a report for this bug.301SmallString<200> Buf;302llvm::raw_svector_ostream Os(Buf);303describeUninitializedArgumentInCall(Call, ArgumentNumber, Os);304auto R = std::make_unique<PathSensitiveBugReport>(*BT, Os.str(), N);305306R->addRange(ArgRange);307if (ArgEx)308bugreporter::trackExpressionValue(N, ArgEx, *R);309C.emitReport(std::move(R));310}311return true;312}313314if (!CheckUninitFields)315return false;316317if (auto LV = V.getAs<nonloc::LazyCompoundVal>()) {318const LazyCompoundValData *D = LV->getCVData();319FindUninitializedField F(C.getState()->getStateManager().getStoreManager(),320C.getSValBuilder().getRegionManager(),321D->getStore());322323if (F.Find(D->getRegion())) {324if (!ChecksEnabled[CK_ArgInitializedness]) {325C.addSink();326return true;327}328if (ExplodedNode *N = C.generateErrorNode()) {329LazyInit_BT(BD, BT);330SmallString<512> Str;331llvm::raw_svector_ostream os(Str);332os << "Passed-by-value struct argument contains uninitialized data";333334if (F.FieldChain.size() == 1)335os << " (e.g., field: '" << *F.FieldChain[0] << "')";336else {337os << " (e.g., via the field chain: '";338bool first = true;339for (SmallVectorImpl<const FieldDecl *>::iterator340DI = F.FieldChain.begin(), DE = F.FieldChain.end(); DI!=DE;++DI){341if (first)342first = false;343else344os << '.';345os << **DI;346}347os << "')";348}349350// Generate a report for this bug.351auto R = std::make_unique<PathSensitiveBugReport>(*BT, os.str(), N);352R->addRange(ArgRange);353354if (ArgEx)355bugreporter::trackExpressionValue(N, ArgEx, *R);356// FIXME: enhance track back for uninitialized value for arbitrary357// memregions358C.emitReport(std::move(R));359}360return true;361}362}363364return false;365}366367ProgramStateRef CallAndMessageChecker::checkFunctionPointerCall(368const CallExpr *CE, CheckerContext &C, ProgramStateRef State) const {369370const Expr *Callee = CE->getCallee()->IgnoreParens();371const LocationContext *LCtx = C.getLocationContext();372SVal L = State->getSVal(Callee, LCtx);373374if (L.isUndef()) {375if (!ChecksEnabled[CK_FunctionPointer]) {376C.addSink(State);377return nullptr;378}379if (!BT_call_undef)380BT_call_undef.reset(new BugType(381OriginalName,382"Called function pointer is an uninitialized pointer value"));383emitBadCall(BT_call_undef.get(), C, Callee);384return nullptr;385}386387ProgramStateRef StNonNull, StNull;388std::tie(StNonNull, StNull) = State->assume(L.castAs<DefinedOrUnknownSVal>());389390if (StNull && !StNonNull) {391if (!ChecksEnabled[CK_FunctionPointer]) {392C.addSink(StNull);393return nullptr;394}395if (!BT_call_null)396BT_call_null.reset(new BugType(397OriginalName, "Called function pointer is null (null dereference)"));398emitBadCall(BT_call_null.get(), C, Callee);399return nullptr;400}401402return StNonNull;403}404405ProgramStateRef CallAndMessageChecker::checkParameterCount(406const CallEvent &Call, CheckerContext &C, ProgramStateRef State) const {407408// If we have a function or block declaration, we can make sure we pass409// enough parameters.410unsigned Params = Call.parameters().size();411if (Call.getNumArgs() >= Params)412return State;413414if (!ChecksEnabled[CK_ParameterCount]) {415C.addSink(State);416return nullptr;417}418419ExplodedNode *N = C.generateErrorNode();420if (!N)421return nullptr;422423LazyInit_BT("Function call with too few arguments", BT_call_few_args);424425SmallString<512> Str;426llvm::raw_svector_ostream os(Str);427if (isa<AnyFunctionCall>(Call)) {428os << "Function ";429} else {430assert(isa<BlockCall>(Call));431os << "Block ";432}433os << "taking " << Params << " argument" << (Params == 1 ? "" : "s")434<< " is called with fewer (" << Call.getNumArgs() << ")";435436C.emitReport(437std::make_unique<PathSensitiveBugReport>(*BT_call_few_args, os.str(), N));438return nullptr;439}440441ProgramStateRef CallAndMessageChecker::checkCXXMethodCall(442const CXXInstanceCall *CC, CheckerContext &C, ProgramStateRef State) const {443444SVal V = CC->getCXXThisVal();445if (V.isUndef()) {446if (!ChecksEnabled[CK_CXXThisMethodCall]) {447C.addSink(State);448return nullptr;449}450if (!BT_cxx_call_undef)451BT_cxx_call_undef.reset(new BugType(452OriginalName, "Called C++ object pointer is uninitialized"));453emitBadCall(BT_cxx_call_undef.get(), C, CC->getCXXThisExpr());454return nullptr;455}456457ProgramStateRef StNonNull, StNull;458std::tie(StNonNull, StNull) = State->assume(V.castAs<DefinedOrUnknownSVal>());459460if (StNull && !StNonNull) {461if (!ChecksEnabled[CK_CXXThisMethodCall]) {462C.addSink(StNull);463return nullptr;464}465if (!BT_cxx_call_null)466BT_cxx_call_null.reset(467new BugType(OriginalName, "Called C++ object pointer is null"));468emitBadCall(BT_cxx_call_null.get(), C, CC->getCXXThisExpr());469return nullptr;470}471472return StNonNull;473}474475ProgramStateRef476CallAndMessageChecker::checkCXXDeallocation(const CXXDeallocatorCall *DC,477CheckerContext &C,478ProgramStateRef State) const {479const CXXDeleteExpr *DE = DC->getOriginExpr();480assert(DE);481SVal Arg = C.getSVal(DE->getArgument());482if (!Arg.isUndef())483return State;484485if (!ChecksEnabled[CK_CXXDeallocationArg]) {486C.addSink(State);487return nullptr;488}489490StringRef Desc;491ExplodedNode *N = C.generateErrorNode();492if (!N)493return nullptr;494if (!BT_cxx_delete_undef)495BT_cxx_delete_undef.reset(496new BugType(OriginalName, "Uninitialized argument value"));497if (DE->isArrayFormAsWritten())498Desc = "Argument to 'delete[]' is uninitialized";499else500Desc = "Argument to 'delete' is uninitialized";501auto R =502std::make_unique<PathSensitiveBugReport>(*BT_cxx_delete_undef, Desc, N);503bugreporter::trackExpressionValue(N, DE, *R);504C.emitReport(std::move(R));505return nullptr;506}507508ProgramStateRef CallAndMessageChecker::checkArgInitializedness(509const CallEvent &Call, CheckerContext &C, ProgramStateRef State) const {510511const Decl *D = Call.getDecl();512513// Don't check for uninitialized field values in arguments if the514// caller has a body that is available and we have the chance to inline it.515// This is a hack, but is a reasonable compromise betweens sometimes warning516// and sometimes not depending on if we decide to inline a function.517const bool checkUninitFields =518!(C.getAnalysisManager().shouldInlineCall() && (D && D->getBody()));519520std::unique_ptr<BugType> *BT;521if (isa<ObjCMethodCall>(Call))522BT = &BT_msg_arg;523else524BT = &BT_call_arg;525526const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D);527for (unsigned i = 0, e = Call.getNumArgs(); i != e; ++i) {528const ParmVarDecl *ParamDecl = nullptr;529if (FD && i < FD->getNumParams())530ParamDecl = FD->getParamDecl(i);531if (PreVisitProcessArg(C, Call.getArgSVal(i), Call.getArgSourceRange(i),532Call.getArgExpr(i), i, checkUninitFields, Call, *BT,533ParamDecl))534return nullptr;535}536return State;537}538539void CallAndMessageChecker::checkPreCall(const CallEvent &Call,540CheckerContext &C) const {541ProgramStateRef State = C.getState();542543if (const CallExpr *CE = dyn_cast_or_null<CallExpr>(Call.getOriginExpr()))544State = checkFunctionPointerCall(CE, C, State);545546if (!State)547return;548549if (Call.getDecl())550State = checkParameterCount(Call, C, State);551552if (!State)553return;554555if (const auto *CC = dyn_cast<CXXInstanceCall>(&Call))556State = checkCXXMethodCall(CC, C, State);557558if (!State)559return;560561if (const auto *DC = dyn_cast<CXXDeallocatorCall>(&Call))562State = checkCXXDeallocation(DC, C, State);563564if (!State)565return;566567State = checkArgInitializedness(Call, C, State);568569// If we make it here, record our assumptions about the callee.570C.addTransition(State);571}572573void CallAndMessageChecker::checkPreObjCMessage(const ObjCMethodCall &msg,574CheckerContext &C) const {575SVal recVal = msg.getReceiverSVal();576if (recVal.isUndef()) {577if (!ChecksEnabled[CK_UndefReceiver]) {578C.addSink();579return;580}581if (ExplodedNode *N = C.generateErrorNode()) {582BugType *BT = nullptr;583switch (msg.getMessageKind()) {584case OCM_Message:585if (!BT_msg_undef)586BT_msg_undef.reset(new BugType(OriginalName,587"Receiver in message expression "588"is an uninitialized value"));589BT = BT_msg_undef.get();590break;591case OCM_PropertyAccess:592if (!BT_objc_prop_undef)593BT_objc_prop_undef.reset(new BugType(594OriginalName,595"Property access on an uninitialized object pointer"));596BT = BT_objc_prop_undef.get();597break;598case OCM_Subscript:599if (!BT_objc_subscript_undef)600BT_objc_subscript_undef.reset(new BugType(601OriginalName,602"Subscript access on an uninitialized object pointer"));603BT = BT_objc_subscript_undef.get();604break;605}606assert(BT && "Unknown message kind.");607608auto R = std::make_unique<PathSensitiveBugReport>(*BT, BT->getDescription(), N);609const ObjCMessageExpr *ME = msg.getOriginExpr();610R->addRange(ME->getReceiverRange());611612// FIXME: getTrackNullOrUndefValueVisitor can't handle "super" yet.613if (const Expr *ReceiverE = ME->getInstanceReceiver())614bugreporter::trackExpressionValue(N, ReceiverE, *R);615C.emitReport(std::move(R));616}617return;618}619}620621void CallAndMessageChecker::checkObjCMessageNil(const ObjCMethodCall &msg,622CheckerContext &C) const {623HandleNilReceiver(C, C.getState(), msg);624}625626void CallAndMessageChecker::emitNilReceiverBug(CheckerContext &C,627const ObjCMethodCall &msg,628ExplodedNode *N) const {629if (!ChecksEnabled[CK_NilReceiver]) {630C.addSink();631return;632}633634if (!BT_msg_ret)635BT_msg_ret.reset(636new BugType(OriginalName, "Receiver in message expression is 'nil'"));637638const ObjCMessageExpr *ME = msg.getOriginExpr();639640QualType ResTy = msg.getResultType();641642SmallString<200> buf;643llvm::raw_svector_ostream os(buf);644os << "The receiver of message '";645ME->getSelector().print(os);646os << "' is nil";647if (ResTy->isReferenceType()) {648os << ", which results in forming a null reference";649} else {650os << " and returns a value of type '";651msg.getResultType().print(os, C.getLangOpts());652os << "' that will be garbage";653}654655auto report =656std::make_unique<PathSensitiveBugReport>(*BT_msg_ret, os.str(), N);657report->addRange(ME->getReceiverRange());658// FIXME: This won't track "self" in messages to super.659if (const Expr *receiver = ME->getInstanceReceiver()) {660bugreporter::trackExpressionValue(N, receiver, *report);661}662C.emitReport(std::move(report));663}664665static bool supportsNilWithFloatRet(const llvm::Triple &triple) {666return (triple.getVendor() == llvm::Triple::Apple &&667(triple.isiOS() || triple.isWatchOS() ||668!triple.isMacOSXVersionLT(10,5)));669}670671void CallAndMessageChecker::HandleNilReceiver(CheckerContext &C,672ProgramStateRef state,673const ObjCMethodCall &Msg) const {674ASTContext &Ctx = C.getASTContext();675static CheckerProgramPointTag Tag(this, "NilReceiver");676677// Check the return type of the message expression. A message to nil will678// return different values depending on the return type and the architecture.679QualType RetTy = Msg.getResultType();680CanQualType CanRetTy = Ctx.getCanonicalType(RetTy);681const LocationContext *LCtx = C.getLocationContext();682683if (CanRetTy->isStructureOrClassType()) {684// Structure returns are safe since the compiler zeroes them out.685SVal V = C.getSValBuilder().makeZeroVal(RetTy);686C.addTransition(state->BindExpr(Msg.getOriginExpr(), LCtx, V), &Tag);687return;688}689690// Other cases: check if sizeof(return type) > sizeof(void*)691if (CanRetTy != Ctx.VoidTy && C.getLocationContext()->getParentMap()692.isConsumedExpr(Msg.getOriginExpr())) {693// Compute: sizeof(void *) and sizeof(return type)694const uint64_t voidPtrSize = Ctx.getTypeSize(Ctx.VoidPtrTy);695const uint64_t returnTypeSize = Ctx.getTypeSize(CanRetTy);696697if (CanRetTy.getTypePtr()->isReferenceType()||698(voidPtrSize < returnTypeSize &&699!(supportsNilWithFloatRet(Ctx.getTargetInfo().getTriple()) &&700(Ctx.FloatTy == CanRetTy ||701Ctx.DoubleTy == CanRetTy ||702Ctx.LongDoubleTy == CanRetTy ||703Ctx.LongLongTy == CanRetTy ||704Ctx.UnsignedLongLongTy == CanRetTy)))) {705if (ExplodedNode *N = C.generateErrorNode(state, &Tag))706emitNilReceiverBug(C, Msg, N);707return;708}709710// Handle the safe cases where the return value is 0 if the711// receiver is nil.712//713// FIXME: For now take the conservative approach that we only714// return null values if we *know* that the receiver is nil.715// This is because we can have surprises like:716//717// ... = [[NSScreens screens] objectAtIndex:0];718//719// What can happen is that [... screens] could return nil, but720// it most likely isn't nil. We should assume the semantics721// of this case unless we have *a lot* more knowledge.722//723SVal V = C.getSValBuilder().makeZeroVal(RetTy);724C.addTransition(state->BindExpr(Msg.getOriginExpr(), LCtx, V), &Tag);725return;726}727728C.addTransition(state);729}730731void ento::registerCallAndMessageModeling(CheckerManager &mgr) {732mgr.registerChecker<CallAndMessageChecker>();733}734735bool ento::shouldRegisterCallAndMessageModeling(const CheckerManager &mgr) {736return true;737}738739void ento::registerCallAndMessageChecker(CheckerManager &mgr) {740CallAndMessageChecker *checker = mgr.getChecker<CallAndMessageChecker>();741742checker->OriginalName = mgr.getCurrentCheckerName();743744#define QUERY_CHECKER_OPTION(OPTION) \745checker->ChecksEnabled[CallAndMessageChecker::CK_##OPTION] = \746mgr.getAnalyzerOptions().getCheckerBooleanOption( \747mgr.getCurrentCheckerName(), #OPTION);748749QUERY_CHECKER_OPTION(FunctionPointer)750QUERY_CHECKER_OPTION(ParameterCount)751QUERY_CHECKER_OPTION(CXXThisMethodCall)752QUERY_CHECKER_OPTION(CXXDeallocationArg)753QUERY_CHECKER_OPTION(ArgInitializedness)754QUERY_CHECKER_OPTION(ArgPointeeInitializedness)755QUERY_CHECKER_OPTION(NilReceiver)756QUERY_CHECKER_OPTION(UndefReceiver)757}758759bool ento::shouldRegisterCallAndMessageChecker(const CheckerManager &mgr) {760return true;761}762763764