1 //===---- CheckerHelpers.cpp - Helper functions for checkers ----*- 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 file defines several static functions for use in checkers.
12 //===----------------------------------------------------------------------===//
14 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h"
15 #include "clang/AST/Expr.h"
17 // Recursively find any substatements containing macros
18 bool clang::ento::containsMacro(const Stmt *S) {
19 if (S->getLocStart().isMacroID())
22 if (S->getLocEnd().isMacroID())
25 for (Stmt::const_child_iterator I = S->child_begin(); I != S->child_end();
27 if (const Stmt *child = *I)
28 if (containsMacro(child))
34 // Recursively find any substatements containing enum constants
35 bool clang::ento::containsEnum(const Stmt *S) {
36 const DeclRefExpr *DR = dyn_cast<DeclRefExpr>(S);
38 if (DR && isa<EnumConstantDecl>(DR->getDecl()))
41 for (Stmt::const_child_iterator I = S->child_begin(); I != S->child_end();
43 if (const Stmt *child = *I)
44 if (containsEnum(child))
50 // Recursively find any substatements containing static vars
51 bool clang::ento::containsStaticLocal(const Stmt *S) {
52 const DeclRefExpr *DR = dyn_cast<DeclRefExpr>(S);
55 if (const VarDecl *VD = dyn_cast<VarDecl>(DR->getDecl()))
56 if (VD->isStaticLocal())
59 for (Stmt::const_child_iterator I = S->child_begin(); I != S->child_end();
61 if (const Stmt *child = *I)
62 if (containsStaticLocal(child))
68 // Recursively find any substatements containing __builtin_offsetof
69 bool clang::ento::containsBuiltinOffsetOf(const Stmt *S) {
70 if (isa<OffsetOfExpr>(S))
73 for (Stmt::const_child_iterator I = S->child_begin(); I != S->child_end();
75 if (const Stmt *child = *I)
76 if (containsBuiltinOffsetOf(child))