[analyzer] Refactoring: Move stuff into namespace 'GR'.
[clang.git] / lib / GR / Checkers / NoReturnFunctionChecker.cpp
blob739460f781d7f0c712f65529df318cd8aa03e678
1 //=== NoReturnFunctionChecker.cpp -------------------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
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;
20 using namespace GR;
22 namespace {
24 class NoReturnFunctionChecker : public CheckerVisitor<NoReturnFunctionChecker> {
25 public:
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,
37 const CallExpr *CE) {
38 const GRState *state = C.getState();
39 const Expr *Callee = CE->getCallee();
41 bool BuildSinks = getFunctionExtInfo(Callee->getType()).getNoReturn();
43 if (!BuildSinks) {
44 SVal L = state->getSVal(Callee);
45 const FunctionDecl *FD = L.getAsFunctionDecl();
46 if (!FD)
47 return;
49 if (FD->getAttr<AnalyzerNoReturnAttr>())
50 BuildSinks = true;
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.
55 BuildSinks
56 = llvm::StringSwitch<bool>(llvm::StringRef(II->getName()))
57 .Case("exit", true)
58 .Case("panic", true)
59 .Case("error", true)
60 .Case("Assert", true)
61 // FIXME: This is just a wrapper around throwing an exception.
62 // Eventually inter-procedural analysis should handle this easily.
63 .Case("ziperr", true)
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)
74 .Default(false);
78 if (BuildSinks)
79 C.generateSink(CE);