21#include "llvm/ADT/StringSwitch.h"
29class 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;
40void NoReturnFunctionChecker::checkPostCall(
const CallEvent &CE,
42 bool BuildSinks =
false;
44 if (
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(CE.
getDecl()))
45 BuildSinks = FD->hasAttr<AnalyzerNoReturnAttr>() || FD->isNoReturn();
47 if (
const CallExpr *CExpr = dyn_cast_or_null<CallExpr>(CE.
getOriginExpr());
48 CExpr && !BuildSinks) {
49 if (
const Expr *
C = CExpr->getCallee())
59 = llvm::StringSwitch<bool>(StringRef(II->getName()))
67 .Case(
"assfail",
true)
68 .Case(
"db_error",
true)
69 .Case(
"__assert",
true)
70 .Case(
"__assert2",
true)
73 .Case(
"_wassert",
true)
74 .Case(
"__assert_rtn",
true)
75 .Case(
"__assert_fail",
true)
76 .Case(
"dtrace_assfail",
true)
77 .Case(
"yy_fatal_error",
true)
78 .Case(
"_XCAssertionFailureHandler",
true)
79 .Case(
"_DTAssertionFailureHandler",
true)
80 .Case(
"_TSAssertionFailureHandler",
true)
86 C.generateSink(
C.getState(),
C.getPredecessor());
89void NoReturnFunctionChecker::checkPostObjCMessage(
const ObjCMethodCall &Msg,
90 CheckerContext &
C)
const {
92 if (
const ObjCMethodDecl *MD = Msg.
getDecl()) {
93 MD = MD->getCanonicalDecl();
94 if (MD->hasAttr<AnalyzerNoReturnAttr>()) {
95 C.generateSink(
C.getState(),
C.getPredecessor());
126 "handleFailureInFunction",
"file",
"lineNumber",
128 if (Sel != HandleFailureInFunctionSel)
133 "handleFailureInMethod",
"object",
"file",
134 "lineNumber",
"description");
135 if (Sel != HandleFailureInMethodSel)
141 C.generateSink(
C.getState(),
C.getPredecessor());
144void ento::registerNoReturnFunctionChecker(CheckerManager &mgr) {
148bool ento::shouldRegisterNoReturnFunctionChecker(
const CheckerManager &mgr) {
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
unsigned getNumArgs() const
Represents an abstract call to a function or method along a particular path.
virtual const Expr * getOriginExpr() const
Returns the expression whose value will be the result of this call.
const IdentifierInfo * getCalleeIdentifier() const
Returns the name of the callee, if its name is a simple identifier.
bool isGlobalCFunction(StringRef SpecificName=StringRef()) const
Returns true if the callee is an externally-visible function in the top-level namespace,...
virtual const Decl * getDecl() const
Returns the declaration of the function or method that will be called.
CHECKER * registerChecker(AT &&...Args)
Register a single-part checker (derived from Checker): construct its singleton instance,...
Simple checker classes that implement one frontend (i.e.
const ObjCMethodDecl * getDecl() const override
Returns the declaration of the function or method that will be called.
bool isInstanceMessage() const
const ObjCInterfaceDecl * getReceiverInterface() const
Get the interface for the receiver.
Selector getSelector() const
The JSON file list parser is used to communicate input to InstallAPI.
static void lazyInitKeywordSelector(Selector &Sel, ASTContext &Ctx, IdentifierInfos *... IIs)
FunctionType::ExtInfo getFunctionExtInfo(const Type &t)