CallAndMessageChecker.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. //===--- CallAndMessageChecker.cpp ------------------------------*- C++ -*--==//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This defines CallAndMessageChecker, a builtin checker that checks for various
  11. // errors of call and objc message expressions.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #include "ClangSACheckers.h"
  15. #include "clang/AST/ParentMap.h"
  16. #include "clang/Basic/TargetInfo.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/Support/raw_ostream.h"
  24. using namespace clang;
  25. using namespace ento;
  26. namespace {
  27. struct ChecksFilter {
  28. DefaultBool Check_CallAndMessageUnInitRefArg;
  29. DefaultBool Check_CallAndMessageChecker;
  30. CheckName CheckName_CallAndMessageUnInitRefArg;
  31. CheckName CheckName_CallAndMessageChecker;
  32. };
  33. class CallAndMessageChecker
  34. : public Checker< check::PreStmt<CallExpr>,
  35. check::PreStmt<CXXDeleteExpr>,
  36. check::PreObjCMessage,
  37. check::PreCall > {
  38. mutable std::unique_ptr<BugType> BT_call_null;
  39. mutable std::unique_ptr<BugType> BT_call_undef;
  40. mutable std::unique_ptr<BugType> BT_cxx_call_null;
  41. mutable std::unique_ptr<BugType> BT_cxx_call_undef;
  42. mutable std::unique_ptr<BugType> BT_call_arg;
  43. mutable std::unique_ptr<BugType> BT_cxx_delete_undef;
  44. mutable std::unique_ptr<BugType> BT_msg_undef;
  45. mutable std::unique_ptr<BugType> BT_objc_prop_undef;
  46. mutable std::unique_ptr<BugType> BT_objc_subscript_undef;
  47. mutable std::unique_ptr<BugType> BT_msg_arg;
  48. mutable std::unique_ptr<BugType> BT_msg_ret;
  49. mutable std::unique_ptr<BugType> BT_call_few_args;
  50. public:
  51. ChecksFilter Filter;
  52. void checkPreStmt(const CallExpr *CE, CheckerContext &C) const;
  53. void checkPreStmt(const CXXDeleteExpr *DE, CheckerContext &C) const;
  54. void checkPreObjCMessage(const ObjCMethodCall &msg, CheckerContext &C) const;
  55. void checkPreCall(const CallEvent &Call, CheckerContext &C) const;
  56. private:
  57. bool PreVisitProcessArg(CheckerContext &C, SVal V, SourceRange ArgRange,
  58. const Expr *ArgEx, bool IsFirstArgument,
  59. bool CheckUninitFields, const CallEvent &Call,
  60. std::unique_ptr<BugType> &BT,
  61. const ParmVarDecl *ParamDecl) const;
  62. static void emitBadCall(BugType *BT, CheckerContext &C, const Expr *BadE);
  63. void emitNilReceiverBug(CheckerContext &C, const ObjCMethodCall &msg,
  64. ExplodedNode *N) const;
  65. void HandleNilReceiver(CheckerContext &C,
  66. ProgramStateRef state,
  67. const ObjCMethodCall &msg) const;
  68. void LazyInit_BT(const char *desc, std::unique_ptr<BugType> &BT) const {
  69. if (!BT)
  70. BT.reset(new BuiltinBug(this, desc));
  71. }
  72. bool uninitRefOrPointer(CheckerContext &C, const SVal &V,
  73. const SourceRange &ArgRange,
  74. const Expr *ArgEx, std::unique_ptr<BugType> &BT,
  75. const ParmVarDecl *ParamDecl, const char *BD) const;
  76. };
  77. } // end anonymous namespace
  78. void CallAndMessageChecker::emitBadCall(BugType *BT, CheckerContext &C,
  79. const Expr *BadE) {
  80. ExplodedNode *N = C.generateSink();
  81. if (!N)
  82. return;
  83. auto R = llvm::make_unique<BugReport>(*BT, BT->getName(), N);
  84. if (BadE) {
  85. R->addRange(BadE->getSourceRange());
  86. if (BadE->isGLValue())
  87. BadE = bugreporter::getDerefExpr(BadE);
  88. bugreporter::trackNullOrUndefValue(N, BadE, *R);
  89. }
  90. C.emitReport(std::move(R));
  91. }
  92. static StringRef describeUninitializedArgumentInCall(const CallEvent &Call,
  93. bool IsFirstArgument) {
  94. switch (Call.getKind()) {
  95. case CE_ObjCMessage: {
  96. const ObjCMethodCall &Msg = cast<ObjCMethodCall>(Call);
  97. switch (Msg.getMessageKind()) {
  98. case OCM_Message:
  99. return "Argument in message expression is an uninitialized value";
  100. case OCM_PropertyAccess:
  101. assert(Msg.isSetter() && "Getters have no args");
  102. return "Argument for property setter is an uninitialized value";
  103. case OCM_Subscript:
  104. if (Msg.isSetter() && IsFirstArgument)
  105. return "Argument for subscript setter is an uninitialized value";
  106. return "Subscript index is an uninitialized value";
  107. }
  108. llvm_unreachable("Unknown message kind.");
  109. }
  110. case CE_Block:
  111. return "Block call argument is an uninitialized value";
  112. default:
  113. return "Function call argument is an uninitialized value";
  114. }
  115. }
  116. bool CallAndMessageChecker::uninitRefOrPointer(CheckerContext &C,
  117. const SVal &V,
  118. const SourceRange &ArgRange,
  119. const Expr *ArgEx,
  120. std::unique_ptr<BugType> &BT,
  121. const ParmVarDecl *ParamDecl,
  122. const char *BD) const {
  123. if (!Filter.Check_CallAndMessageUnInitRefArg)
  124. return false;
  125. // No parameter declaration available, i.e. variadic function argument.
  126. if(!ParamDecl)
  127. return false;
  128. // If parameter is declared as pointer to const in function declaration,
  129. // then check if corresponding argument in function call is
  130. // pointing to undefined symbol value (uninitialized memory).
  131. StringRef Message;
  132. if (ParamDecl->getType()->isPointerType()) {
  133. Message = "Function call argument is a pointer to uninitialized value";
  134. } else if (ParamDecl->getType()->isReferenceType()) {
  135. Message = "Function call argument is an uninitialized value";
  136. } else
  137. return false;
  138. if(!ParamDecl->getType()->getPointeeType().isConstQualified())
  139. return false;
  140. if (const MemRegion *SValMemRegion = V.getAsRegion()) {
  141. const ProgramStateRef State = C.getState();
  142. const SVal PSV = State->getSVal(SValMemRegion);
  143. if (PSV.isUndef()) {
  144. if (ExplodedNode *N = C.generateSink()) {
  145. LazyInit_BT(BD, BT);
  146. auto R = llvm::make_unique<BugReport>(*BT, Message, N);
  147. R->addRange(ArgRange);
  148. if (ArgEx) {
  149. bugreporter::trackNullOrUndefValue(N, ArgEx, *R);
  150. }
  151. C.emitReport(std::move(R));
  152. }
  153. return true;
  154. }
  155. }
  156. return false;
  157. }
  158. bool CallAndMessageChecker::PreVisitProcessArg(CheckerContext &C,
  159. SVal V,
  160. SourceRange ArgRange,
  161. const Expr *ArgEx,
  162. bool IsFirstArgument,
  163. bool CheckUninitFields,
  164. const CallEvent &Call,
  165. std::unique_ptr<BugType> &BT,
  166. const ParmVarDecl *ParamDecl
  167. ) const {
  168. const char *BD = "Uninitialized argument value";
  169. if (uninitRefOrPointer(C, V, ArgRange, ArgEx, BT, ParamDecl, BD))
  170. return true;
  171. if (V.isUndef()) {
  172. if (ExplodedNode *N = C.generateSink()) {
  173. LazyInit_BT(BD, BT);
  174. // Generate a report for this bug.
  175. StringRef Desc =
  176. describeUninitializedArgumentInCall(Call, IsFirstArgument);
  177. auto R = llvm::make_unique<BugReport>(*BT, Desc, N);
  178. R->addRange(ArgRange);
  179. if (ArgEx)
  180. bugreporter::trackNullOrUndefValue(N, ArgEx, *R);
  181. C.emitReport(std::move(R));
  182. }
  183. return true;
  184. }
  185. if (!CheckUninitFields)
  186. return false;
  187. if (Optional<nonloc::LazyCompoundVal> LV =
  188. V.getAs<nonloc::LazyCompoundVal>()) {
  189. class FindUninitializedField {
  190. public:
  191. SmallVector<const FieldDecl *, 10> FieldChain;
  192. private:
  193. StoreManager &StoreMgr;
  194. MemRegionManager &MrMgr;
  195. Store store;
  196. public:
  197. FindUninitializedField(StoreManager &storeMgr,
  198. MemRegionManager &mrMgr, Store s)
  199. : StoreMgr(storeMgr), MrMgr(mrMgr), store(s) {}
  200. bool Find(const TypedValueRegion *R) {
  201. QualType T = R->getValueType();
  202. if (const RecordType *RT = T->getAsStructureType()) {
  203. const RecordDecl *RD = RT->getDecl()->getDefinition();
  204. assert(RD && "Referred record has no definition");
  205. for (const auto *I : RD->fields()) {
  206. const FieldRegion *FR = MrMgr.getFieldRegion(I, R);
  207. FieldChain.push_back(I);
  208. T = I->getType();
  209. if (T->getAsStructureType()) {
  210. if (Find(FR))
  211. return true;
  212. }
  213. else {
  214. const SVal &V = StoreMgr.getBinding(store, loc::MemRegionVal(FR));
  215. if (V.isUndef())
  216. return true;
  217. }
  218. FieldChain.pop_back();
  219. }
  220. }
  221. return false;
  222. }
  223. };
  224. const LazyCompoundValData *D = LV->getCVData();
  225. FindUninitializedField F(C.getState()->getStateManager().getStoreManager(),
  226. C.getSValBuilder().getRegionManager(),
  227. D->getStore());
  228. if (F.Find(D->getRegion())) {
  229. if (ExplodedNode *N = C.generateSink()) {
  230. LazyInit_BT(BD, BT);
  231. SmallString<512> Str;
  232. llvm::raw_svector_ostream os(Str);
  233. os << "Passed-by-value struct argument contains uninitialized data";
  234. if (F.FieldChain.size() == 1)
  235. os << " (e.g., field: '" << *F.FieldChain[0] << "')";
  236. else {
  237. os << " (e.g., via the field chain: '";
  238. bool first = true;
  239. for (SmallVectorImpl<const FieldDecl *>::iterator
  240. DI = F.FieldChain.begin(), DE = F.FieldChain.end(); DI!=DE;++DI){
  241. if (first)
  242. first = false;
  243. else
  244. os << '.';
  245. os << **DI;
  246. }
  247. os << "')";
  248. }
  249. // Generate a report for this bug.
  250. auto R = llvm::make_unique<BugReport>(*BT, os.str(), N);
  251. R->addRange(ArgRange);
  252. // FIXME: enhance track back for uninitialized value for arbitrary
  253. // memregions
  254. C.emitReport(std::move(R));
  255. }
  256. return true;
  257. }
  258. }
  259. return false;
  260. }
  261. void CallAndMessageChecker::checkPreStmt(const CallExpr *CE,
  262. CheckerContext &C) const{
  263. const Expr *Callee = CE->getCallee()->IgnoreParens();
  264. ProgramStateRef State = C.getState();
  265. const LocationContext *LCtx = C.getLocationContext();
  266. SVal L = State->getSVal(Callee, LCtx);
  267. if (L.isUndef()) {
  268. if (!BT_call_undef)
  269. BT_call_undef.reset(new BuiltinBug(
  270. this, "Called function pointer is an uninitalized pointer value"));
  271. emitBadCall(BT_call_undef.get(), C, Callee);
  272. return;
  273. }
  274. ProgramStateRef StNonNull, StNull;
  275. std::tie(StNonNull, StNull) = State->assume(L.castAs<DefinedOrUnknownSVal>());
  276. if (StNull && !StNonNull) {
  277. if (!BT_call_null)
  278. BT_call_null.reset(new BuiltinBug(
  279. this, "Called function pointer is null (null dereference)"));
  280. emitBadCall(BT_call_null.get(), C, Callee);
  281. return;
  282. }
  283. C.addTransition(StNonNull);
  284. }
  285. void CallAndMessageChecker::checkPreStmt(const CXXDeleteExpr *DE,
  286. CheckerContext &C) const {
  287. SVal Arg = C.getSVal(DE->getArgument());
  288. if (Arg.isUndef()) {
  289. StringRef Desc;
  290. ExplodedNode *N = C.generateSink();
  291. if (!N)
  292. return;
  293. if (!BT_cxx_delete_undef)
  294. BT_cxx_delete_undef.reset(
  295. new BuiltinBug(this, "Uninitialized argument value"));
  296. if (DE->isArrayFormAsWritten())
  297. Desc = "Argument to 'delete[]' is uninitialized";
  298. else
  299. Desc = "Argument to 'delete' is uninitialized";
  300. BugType *BT = BT_cxx_delete_undef.get();
  301. auto R = llvm::make_unique<BugReport>(*BT, Desc, N);
  302. bugreporter::trackNullOrUndefValue(N, DE, *R);
  303. C.emitReport(std::move(R));
  304. return;
  305. }
  306. }
  307. void CallAndMessageChecker::checkPreCall(const CallEvent &Call,
  308. CheckerContext &C) const {
  309. ProgramStateRef State = C.getState();
  310. // If this is a call to a C++ method, check if the callee is null or
  311. // undefined.
  312. if (const CXXInstanceCall *CC = dyn_cast<CXXInstanceCall>(&Call)) {
  313. SVal V = CC->getCXXThisVal();
  314. if (V.isUndef()) {
  315. if (!BT_cxx_call_undef)
  316. BT_cxx_call_undef.reset(
  317. new BuiltinBug(this, "Called C++ object pointer is uninitialized"));
  318. emitBadCall(BT_cxx_call_undef.get(), C, CC->getCXXThisExpr());
  319. return;
  320. }
  321. ProgramStateRef StNonNull, StNull;
  322. std::tie(StNonNull, StNull) =
  323. State->assume(V.castAs<DefinedOrUnknownSVal>());
  324. if (StNull && !StNonNull) {
  325. if (!BT_cxx_call_null)
  326. BT_cxx_call_null.reset(
  327. new BuiltinBug(this, "Called C++ object pointer is null"));
  328. emitBadCall(BT_cxx_call_null.get(), C, CC->getCXXThisExpr());
  329. return;
  330. }
  331. State = StNonNull;
  332. }
  333. const Decl *D = Call.getDecl();
  334. const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D);
  335. if (FD) {
  336. // If we have a declaration, we can make sure we pass enough parameters to
  337. // the function.
  338. unsigned Params = FD->getNumParams();
  339. if (Call.getNumArgs() < Params) {
  340. ExplodedNode *N = C.generateSink();
  341. if (!N)
  342. return;
  343. LazyInit_BT("Function call with too few arguments", BT_call_few_args);
  344. SmallString<512> Str;
  345. llvm::raw_svector_ostream os(Str);
  346. os << "Function taking " << Params << " argument"
  347. << (Params == 1 ? "" : "s") << " is called with less ("
  348. << Call.getNumArgs() << ")";
  349. C.emitReport(
  350. llvm::make_unique<BugReport>(*BT_call_few_args, os.str(), N));
  351. }
  352. }
  353. // Don't check for uninitialized field values in arguments if the
  354. // caller has a body that is available and we have the chance to inline it.
  355. // This is a hack, but is a reasonable compromise betweens sometimes warning
  356. // and sometimes not depending on if we decide to inline a function.
  357. const bool checkUninitFields =
  358. !(C.getAnalysisManager().shouldInlineCall() && (D && D->getBody()));
  359. std::unique_ptr<BugType> *BT;
  360. if (isa<ObjCMethodCall>(Call))
  361. BT = &BT_msg_arg;
  362. else
  363. BT = &BT_call_arg;
  364. for (unsigned i = 0, e = Call.getNumArgs(); i != e; ++i) {
  365. const ParmVarDecl *ParamDecl = nullptr;
  366. if(FD && i < FD->getNumParams())
  367. ParamDecl = FD->getParamDecl(i);
  368. if (PreVisitProcessArg(C, Call.getArgSVal(i), Call.getArgSourceRange(i),
  369. Call.getArgExpr(i), /*IsFirstArgument=*/i == 0,
  370. checkUninitFields, Call, *BT, ParamDecl))
  371. return;
  372. }
  373. // If we make it here, record our assumptions about the callee.
  374. C.addTransition(State);
  375. }
  376. void CallAndMessageChecker::checkPreObjCMessage(const ObjCMethodCall &msg,
  377. CheckerContext &C) const {
  378. SVal recVal = msg.getReceiverSVal();
  379. if (recVal.isUndef()) {
  380. if (ExplodedNode *N = C.generateSink()) {
  381. BugType *BT = nullptr;
  382. switch (msg.getMessageKind()) {
  383. case OCM_Message:
  384. if (!BT_msg_undef)
  385. BT_msg_undef.reset(new BuiltinBug(this,
  386. "Receiver in message expression "
  387. "is an uninitialized value"));
  388. BT = BT_msg_undef.get();
  389. break;
  390. case OCM_PropertyAccess:
  391. if (!BT_objc_prop_undef)
  392. BT_objc_prop_undef.reset(new BuiltinBug(
  393. this, "Property access on an uninitialized object pointer"));
  394. BT = BT_objc_prop_undef.get();
  395. break;
  396. case OCM_Subscript:
  397. if (!BT_objc_subscript_undef)
  398. BT_objc_subscript_undef.reset(new BuiltinBug(
  399. this, "Subscript access on an uninitialized object pointer"));
  400. BT = BT_objc_subscript_undef.get();
  401. break;
  402. }
  403. assert(BT && "Unknown message kind.");
  404. auto R = llvm::make_unique<BugReport>(*BT, BT->getName(), N);
  405. const ObjCMessageExpr *ME = msg.getOriginExpr();
  406. R->addRange(ME->getReceiverRange());
  407. // FIXME: getTrackNullOrUndefValueVisitor can't handle "super" yet.
  408. if (const Expr *ReceiverE = ME->getInstanceReceiver())
  409. bugreporter::trackNullOrUndefValue(N, ReceiverE, *R);
  410. C.emitReport(std::move(R));
  411. }
  412. return;
  413. } else {
  414. // Bifurcate the state into nil and non-nil ones.
  415. DefinedOrUnknownSVal receiverVal = recVal.castAs<DefinedOrUnknownSVal>();
  416. ProgramStateRef state = C.getState();
  417. ProgramStateRef notNilState, nilState;
  418. std::tie(notNilState, nilState) = state->assume(receiverVal);
  419. // Handle receiver must be nil.
  420. if (nilState && !notNilState) {
  421. HandleNilReceiver(C, state, msg);
  422. return;
  423. }
  424. }
  425. }
  426. void CallAndMessageChecker::emitNilReceiverBug(CheckerContext &C,
  427. const ObjCMethodCall &msg,
  428. ExplodedNode *N) const {
  429. if (!BT_msg_ret)
  430. BT_msg_ret.reset(
  431. new BuiltinBug(this, "Receiver in message expression is 'nil'"));
  432. const ObjCMessageExpr *ME = msg.getOriginExpr();
  433. QualType ResTy = msg.getResultType();
  434. SmallString<200> buf;
  435. llvm::raw_svector_ostream os(buf);
  436. os << "The receiver of message '";
  437. ME->getSelector().print(os);
  438. os << "' is nil";
  439. if (ResTy->isReferenceType()) {
  440. os << ", which results in forming a null reference";
  441. } else {
  442. os << " and returns a value of type '";
  443. msg.getResultType().print(os, C.getLangOpts());
  444. os << "' that will be garbage";
  445. }
  446. auto report = llvm::make_unique<BugReport>(*BT_msg_ret, os.str(), N);
  447. report->addRange(ME->getReceiverRange());
  448. // FIXME: This won't track "self" in messages to super.
  449. if (const Expr *receiver = ME->getInstanceReceiver()) {
  450. bugreporter::trackNullOrUndefValue(N, receiver, *report);
  451. }
  452. C.emitReport(std::move(report));
  453. }
  454. static bool supportsNilWithFloatRet(const llvm::Triple &triple) {
  455. return (triple.getVendor() == llvm::Triple::Apple &&
  456. (triple.isiOS() || !triple.isMacOSXVersionLT(10,5)));
  457. }
  458. void CallAndMessageChecker::HandleNilReceiver(CheckerContext &C,
  459. ProgramStateRef state,
  460. const ObjCMethodCall &Msg) const {
  461. ASTContext &Ctx = C.getASTContext();
  462. static CheckerProgramPointTag Tag(this, "NilReceiver");
  463. // Check the return type of the message expression. A message to nil will
  464. // return different values depending on the return type and the architecture.
  465. QualType RetTy = Msg.getResultType();
  466. CanQualType CanRetTy = Ctx.getCanonicalType(RetTy);
  467. const LocationContext *LCtx = C.getLocationContext();
  468. if (CanRetTy->isStructureOrClassType()) {
  469. // Structure returns are safe since the compiler zeroes them out.
  470. SVal V = C.getSValBuilder().makeZeroVal(RetTy);
  471. C.addTransition(state->BindExpr(Msg.getOriginExpr(), LCtx, V), &Tag);
  472. return;
  473. }
  474. // Other cases: check if sizeof(return type) > sizeof(void*)
  475. if (CanRetTy != Ctx.VoidTy && C.getLocationContext()->getParentMap()
  476. .isConsumedExpr(Msg.getOriginExpr())) {
  477. // Compute: sizeof(void *) and sizeof(return type)
  478. const uint64_t voidPtrSize = Ctx.getTypeSize(Ctx.VoidPtrTy);
  479. const uint64_t returnTypeSize = Ctx.getTypeSize(CanRetTy);
  480. if (CanRetTy.getTypePtr()->isReferenceType()||
  481. (voidPtrSize < returnTypeSize &&
  482. !(supportsNilWithFloatRet(Ctx.getTargetInfo().getTriple()) &&
  483. (Ctx.FloatTy == CanRetTy ||
  484. Ctx.DoubleTy == CanRetTy ||
  485. Ctx.LongDoubleTy == CanRetTy ||
  486. Ctx.LongLongTy == CanRetTy ||
  487. Ctx.UnsignedLongLongTy == CanRetTy)))) {
  488. if (ExplodedNode *N = C.generateSink(state, nullptr, &Tag))
  489. emitNilReceiverBug(C, Msg, N);
  490. return;
  491. }
  492. // Handle the safe cases where the return value is 0 if the
  493. // receiver is nil.
  494. //
  495. // FIXME: For now take the conservative approach that we only
  496. // return null values if we *know* that the receiver is nil.
  497. // This is because we can have surprises like:
  498. //
  499. // ... = [[NSScreens screens] objectAtIndex:0];
  500. //
  501. // What can happen is that [... screens] could return nil, but
  502. // it most likely isn't nil. We should assume the semantics
  503. // of this case unless we have *a lot* more knowledge.
  504. //
  505. SVal V = C.getSValBuilder().makeZeroVal(RetTy);
  506. C.addTransition(state->BindExpr(Msg.getOriginExpr(), LCtx, V), &Tag);
  507. return;
  508. }
  509. C.addTransition(state);
  510. }
  511. #define REGISTER_CHECKER(name) \
  512. void ento::register##name(CheckerManager &mgr) { \
  513. CallAndMessageChecker *Checker = \
  514. mgr.registerChecker<CallAndMessageChecker>(); \
  515. Checker->Filter.Check_##name = true; \
  516. Checker->Filter.CheckName_##name = mgr.getCurrentCheckName(); \
  517. }
  518. REGISTER_CHECKER(CallAndMessageUnInitRefArg)
  519. REGISTER_CHECKER(CallAndMessageChecker)