21 #include "llvm/ADT/StringSwitch.h" 24 using namespace clang;
29 class NoReturnFunctionChecker :
public Checker< check::PostCall,
30 check::PostObjCMessage > {
31 mutable Selector HandleFailureInFunctionSel;
32 mutable Selector HandleFailureInMethodSel;
34 void checkPostCall(
const CallEvent &CE, CheckerContext &C)
const;
35 void checkPostObjCMessage(
const ObjCMethodCall &msg, CheckerContext &C)
const;
40 void NoReturnFunctionChecker::checkPostCall(
const CallEvent &CE,
41 CheckerContext &C)
const {
42 bool BuildSinks =
false;
44 if (
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(CE.getDecl()))
45 BuildSinks = FD->hasAttr<AnalyzerNoReturnAttr>() || FD->isNoReturn();
47 const Expr *Callee = CE.getOriginExpr();
48 if (!BuildSinks && Callee)
51 if (!BuildSinks && CE.isGlobalCFunction()) {
57 = llvm::StringSwitch<bool>(StringRef(II->getName()))
65 .Case(
"assfail",
true)
66 .Case(
"db_error",
true)
67 .Case(
"__assert",
true)
68 .Case(
"__assert2",
true)
71 .Case(
"_wassert",
true)
72 .Case(
"__assert_rtn",
true)
73 .Case(
"__assert_fail",
true)
74 .Case(
"dtrace_assfail",
true)
75 .Case(
"yy_fatal_error",
true)
76 .Case(
"_XCAssertionFailureHandler",
true)
77 .Case(
"_DTAssertionFailureHandler",
true)
78 .Case(
"_TSAssertionFailureHandler",
true)
84 C.generateSink(C.getState(), C.getPredecessor());
87 void NoReturnFunctionChecker::checkPostObjCMessage(
const ObjCMethodCall &Msg,
88 CheckerContext &C)
const {
91 MD = MD->getCanonicalDecl();
92 if (MD->hasAttr<AnalyzerNoReturnAttr>()) {
93 C.generateSink(C.getState(), C.getPredecessor());
124 "handleFailureInFunction",
"file",
"lineNumber",
126 if (Sel != HandleFailureInFunctionSel)
131 "handleFailureInMethod",
"object",
"file",
132 "lineNumber",
"description");
133 if (Sel != HandleFailureInMethodSel)
139 C.generateSink(C.getState(), C.getPredecessor());
142 void ento::registerNoReturnFunctionChecker(CheckerManager &mgr) {
143 mgr.registerChecker<NoReturnFunctionChecker>();
146 bool ento::shouldRegisterNoReturnFunctionChecker(
const LangOptions &LO) {
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.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
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