1 //=== NoReturnFunctionChecker.cpp -------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This defines NoReturnFunctionChecker, which evaluates functions that do not
11 // return to the caller.
13 //===----------------------------------------------------------------------===//
15 #include "GRExprEngineInternalChecks.h"
16 #include "clang/GR/PathSensitive/CheckerVisitor.h"
17 #include "llvm/ADT/StringSwitch.h"
19 using namespace clang
;
24 class NoReturnFunctionChecker
: public CheckerVisitor
<NoReturnFunctionChecker
> {
26 static void *getTag() { static int tag
= 0; return &tag
; }
27 void PostVisitCallExpr(CheckerContext
&C
, const CallExpr
*CE
);
32 void GR::RegisterNoReturnFunctionChecker(GRExprEngine
&Eng
) {
33 Eng
.registerCheck(new NoReturnFunctionChecker());
36 void NoReturnFunctionChecker::PostVisitCallExpr(CheckerContext
&C
,
38 const GRState
*state
= C
.getState();
39 const Expr
*Callee
= CE
->getCallee();
41 bool BuildSinks
= getFunctionExtInfo(Callee
->getType()).getNoReturn();
44 SVal L
= state
->getSVal(Callee
);
45 const FunctionDecl
*FD
= L
.getAsFunctionDecl();
49 if (FD
->getAttr
<AnalyzerNoReturnAttr
>())
51 else if (const IdentifierInfo
*II
= FD
->getIdentifier()) {
52 // HACK: Some functions are not marked noreturn, and don't return.
53 // Here are a few hardwired ones. If this takes too long, we can
54 // potentially cache these results.
56 = llvm::StringSwitch
<bool>(llvm::StringRef(II
->getName()))
61 // FIXME: This is just a wrapper around throwing an exception.
62 // Eventually inter-procedural analysis should handle this easily.
64 .Case("assfail", true)
65 .Case("db_error", true)
66 .Case("__assert", true)
67 .Case("__assert_rtn", true)
68 .Case("__assert_fail", true)
69 .Case("dtrace_assfail", true)
70 .Case("yy_fatal_error", true)
71 .Case("_XCAssertionFailureHandler", true)
72 .Case("_DTAssertionFailureHandler", true)
73 .Case("_TSAssertionFailureHandler", true)