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 "ClangSACheckers.h"
16 #include "clang/StaticAnalyzer/Core/Checker.h"
17 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
18 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
19 #include "llvm/ADT/StringSwitch.h"
21 using namespace clang;
26 class NoReturnFunctionChecker : public Checker< check::PostStmt<CallExpr> > {
28 void checkPostStmt(const CallExpr *CE, CheckerContext &C) const;
33 void NoReturnFunctionChecker::checkPostStmt(const CallExpr *CE,
34 CheckerContext &C) const {
35 const GRState *state = C.getState();
36 const Expr *Callee = CE->getCallee();
38 bool BuildSinks = getFunctionExtInfo(Callee->getType()).getNoReturn();
41 SVal L = state->getSVal(Callee);
42 const FunctionDecl *FD = L.getAsFunctionDecl();
46 if (FD->getAttr<AnalyzerNoReturnAttr>())
48 else if (const IdentifierInfo *II = FD->getIdentifier()) {
49 // HACK: Some functions are not marked noreturn, and don't return.
50 // Here are a few hardwired ones. If this takes too long, we can
51 // potentially cache these results.
53 = llvm::StringSwitch<bool>(llvm::StringRef(II->getName()))
58 // FIXME: This is just a wrapper around throwing an exception.
59 // Eventually inter-procedural analysis should handle this easily.
61 .Case("assfail", true)
62 .Case("db_error", true)
63 .Case("__assert", true)
64 .Case("__assert_rtn", true)
65 .Case("__assert_fail", true)
66 .Case("dtrace_assfail", true)
67 .Case("yy_fatal_error", true)
68 .Case("_XCAssertionFailureHandler", true)
69 .Case("_DTAssertionFailureHandler", true)
70 .Case("_TSAssertionFailureHandler", true)
79 void ento::registerNoReturnFunctionChecker(CheckerManager &mgr) {
80 mgr.registerChecker<NoReturnFunctionChecker>();