22 #include "llvm/ADT/StringSwitch.h" 25 using namespace clang;
30 class NoReturnFunctionChecker :
public Checker< check::PostCall,
31 check::PostObjCMessage > {
32 mutable Selector HandleFailureInFunctionSel;
33 mutable Selector HandleFailureInMethodSel;
35 void checkPostCall(
const CallEvent &CE, CheckerContext &C)
const;
36 void checkPostObjCMessage(
const ObjCMethodCall &msg, CheckerContext &C)
const;
41 void NoReturnFunctionChecker::checkPostCall(
const CallEvent &CE,
42 CheckerContext &C)
const {
43 bool BuildSinks =
false;
45 if (
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(CE.getDecl()))
46 BuildSinks = FD->hasAttr<AnalyzerNoReturnAttr>() || FD->isNoReturn();
48 const Expr *Callee = CE.getOriginExpr();
49 if (!BuildSinks && Callee)
52 if (!BuildSinks && CE.isGlobalCFunction()) {
58 = llvm::StringSwitch<bool>(StringRef(II->getName()))
66 .Case(
"assfail",
true)
67 .Case(
"db_error",
true)
68 .Case(
"__assert",
true)
69 .Case(
"__assert2",
true)
72 .Case(
"_wassert",
true)
73 .Case(
"__assert_rtn",
true)
74 .Case(
"__assert_fail",
true)
75 .Case(
"dtrace_assfail",
true)
76 .Case(
"yy_fatal_error",
true)
77 .Case(
"_XCAssertionFailureHandler",
true)
78 .Case(
"_DTAssertionFailureHandler",
true)
79 .Case(
"_TSAssertionFailureHandler",
true)
85 C.generateSink(C.getState(), C.getPredecessor());
88 void NoReturnFunctionChecker::checkPostObjCMessage(
const ObjCMethodCall &Msg,
89 CheckerContext &C)
const {
92 MD = MD->getCanonicalDecl();
93 if (MD->hasAttr<AnalyzerNoReturnAttr>()) {
94 C.generateSink(C.getState(), C.getPredecessor());
125 "handleFailureInFunction",
"file",
"lineNumber",
127 if (Sel != HandleFailureInFunctionSel)
132 "handleFailureInMethod",
"object",
"file",
133 "lineNumber",
"description");
134 if (Sel != HandleFailureInMethodSel)
140 C.generateSink(C.getState(), C.getPredecessor());
143 void ento::registerNoReturnFunctionChecker(CheckerManager &mgr) {
144 mgr.registerChecker<NoReturnFunctionChecker>();
Represents a function declaration or definition.
Smart pointer class that efficiently represents Objective-C method names.
ObjCMethodDecl - Represents an instance or class method declaration.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
One of these records is kept for each identifier that is lexed.
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
const ObjCInterfaceDecl * getReceiverInterface() const
Get the interface for the receiver.
Represents any expression that calls an Objective-C method.
Represents an ObjC class declaration.
This represents one expression.
unsigned getNumArgs() const
static void lazyInitKeywordSelector(Selector &Sel, ASTContext &Ctx, IdentifierInfos *... IIs)
const ObjCMethodDecl * getDecl() const override
Selector getSelector() const
Dataflow Directional Tag Classes.
FunctionType::ExtInfo getFunctionExtInfo(const Type &t)
bool isInstanceMessage() const