1 //===--- CallAndMessageChecker.cpp ------------------------------*- C++ -*--==//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This defines CallAndMessageChecker, a builtin checker that checks for various
10 // errors of call and objc message expressions.
12 //===----------------------------------------------------------------------===//
14 #include "clang/AST/ExprCXX.h"
15 #include "clang/AST/ParentMap.h"
16 #include "clang/Basic/TargetInfo.h"
17 #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
18 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
19 #include "clang/StaticAnalyzer/Core/Checker.h"
20 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
21 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
22 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
23 #include "llvm/ADT/SmallString.h"
24 #include "llvm/ADT/StringExtras.h"
25 #include "llvm/Support/Casting.h"
26 #include "llvm/Support/raw_ostream.h"
28 using namespace clang
;
33 class CallAndMessageChecker
34 : public Checker
<check::PreObjCMessage
, check::ObjCMessageNil
,
36 mutable std::unique_ptr
<BugType
> BT_call_null
;
37 mutable std::unique_ptr
<BugType
> BT_call_undef
;
38 mutable std::unique_ptr
<BugType
> BT_cxx_call_null
;
39 mutable std::unique_ptr
<BugType
> BT_cxx_call_undef
;
40 mutable std::unique_ptr
<BugType
> BT_call_arg
;
41 mutable std::unique_ptr
<BugType
> BT_cxx_delete_undef
;
42 mutable std::unique_ptr
<BugType
> BT_msg_undef
;
43 mutable std::unique_ptr
<BugType
> BT_objc_prop_undef
;
44 mutable std::unique_ptr
<BugType
> BT_objc_subscript_undef
;
45 mutable std::unique_ptr
<BugType
> BT_msg_arg
;
46 mutable std::unique_ptr
<BugType
> BT_msg_ret
;
47 mutable std::unique_ptr
<BugType
> BT_call_few_args
;
50 // These correspond with the checker options. Looking at other checkers such
51 // as MallocChecker and CStringChecker, this is similar as to how they pull
52 // off having a modeling class, but emitting diagnostics under a smaller
53 // checker's name that can be safely disabled without disturbing the
54 // underlaying modeling engine.
55 // The reason behind having *checker options* rather then actual *checkers*
56 // here is that CallAndMessage is among the oldest checkers out there, and can
57 // be responsible for the majority of the reports on any given project. This
58 // is obviously not ideal, but changing checker name has the consequence of
59 // changing the issue hashes associated with the reports, and databases
60 // relying on this (CodeChecker, for instance) would suffer greatly.
61 // If we ever end up making changes to the issue hash generation algorithm, or
62 // the warning messages here, we should totally jump on the opportunity to
63 // convert these to actual checkers.
68 CK_CXXDeallocationArg
,
69 CK_ArgInitializedness
,
70 CK_ArgPointeeInitializedness
,
76 bool ChecksEnabled
[CK_NumCheckKinds
] = {false};
77 // The original core.CallAndMessage checker name. This should rather be an
78 // array, as seen in MallocChecker and CStringChecker.
79 CheckerNameRef OriginalName
;
81 void checkPreObjCMessage(const ObjCMethodCall
&msg
, CheckerContext
&C
) const;
83 /// Fill in the return value that results from messaging nil based on the
84 /// return type and architecture and diagnose if the return value will be
86 void checkObjCMessageNil(const ObjCMethodCall
&msg
, CheckerContext
&C
) const;
88 void checkPreCall(const CallEvent
&Call
, CheckerContext
&C
) const;
90 ProgramStateRef
checkFunctionPointerCall(const CallExpr
*CE
,
92 ProgramStateRef State
) const;
94 ProgramStateRef
checkCXXMethodCall(const CXXInstanceCall
*CC
,
96 ProgramStateRef State
) const;
98 ProgramStateRef
checkParameterCount(const CallEvent
&Call
, CheckerContext
&C
,
99 ProgramStateRef State
) const;
101 ProgramStateRef
checkCXXDeallocation(const CXXDeallocatorCall
*DC
,
103 ProgramStateRef State
) const;
105 ProgramStateRef
checkArgInitializedness(const CallEvent
&Call
,
107 ProgramStateRef State
) const;
110 bool PreVisitProcessArg(CheckerContext
&C
, SVal V
, SourceRange ArgRange
,
111 const Expr
*ArgEx
, int ArgumentNumber
,
112 bool CheckUninitFields
, const CallEvent
&Call
,
113 std::unique_ptr
<BugType
> &BT
,
114 const ParmVarDecl
*ParamDecl
) const;
116 static void emitBadCall(BugType
*BT
, CheckerContext
&C
, const Expr
*BadE
);
117 void emitNilReceiverBug(CheckerContext
&C
, const ObjCMethodCall
&msg
,
118 ExplodedNode
*N
) const;
120 void HandleNilReceiver(CheckerContext
&C
,
121 ProgramStateRef state
,
122 const ObjCMethodCall
&msg
) const;
124 void LazyInit_BT(const char *desc
, std::unique_ptr
<BugType
> &BT
) const {
126 BT
.reset(new BugType(OriginalName
, desc
));
128 bool uninitRefOrPointer(CheckerContext
&C
, SVal V
, SourceRange ArgRange
,
129 const Expr
*ArgEx
, std::unique_ptr
<BugType
> &BT
,
130 const ParmVarDecl
*ParamDecl
, const char *BD
,
131 int ArgumentNumber
) const;
133 } // end anonymous namespace
135 void CallAndMessageChecker::emitBadCall(BugType
*BT
, CheckerContext
&C
,
137 ExplodedNode
*N
= C
.generateErrorNode();
141 auto R
= std::make_unique
<PathSensitiveBugReport
>(*BT
, BT
->getDescription(), N
);
143 R
->addRange(BadE
->getSourceRange());
144 if (BadE
->isGLValue())
145 BadE
= bugreporter::getDerefExpr(BadE
);
146 bugreporter::trackExpressionValue(N
, BadE
, *R
);
148 C
.emitReport(std::move(R
));
151 static void describeUninitializedArgumentInCall(const CallEvent
&Call
,
153 llvm::raw_svector_ostream
&Os
) {
154 switch (Call
.getKind()) {
155 case CE_ObjCMessage
: {
156 const ObjCMethodCall
&Msg
= cast
<ObjCMethodCall
>(Call
);
157 switch (Msg
.getMessageKind()) {
159 Os
<< (ArgumentNumber
+ 1) << llvm::getOrdinalSuffix(ArgumentNumber
+ 1)
160 << " argument in message expression is an uninitialized value";
162 case OCM_PropertyAccess
:
163 assert(Msg
.isSetter() && "Getters have no args");
164 Os
<< "Argument for property setter is an uninitialized value";
167 if (Msg
.isSetter() && (ArgumentNumber
== 0))
168 Os
<< "Argument for subscript setter is an uninitialized value";
170 Os
<< "Subscript index is an uninitialized value";
173 llvm_unreachable("Unknown message kind.");
176 Os
<< (ArgumentNumber
+ 1) << llvm::getOrdinalSuffix(ArgumentNumber
+ 1)
177 << " block call argument is an uninitialized value";
180 Os
<< (ArgumentNumber
+ 1) << llvm::getOrdinalSuffix(ArgumentNumber
+ 1)
181 << " function call argument is an uninitialized value";
186 bool CallAndMessageChecker::uninitRefOrPointer(
187 CheckerContext
&C
, SVal V
, SourceRange ArgRange
, const Expr
*ArgEx
,
188 std::unique_ptr
<BugType
> &BT
, const ParmVarDecl
*ParamDecl
, const char *BD
,
189 int ArgumentNumber
) const {
191 // The pointee being uninitialized is a sign of code smell, not a bug, no need
193 if (!ChecksEnabled
[CK_ArgPointeeInitializedness
])
196 // No parameter declaration available, i.e. variadic function argument.
200 // If parameter is declared as pointer to const in function declaration,
201 // then check if corresponding argument in function call is
202 // pointing to undefined symbol value (uninitialized memory).
203 SmallString
<200> Buf
;
204 llvm::raw_svector_ostream
Os(Buf
);
206 if (ParamDecl
->getType()->isPointerType()) {
207 Os
<< (ArgumentNumber
+ 1) << llvm::getOrdinalSuffix(ArgumentNumber
+ 1)
208 << " function call argument is a pointer to uninitialized value";
209 } else if (ParamDecl
->getType()->isReferenceType()) {
210 Os
<< (ArgumentNumber
+ 1) << llvm::getOrdinalSuffix(ArgumentNumber
+ 1)
211 << " function call argument is an uninitialized value";
215 if(!ParamDecl
->getType()->getPointeeType().isConstQualified())
218 if (const MemRegion
*SValMemRegion
= V
.getAsRegion()) {
219 const ProgramStateRef State
= C
.getState();
220 const SVal PSV
= State
->getSVal(SValMemRegion
, C
.getASTContext().CharTy
);
222 if (ExplodedNode
*N
= C
.generateErrorNode()) {
224 auto R
= std::make_unique
<PathSensitiveBugReport
>(*BT
, Os
.str(), N
);
225 R
->addRange(ArgRange
);
227 bugreporter::trackExpressionValue(N
, ArgEx
, *R
);
229 C
.emitReport(std::move(R
));
238 class FindUninitializedField
{
240 SmallVector
<const FieldDecl
*, 10> FieldChain
;
243 StoreManager
&StoreMgr
;
244 MemRegionManager
&MrMgr
;
248 FindUninitializedField(StoreManager
&storeMgr
, MemRegionManager
&mrMgr
,
250 : StoreMgr(storeMgr
), MrMgr(mrMgr
), store(s
) {}
252 bool Find(const TypedValueRegion
*R
) {
253 QualType T
= R
->getValueType();
254 if (const RecordType
*RT
= T
->getAsStructureType()) {
255 const RecordDecl
*RD
= RT
->getDecl()->getDefinition();
256 assert(RD
&& "Referred record has no definition");
257 for (const auto *I
: RD
->fields()) {
258 const FieldRegion
*FR
= MrMgr
.getFieldRegion(I
, R
);
259 FieldChain
.push_back(I
);
261 if (T
->getAsStructureType()) {
265 SVal V
= StoreMgr
.getBinding(store
, loc::MemRegionVal(FR
));
269 FieldChain
.pop_back();
278 bool CallAndMessageChecker::PreVisitProcessArg(CheckerContext
&C
,
280 SourceRange ArgRange
,
283 bool CheckUninitFields
,
284 const CallEvent
&Call
,
285 std::unique_ptr
<BugType
> &BT
,
286 const ParmVarDecl
*ParamDecl
288 const char *BD
= "Uninitialized argument value";
290 if (uninitRefOrPointer(C
, V
, ArgRange
, ArgEx
, BT
, ParamDecl
, BD
,
295 if (!ChecksEnabled
[CK_ArgInitializedness
]) {
299 if (ExplodedNode
*N
= C
.generateErrorNode()) {
301 // Generate a report for this bug.
302 SmallString
<200> Buf
;
303 llvm::raw_svector_ostream
Os(Buf
);
304 describeUninitializedArgumentInCall(Call
, ArgumentNumber
, Os
);
305 auto R
= std::make_unique
<PathSensitiveBugReport
>(*BT
, Os
.str(), N
);
307 R
->addRange(ArgRange
);
309 bugreporter::trackExpressionValue(N
, ArgEx
, *R
);
310 C
.emitReport(std::move(R
));
315 if (!CheckUninitFields
)
318 if (auto LV
= V
.getAs
<nonloc::LazyCompoundVal
>()) {
319 const LazyCompoundValData
*D
= LV
->getCVData();
320 FindUninitializedField
F(C
.getState()->getStateManager().getStoreManager(),
321 C
.getSValBuilder().getRegionManager(),
324 if (F
.Find(D
->getRegion())) {
325 if (!ChecksEnabled
[CK_ArgInitializedness
]) {
329 if (ExplodedNode
*N
= C
.generateErrorNode()) {
331 SmallString
<512> Str
;
332 llvm::raw_svector_ostream
os(Str
);
333 os
<< "Passed-by-value struct argument contains uninitialized data";
335 if (F
.FieldChain
.size() == 1)
336 os
<< " (e.g., field: '" << *F
.FieldChain
[0] << "')";
338 os
<< " (e.g., via the field chain: '";
340 for (SmallVectorImpl
<const FieldDecl
*>::iterator
341 DI
= F
.FieldChain
.begin(), DE
= F
.FieldChain
.end(); DI
!=DE
;++DI
){
351 // Generate a report for this bug.
352 auto R
= std::make_unique
<PathSensitiveBugReport
>(*BT
, os
.str(), N
);
353 R
->addRange(ArgRange
);
356 bugreporter::trackExpressionValue(N
, ArgEx
, *R
);
357 // FIXME: enhance track back for uninitialized value for arbitrary
359 C
.emitReport(std::move(R
));
368 ProgramStateRef
CallAndMessageChecker::checkFunctionPointerCall(
369 const CallExpr
*CE
, CheckerContext
&C
, ProgramStateRef State
) const {
371 const Expr
*Callee
= CE
->getCallee()->IgnoreParens();
372 const LocationContext
*LCtx
= C
.getLocationContext();
373 SVal L
= State
->getSVal(Callee
, LCtx
);
376 if (!ChecksEnabled
[CK_FunctionPointer
]) {
381 BT_call_undef
.reset(new BugType(
383 "Called function pointer is an uninitialized pointer value"));
384 emitBadCall(BT_call_undef
.get(), C
, Callee
);
388 ProgramStateRef StNonNull
, StNull
;
389 std::tie(StNonNull
, StNull
) = State
->assume(L
.castAs
<DefinedOrUnknownSVal
>());
391 if (StNull
&& !StNonNull
) {
392 if (!ChecksEnabled
[CK_FunctionPointer
]) {
397 BT_call_null
.reset(new BugType(
398 OriginalName
, "Called function pointer is null (null dereference)"));
399 emitBadCall(BT_call_null
.get(), C
, Callee
);
406 ProgramStateRef
CallAndMessageChecker::checkParameterCount(
407 const CallEvent
&Call
, CheckerContext
&C
, ProgramStateRef State
) const {
409 // If we have a function or block declaration, we can make sure we pass
410 // enough parameters.
411 unsigned Params
= Call
.parameters().size();
412 if (Call
.getNumArgs() >= Params
)
415 if (!ChecksEnabled
[CK_ParameterCount
]) {
420 ExplodedNode
*N
= C
.generateErrorNode();
424 LazyInit_BT("Function call with too few arguments", BT_call_few_args
);
426 SmallString
<512> Str
;
427 llvm::raw_svector_ostream
os(Str
);
428 if (isa
<AnyFunctionCall
>(Call
)) {
431 assert(isa
<BlockCall
>(Call
));
434 os
<< "taking " << Params
<< " argument" << (Params
== 1 ? "" : "s")
435 << " is called with fewer (" << Call
.getNumArgs() << ")";
438 std::make_unique
<PathSensitiveBugReport
>(*BT_call_few_args
, os
.str(), N
));
442 ProgramStateRef
CallAndMessageChecker::checkCXXMethodCall(
443 const CXXInstanceCall
*CC
, CheckerContext
&C
, ProgramStateRef State
) const {
445 SVal V
= CC
->getCXXThisVal();
447 if (!ChecksEnabled
[CK_CXXThisMethodCall
]) {
451 if (!BT_cxx_call_undef
)
452 BT_cxx_call_undef
.reset(new BugType(
453 OriginalName
, "Called C++ object pointer is uninitialized"));
454 emitBadCall(BT_cxx_call_undef
.get(), C
, CC
->getCXXThisExpr());
458 ProgramStateRef StNonNull
, StNull
;
459 std::tie(StNonNull
, StNull
) = State
->assume(V
.castAs
<DefinedOrUnknownSVal
>());
461 if (StNull
&& !StNonNull
) {
462 if (!ChecksEnabled
[CK_CXXThisMethodCall
]) {
466 if (!BT_cxx_call_null
)
467 BT_cxx_call_null
.reset(
468 new BugType(OriginalName
, "Called C++ object pointer is null"));
469 emitBadCall(BT_cxx_call_null
.get(), C
, CC
->getCXXThisExpr());
477 CallAndMessageChecker::checkCXXDeallocation(const CXXDeallocatorCall
*DC
,
479 ProgramStateRef State
) const {
480 const CXXDeleteExpr
*DE
= DC
->getOriginExpr();
482 SVal Arg
= C
.getSVal(DE
->getArgument());
486 if (!ChecksEnabled
[CK_CXXDeallocationArg
]) {
492 ExplodedNode
*N
= C
.generateErrorNode();
495 if (!BT_cxx_delete_undef
)
496 BT_cxx_delete_undef
.reset(
497 new BugType(OriginalName
, "Uninitialized argument value"));
498 if (DE
->isArrayFormAsWritten())
499 Desc
= "Argument to 'delete[]' is uninitialized";
501 Desc
= "Argument to 'delete' is uninitialized";
503 std::make_unique
<PathSensitiveBugReport
>(*BT_cxx_delete_undef
, Desc
, N
);
504 bugreporter::trackExpressionValue(N
, DE
, *R
);
505 C
.emitReport(std::move(R
));
509 ProgramStateRef
CallAndMessageChecker::checkArgInitializedness(
510 const CallEvent
&Call
, CheckerContext
&C
, ProgramStateRef State
) const {
512 const Decl
*D
= Call
.getDecl();
514 // Don't check for uninitialized field values in arguments if the
515 // caller has a body that is available and we have the chance to inline it.
516 // This is a hack, but is a reasonable compromise betweens sometimes warning
517 // and sometimes not depending on if we decide to inline a function.
518 const bool checkUninitFields
=
519 !(C
.getAnalysisManager().shouldInlineCall() && (D
&& D
->getBody()));
521 std::unique_ptr
<BugType
> *BT
;
522 if (isa
<ObjCMethodCall
>(Call
))
527 const FunctionDecl
*FD
= dyn_cast_or_null
<FunctionDecl
>(D
);
528 for (unsigned i
= 0, e
= Call
.getNumArgs(); i
!= e
; ++i
) {
529 const ParmVarDecl
*ParamDecl
= nullptr;
530 if (FD
&& i
< FD
->getNumParams())
531 ParamDecl
= FD
->getParamDecl(i
);
532 if (PreVisitProcessArg(C
, Call
.getArgSVal(i
), Call
.getArgSourceRange(i
),
533 Call
.getArgExpr(i
), i
, checkUninitFields
, Call
, *BT
,
540 void CallAndMessageChecker::checkPreCall(const CallEvent
&Call
,
541 CheckerContext
&C
) const {
542 ProgramStateRef State
= C
.getState();
544 if (const CallExpr
*CE
= dyn_cast_or_null
<CallExpr
>(Call
.getOriginExpr()))
545 State
= checkFunctionPointerCall(CE
, C
, State
);
551 State
= checkParameterCount(Call
, C
, State
);
556 if (const auto *CC
= dyn_cast
<CXXInstanceCall
>(&Call
))
557 State
= checkCXXMethodCall(CC
, C
, State
);
562 if (const auto *DC
= dyn_cast
<CXXDeallocatorCall
>(&Call
))
563 State
= checkCXXDeallocation(DC
, C
, State
);
568 State
= checkArgInitializedness(Call
, C
, State
);
570 // If we make it here, record our assumptions about the callee.
571 C
.addTransition(State
);
574 void CallAndMessageChecker::checkPreObjCMessage(const ObjCMethodCall
&msg
,
575 CheckerContext
&C
) const {
576 SVal recVal
= msg
.getReceiverSVal();
577 if (recVal
.isUndef()) {
578 if (!ChecksEnabled
[CK_UndefReceiver
]) {
582 if (ExplodedNode
*N
= C
.generateErrorNode()) {
583 BugType
*BT
= nullptr;
584 switch (msg
.getMessageKind()) {
587 BT_msg_undef
.reset(new BugType(OriginalName
,
588 "Receiver in message expression "
589 "is an uninitialized value"));
590 BT
= BT_msg_undef
.get();
592 case OCM_PropertyAccess
:
593 if (!BT_objc_prop_undef
)
594 BT_objc_prop_undef
.reset(new BugType(
596 "Property access on an uninitialized object pointer"));
597 BT
= BT_objc_prop_undef
.get();
600 if (!BT_objc_subscript_undef
)
601 BT_objc_subscript_undef
.reset(new BugType(
603 "Subscript access on an uninitialized object pointer"));
604 BT
= BT_objc_subscript_undef
.get();
607 assert(BT
&& "Unknown message kind.");
609 auto R
= std::make_unique
<PathSensitiveBugReport
>(*BT
, BT
->getDescription(), N
);
610 const ObjCMessageExpr
*ME
= msg
.getOriginExpr();
611 R
->addRange(ME
->getReceiverRange());
613 // FIXME: getTrackNullOrUndefValueVisitor can't handle "super" yet.
614 if (const Expr
*ReceiverE
= ME
->getInstanceReceiver())
615 bugreporter::trackExpressionValue(N
, ReceiverE
, *R
);
616 C
.emitReport(std::move(R
));
622 void CallAndMessageChecker::checkObjCMessageNil(const ObjCMethodCall
&msg
,
623 CheckerContext
&C
) const {
624 HandleNilReceiver(C
, C
.getState(), msg
);
627 void CallAndMessageChecker::emitNilReceiverBug(CheckerContext
&C
,
628 const ObjCMethodCall
&msg
,
629 ExplodedNode
*N
) const {
630 if (!ChecksEnabled
[CK_NilReceiver
]) {
637 new BugType(OriginalName
, "Receiver in message expression is 'nil'"));
639 const ObjCMessageExpr
*ME
= msg
.getOriginExpr();
641 QualType ResTy
= msg
.getResultType();
643 SmallString
<200> buf
;
644 llvm::raw_svector_ostream
os(buf
);
645 os
<< "The receiver of message '";
646 ME
->getSelector().print(os
);
648 if (ResTy
->isReferenceType()) {
649 os
<< ", which results in forming a null reference";
651 os
<< " and returns a value of type '";
652 msg
.getResultType().print(os
, C
.getLangOpts());
653 os
<< "' that will be garbage";
657 std::make_unique
<PathSensitiveBugReport
>(*BT_msg_ret
, os
.str(), N
);
658 report
->addRange(ME
->getReceiverRange());
659 // FIXME: This won't track "self" in messages to super.
660 if (const Expr
*receiver
= ME
->getInstanceReceiver()) {
661 bugreporter::trackExpressionValue(N
, receiver
, *report
);
663 C
.emitReport(std::move(report
));
666 static bool supportsNilWithFloatRet(const llvm::Triple
&triple
) {
667 return (triple
.getVendor() == llvm::Triple::Apple
&&
668 (triple
.isiOS() || triple
.isWatchOS() ||
669 !triple
.isMacOSXVersionLT(10,5)));
672 void CallAndMessageChecker::HandleNilReceiver(CheckerContext
&C
,
673 ProgramStateRef state
,
674 const ObjCMethodCall
&Msg
) const {
675 ASTContext
&Ctx
= C
.getASTContext();
676 static CheckerProgramPointTag
Tag(this, "NilReceiver");
678 // Check the return type of the message expression. A message to nil will
679 // return different values depending on the return type and the architecture.
680 QualType RetTy
= Msg
.getResultType();
681 CanQualType CanRetTy
= Ctx
.getCanonicalType(RetTy
);
682 const LocationContext
*LCtx
= C
.getLocationContext();
684 if (CanRetTy
->isStructureOrClassType()) {
685 // Structure returns are safe since the compiler zeroes them out.
686 SVal V
= C
.getSValBuilder().makeZeroVal(RetTy
);
687 C
.addTransition(state
->BindExpr(Msg
.getOriginExpr(), LCtx
, V
), &Tag
);
691 // Other cases: check if sizeof(return type) > sizeof(void*)
692 if (CanRetTy
!= Ctx
.VoidTy
&& C
.getLocationContext()->getParentMap()
693 .isConsumedExpr(Msg
.getOriginExpr())) {
694 // Compute: sizeof(void *) and sizeof(return type)
695 const uint64_t voidPtrSize
= Ctx
.getTypeSize(Ctx
.VoidPtrTy
);
696 const uint64_t returnTypeSize
= Ctx
.getTypeSize(CanRetTy
);
698 if (CanRetTy
.getTypePtr()->isReferenceType()||
699 (voidPtrSize
< returnTypeSize
&&
700 !(supportsNilWithFloatRet(Ctx
.getTargetInfo().getTriple()) &&
701 (Ctx
.FloatTy
== CanRetTy
||
702 Ctx
.DoubleTy
== CanRetTy
||
703 Ctx
.LongDoubleTy
== CanRetTy
||
704 Ctx
.LongLongTy
== CanRetTy
||
705 Ctx
.UnsignedLongLongTy
== CanRetTy
)))) {
706 if (ExplodedNode
*N
= C
.generateErrorNode(state
, &Tag
))
707 emitNilReceiverBug(C
, Msg
, N
);
711 // Handle the safe cases where the return value is 0 if the
714 // FIXME: For now take the conservative approach that we only
715 // return null values if we *know* that the receiver is nil.
716 // This is because we can have surprises like:
718 // ... = [[NSScreens screens] objectAtIndex:0];
720 // What can happen is that [... screens] could return nil, but
721 // it most likely isn't nil. We should assume the semantics
722 // of this case unless we have *a lot* more knowledge.
724 SVal V
= C
.getSValBuilder().makeZeroVal(RetTy
);
725 C
.addTransition(state
->BindExpr(Msg
.getOriginExpr(), LCtx
, V
), &Tag
);
729 C
.addTransition(state
);
732 void ento::registerCallAndMessageModeling(CheckerManager
&mgr
) {
733 mgr
.registerChecker
<CallAndMessageChecker
>();
736 bool ento::shouldRegisterCallAndMessageModeling(const CheckerManager
&mgr
) {
740 void ento::registerCallAndMessageChecker(CheckerManager
&mgr
) {
741 CallAndMessageChecker
*checker
= mgr
.getChecker
<CallAndMessageChecker
>();
743 checker
->OriginalName
= mgr
.getCurrentCheckerName();
745 #define QUERY_CHECKER_OPTION(OPTION) \
746 checker->ChecksEnabled[CallAndMessageChecker::CK_##OPTION] = \
747 mgr.getAnalyzerOptions().getCheckerBooleanOption( \
748 mgr.getCurrentCheckerName(), #OPTION);
750 QUERY_CHECKER_OPTION(FunctionPointer
)
751 QUERY_CHECKER_OPTION(ParameterCount
)
752 QUERY_CHECKER_OPTION(CXXThisMethodCall
)
753 QUERY_CHECKER_OPTION(CXXDeallocationArg
)
754 QUERY_CHECKER_OPTION(ArgInitializedness
)
755 QUERY_CHECKER_OPTION(ArgPointeeInitializedness
)
756 QUERY_CHECKER_OPTION(NilReceiver
)
757 QUERY_CHECKER_OPTION(UndefReceiver
)
760 bool ento::shouldRegisterCallAndMessageChecker(const CheckerManager
&mgr
) {