clang  14.0.0git
LoopUnrolling.cpp
Go to the documentation of this file.
1 //===--- LoopUnrolling.cpp - Unroll loops -----------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// This file contains functions which are used to decide if a loop worth to be
10 /// unrolled. Moreover, these functions manages the stack of loop which is
11 /// tracked by the ProgramState.
12 ///
13 //===----------------------------------------------------------------------===//
14 
20 
21 using namespace clang;
22 using namespace ento;
23 using namespace clang::ast_matchers;
24 
25 static const int MAXIMUM_STEP_UNROLLED = 128;
26 
27 struct LoopState {
28 private:
29  enum Kind { Normal, Unrolled } K;
30  const Stmt *LoopStmt;
31  const LocationContext *LCtx;
32  unsigned maxStep;
33  LoopState(Kind InK, const Stmt *S, const LocationContext *L, unsigned N)
34  : K(InK), LoopStmt(S), LCtx(L), maxStep(N) {}
35 
36 public:
37  static LoopState getNormal(const Stmt *S, const LocationContext *L,
38  unsigned N) {
39  return LoopState(Normal, S, L, N);
40  }
41  static LoopState getUnrolled(const Stmt *S, const LocationContext *L,
42  unsigned N) {
43  return LoopState(Unrolled, S, L, N);
44  }
45  bool isUnrolled() const { return K == Unrolled; }
46  unsigned getMaxStep() const { return maxStep; }
47  const Stmt *getLoopStmt() const { return LoopStmt; }
48  const LocationContext *getLocationContext() const { return LCtx; }
49  bool operator==(const LoopState &X) const {
50  return K == X.K && LoopStmt == X.LoopStmt;
51  }
52  void Profile(llvm::FoldingSetNodeID &ID) const {
53  ID.AddInteger(K);
54  ID.AddPointer(LoopStmt);
55  ID.AddPointer(LCtx);
56  ID.AddInteger(maxStep);
57  }
58 };
59 
60 // The tracked stack of loops. The stack indicates that which loops the
61 // simulated element contained by. The loops are marked depending if we decided
62 // to unroll them.
63 // TODO: The loop stack should not need to be in the program state since it is
64 // lexical in nature. Instead, the stack of loops should be tracked in the
65 // LocationContext.
67 
68 namespace clang {
69 namespace ento {
70 
71 static bool isLoopStmt(const Stmt *S) {
72  return S && (isa<ForStmt>(S) || isa<WhileStmt>(S) || isa<DoStmt>(S));
73 }
74 
76  auto LS = State->get<LoopStack>();
77  if (!LS.isEmpty() && LS.getHead().getLoopStmt() == LoopStmt)
78  State = State->set<LoopStack>(LS.getTail());
79  return State;
80 }
81 
82 static internal::Matcher<Stmt> simpleCondition(StringRef BindName,
83  StringRef RefName) {
84  return binaryOperator(
85  anyOf(hasOperatorName("<"), hasOperatorName(">"),
86  hasOperatorName("<="), hasOperatorName(">="),
87  hasOperatorName("!=")),
88  hasEitherOperand(ignoringParenImpCasts(
89  declRefExpr(to(varDecl(hasType(isInteger())).bind(BindName)))
90  .bind(RefName))),
91  hasEitherOperand(
92  ignoringParenImpCasts(integerLiteral().bind("boundNum"))))
93  .bind("conditionOperator");
94 }
95 
96 static internal::Matcher<Stmt>
97 changeIntBoundNode(internal::Matcher<Decl> VarNodeMatcher) {
98  return anyOf(
99  unaryOperator(anyOf(hasOperatorName("--"), hasOperatorName("++")),
100  hasUnaryOperand(ignoringParenImpCasts(
101  declRefExpr(to(varDecl(VarNodeMatcher)))))),
102  binaryOperator(isAssignmentOperator(),
103  hasLHS(ignoringParenImpCasts(
104  declRefExpr(to(varDecl(VarNodeMatcher)))))));
105 }
106 
107 static internal::Matcher<Stmt>
108 callByRef(internal::Matcher<Decl> VarNodeMatcher) {
109  return callExpr(forEachArgumentWithParam(
110  declRefExpr(to(varDecl(VarNodeMatcher))),
111  parmVarDecl(hasType(references(qualType(unless(isConstQualified())))))));
112 }
113 
114 static internal::Matcher<Stmt>
115 assignedToRef(internal::Matcher<Decl> VarNodeMatcher) {
117  allOf(hasType(referenceType()),
118  hasInitializer(anyOf(
119  initListExpr(has(declRefExpr(to(varDecl(VarNodeMatcher))))),
120  declRefExpr(to(varDecl(VarNodeMatcher)))))))));
121 }
122 
123 static internal::Matcher<Stmt>
124 getAddrTo(internal::Matcher<Decl> VarNodeMatcher) {
125  return unaryOperator(
126  hasOperatorName("&"),
127  hasUnaryOperand(declRefExpr(hasDeclaration(VarNodeMatcher))));
128 }
129 
130 static internal::Matcher<Stmt> hasSuspiciousStmt(StringRef NodeName) {
131  return hasDescendant(stmt(
133  // Escaping and not known mutation of the loop counter is handled
134  // by exclusion of assigning and address-of operators and
135  // pass-by-ref function calls on the loop counter from the body.
136  changeIntBoundNode(equalsBoundNode(std::string(NodeName))),
137  callByRef(equalsBoundNode(std::string(NodeName))),
138  getAddrTo(equalsBoundNode(std::string(NodeName))),
139  assignedToRef(equalsBoundNode(std::string(NodeName))))));
140 }
141 
142 static internal::Matcher<Stmt> forLoopMatcher() {
143  return forStmt(
144  hasCondition(simpleCondition("initVarName", "initVarRef")),
145  // Initialization should match the form: 'int i = 6' or 'i = 42'.
146  hasLoopInit(
147  anyOf(declStmt(hasSingleDecl(
148  varDecl(allOf(hasInitializer(ignoringParenImpCasts(
149  integerLiteral().bind("initNum"))),
150  equalsBoundNode("initVarName"))))),
152  equalsBoundNode("initVarName"))))),
153  hasRHS(ignoringParenImpCasts(
154  integerLiteral().bind("initNum")))))),
155  // Incrementation should be a simple increment or decrement
156  // operator call.
157  hasIncrement(unaryOperator(
158  anyOf(hasOperatorName("++"), hasOperatorName("--")),
159  hasUnaryOperand(declRefExpr(
160  to(varDecl(allOf(equalsBoundNode("initVarName"),
161  hasType(isInteger())))))))),
162  unless(hasBody(hasSuspiciousStmt("initVarName"))))
163  .bind("forLoop");
164 }
165 
166 static bool isCapturedByReference(ExplodedNode *N, const DeclRefExpr *DR) {
167 
168  // Get the lambda CXXRecordDecl
170  const LocationContext *LocCtxt = N->getLocationContext();
171  const Decl *D = LocCtxt->getDecl();
172  const auto *MD = cast<CXXMethodDecl>(D);
173  assert(MD && MD->getParent()->isLambda() &&
174  "Captured variable should only be seen while evaluating a lambda");
175  const CXXRecordDecl *LambdaCXXRec = MD->getParent();
176 
177  // Lookup the fields of the lambda
178  llvm::DenseMap<const VarDecl *, FieldDecl *> LambdaCaptureFields;
179  FieldDecl *LambdaThisCaptureField;
180  LambdaCXXRec->getCaptureFields(LambdaCaptureFields, LambdaThisCaptureField);
181 
182  // Check if the counter is captured by reference
183  const VarDecl *VD = cast<VarDecl>(DR->getDecl()->getCanonicalDecl());
184  assert(VD);
185  const FieldDecl *FD = LambdaCaptureFields[VD];
186  assert(FD && "Captured variable without a corresponding field");
187  return FD->getType()->isReferenceType();
188 }
189 
190 // A loop counter is considered escaped if:
191 // case 1: It is a global variable.
192 // case 2: It is a reference parameter or a reference capture.
193 // case 3: It is assigned to a non-const reference variable or parameter.
194 // case 4: Has its address taken.
195 static bool isPossiblyEscaped(ExplodedNode *N, const DeclRefExpr *DR) {
196  const VarDecl *VD = cast<VarDecl>(DR->getDecl()->getCanonicalDecl());
197  assert(VD);
198  // Case 1:
199  if (VD->hasGlobalStorage())
200  return true;
201 
202  const bool IsRefParamOrCapture =
203  isa<ParmVarDecl>(VD) || DR->refersToEnclosingVariableOrCapture();
204  // Case 2:
206  isCapturedByReference(N, DR)) ||
207  (IsRefParamOrCapture && VD->getType()->isReferenceType()))
208  return true;
209 
210  while (!N->pred_empty()) {
211  // FIXME: getStmtForDiagnostics() does nasty things in order to provide
212  // a valid statement for body farms, do we need this behavior here?
213  const Stmt *S = N->getStmtForDiagnostics();
214  if (!S) {
215  N = N->getFirstPred();
216  continue;
217  }
218 
219  if (const DeclStmt *DS = dyn_cast<DeclStmt>(S)) {
220  for (const Decl *D : DS->decls()) {
221  // Once we reach the declaration of the VD we can return.
222  if (D->getCanonicalDecl() == VD)
223  return false;
224  }
225  }
226  // Check the usage of the pass-by-ref function calls and adress-of operator
227  // on VD and reference initialized by VD.
228  ASTContext &ASTCtx =
230  // Case 3 and 4:
231  auto Match =
232  match(stmt(anyOf(callByRef(equalsNode(VD)), getAddrTo(equalsNode(VD)),
233  assignedToRef(equalsNode(VD)))),
234  *S, ASTCtx);
235  if (!Match.empty())
236  return true;
237 
238  N = N->getFirstPred();
239  }
240 
241  // Reference parameter and reference capture will not be found.
242  if (IsRefParamOrCapture)
243  return false;
244 
245  llvm_unreachable("Reached root without finding the declaration of VD");
246 }
247 
248 bool shouldCompletelyUnroll(const Stmt *LoopStmt, ASTContext &ASTCtx,
249  ExplodedNode *Pred, unsigned &maxStep) {
250 
251  if (!isLoopStmt(LoopStmt))
252  return false;
253 
254  // TODO: Match the cases where the bound is not a concrete literal but an
255  // integer with known value
256  auto Matches = match(forLoopMatcher(), *LoopStmt, ASTCtx);
257  if (Matches.empty())
258  return false;
259 
260  const auto *CounterVarRef = Matches[0].getNodeAs<DeclRefExpr>("initVarRef");
261  llvm::APInt BoundNum =
262  Matches[0].getNodeAs<IntegerLiteral>("boundNum")->getValue();
263  llvm::APInt InitNum =
264  Matches[0].getNodeAs<IntegerLiteral>("initNum")->getValue();
265  auto CondOp = Matches[0].getNodeAs<BinaryOperator>("conditionOperator");
266  if (InitNum.getBitWidth() != BoundNum.getBitWidth()) {
267  InitNum = InitNum.zextOrSelf(BoundNum.getBitWidth());
268  BoundNum = BoundNum.zextOrSelf(InitNum.getBitWidth());
269  }
270 
271  if (CondOp->getOpcode() == BO_GE || CondOp->getOpcode() == BO_LE)
272  maxStep = (BoundNum - InitNum + 1).abs().getZExtValue();
273  else
274  maxStep = (BoundNum - InitNum).abs().getZExtValue();
275 
276  // Check if the counter of the loop is not escaped before.
277  return !isPossiblyEscaped(Pred, CounterVarRef);
278 }
279 
280 bool madeNewBranch(ExplodedNode *N, const Stmt *LoopStmt) {
281  const Stmt *S = nullptr;
282  while (!N->pred_empty()) {
283  if (N->succ_size() > 1)
284  return true;
285 
286  ProgramPoint P = N->getLocation();
287  if (Optional<BlockEntrance> BE = P.getAs<BlockEntrance>())
288  S = BE->getBlock()->getTerminatorStmt();
289 
290  if (S == LoopStmt)
291  return false;
292 
293  N = N->getFirstPred();
294  }
295 
296  llvm_unreachable("Reached root without encountering the previous step");
297 }
298 
299 // updateLoopStack is called on every basic block, therefore it needs to be fast
301  ExplodedNode *Pred, unsigned maxVisitOnPath) {
302  auto State = Pred->getState();
303  auto LCtx = Pred->getLocationContext();
304 
305  if (!isLoopStmt(LoopStmt))
306  return State;
307 
308  auto LS = State->get<LoopStack>();
309  if (!LS.isEmpty() && LoopStmt == LS.getHead().getLoopStmt() &&
310  LCtx == LS.getHead().getLocationContext()) {
311  if (LS.getHead().isUnrolled() && madeNewBranch(Pred, LoopStmt)) {
312  State = State->set<LoopStack>(LS.getTail());
313  State = State->add<LoopStack>(
314  LoopState::getNormal(LoopStmt, LCtx, maxVisitOnPath));
315  }
316  return State;
317  }
318  unsigned maxStep;
319  if (!shouldCompletelyUnroll(LoopStmt, ASTCtx, Pred, maxStep)) {
320  State = State->add<LoopStack>(
321  LoopState::getNormal(LoopStmt, LCtx, maxVisitOnPath));
322  return State;
323  }
324 
325  unsigned outerStep = (LS.isEmpty() ? 1 : LS.getHead().getMaxStep());
326 
327  unsigned innerMaxStep = maxStep * outerStep;
328  if (innerMaxStep > MAXIMUM_STEP_UNROLLED)
329  State = State->add<LoopStack>(
330  LoopState::getNormal(LoopStmt, LCtx, maxVisitOnPath));
331  else
332  State = State->add<LoopStack>(
333  LoopState::getUnrolled(LoopStmt, LCtx, innerMaxStep));
334  return State;
335 }
336 
338  auto LS = State->get<LoopStack>();
339  if (LS.isEmpty() || !LS.getHead().isUnrolled())
340  return false;
341  return true;
342 }
343 }
344 }
LoopState::getLoopStmt
const Stmt * getLoopStmt() const
Definition: LoopUnrolling.cpp:47
clang::AnalysisDeclContext::getASTContext
ASTContext & getASTContext() const
Definition: AnalysisDeclContext.h:104
clang::ast_matchers::initListExpr
const internal::VariadicDynCastAllOfMatcher< Stmt, InitListExpr > initListExpr
Matches init list expressions.
Definition: ASTMatchersInternal.cpp:848
clang::ento::ExplodedNode::getLocationContext
const LocationContext * getLocationContext() const
Definition: ExplodedGraph.h:146
clang::interp::APInt
llvm::APInt APInt
Definition: Integral.h:27
clang::LocationContext
It wraps the AnalysisDeclContext to represent both the call stack with the help of StackFrameContext ...
Definition: AnalysisDeclContext.h:215
clang::ento::ExplodedNode::succ_size
unsigned succ_size() const
Definition: ExplodedGraph.h:199
clang::ento::isPossiblyEscaped
static bool isPossiblyEscaped(ExplodedNode *N, const DeclRefExpr *DR)
Definition: LoopUnrolling.cpp:195
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::ast_matchers::stmt
const internal::VariadicAllOfMatcher< Stmt > stmt
Matches statements.
Definition: ASTMatchersInternal.cpp:809
LoopState::getNormal
static LoopState getNormal(const Stmt *S, const LocationContext *L, unsigned N)
Definition: LoopUnrolling.cpp:37
clang::VarDecl::hasGlobalStorage
bool hasGlobalStorage() const
Returns true for all variables that do not have local storage.
Definition: Decl.h:1143
LoopUnrolling.h
clang::ento::simpleCondition
static internal::Matcher< Stmt > simpleCondition(StringRef BindName, StringRef RefName)
Definition: LoopUnrolling.cpp:82
clang::ast_matchers::anyOf
const internal::VariadicOperatorMatcherFunc< 2, std::numeric_limits< unsigned >::max()> anyOf
Matches if any of the given matchers matches.
Definition: ASTMatchersInternal.cpp:988
LoopState::getMaxStep
unsigned getMaxStep() const
Definition: LoopUnrolling.cpp:46
clang::FieldDecl
Represents a member of a struct/union/class.
Definition: Decl.h:2835
clang::ento::ExplodedNode
Definition: ExplodedGraph.h:65
clang::ento::ExplodedNode::pred_empty
bool pred_empty() const
Definition: ExplodedGraph.h:202
clang::ento::updateLoopStack
ProgramStateRef updateLoopStack(const Stmt *LoopStmt, ASTContext &ASTCtx, ExplodedNode *Pred, unsigned maxVisitOnPath)
Updates the stack of loops contained by the ProgramState.
Definition: LoopUnrolling.cpp:300
clang::ast_matchers::allOf
const internal::VariadicOperatorMatcherFunc< 2, std::numeric_limits< unsigned >::max()> allOf
Matches if all given matchers match.
Definition: ASTMatchersInternal.cpp:991
llvm::Optional
Definition: LLVM.h:40
clang::ento::shouldCompletelyUnroll
bool shouldCompletelyUnroll(const Stmt *LoopStmt, ASTContext &ASTCtx, ExplodedNode *Pred, unsigned &maxStep)
Definition: LoopUnrolling.cpp:248
clang::ast_matchers::returnStmt
const internal::VariadicDynCastAllOfMatcher< Stmt, ReturnStmt > returnStmt
Matches return statements.
Definition: ASTMatchersInternal.cpp:902
clang::tooling::X
static ToolExecutorPluginRegistry::Add< AllTUsToolExecutorPlugin > X("all-TUs", "Runs FrontendActions on all TUs in the compilation database. " "Tool results are stored in memory.")
REGISTER_LIST_WITH_PROGRAMSTATE
#define REGISTER_LIST_WITH_PROGRAMSTATE(Name, Elem)
Declares an immutable list type NameTy, suitable for placement into the ProgramState.
Definition: ProgramStateTrait.h:132
ASTMatchFinder.h
clang::ento::isUnrolledState
bool isUnrolledState(ProgramStateRef State)
Returns if the given State indicates that is inside a completely unrolled loop.
Definition: LoopUnrolling.cpp:337
LoopState
Definition: LoopUnrolling.cpp:27
clang::ento::assignedToRef
static internal::Matcher< Stmt > assignedToRef(internal::Matcher< Decl > VarNodeMatcher)
Definition: LoopUnrolling.cpp:115
getValue
static SVal getValue(SVal val, SValBuilder &svalBuilder)
Definition: ArrayBoundCheckerV2.cpp:277
CallEvent.h
clang::Type::isReferenceType
bool isReferenceType() const
Definition: Type.h:6685
clang::IntegerLiteral
Definition: Expr.h:1488
clang::ento::ExplodedNode::getState
const ProgramStateRef & getState() const
Definition: ExplodedGraph.h:169
clang::ast_matchers
Definition: ASTMatchers.h:98
LoopState::operator==
bool operator==(const LoopState &X) const
Definition: LoopUnrolling.cpp:49
clang::LocationContext::getAnalysisDeclContext
AnalysisDeclContext * getAnalysisDeclContext() const
Definition: AnalysisDeclContext.h:241
clang::BinaryOperator
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:3803
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:212
ASTMatchers.h
clang::ento::processLoopEnd
ProgramStateRef processLoopEnd(const Stmt *LoopStmt, ProgramStateRef State)
Updates the given ProgramState.
Definition: LoopUnrolling.cpp:75
clang::ast_matchers::switchStmt
const internal::VariadicDynCastAllOfMatcher< Stmt, SwitchStmt > switchStmt
Matches switch statements.
Definition: ASTMatchersInternal.cpp:906
clang::Decl::getCanonicalDecl
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:901
clang::DeclRefExpr::getDecl
ValueDecl * getDecl()
Definition: Expr.h:1289
LoopState::Profile
void Profile(llvm::FoldingSetNodeID &ID) const
Definition: LoopUnrolling.cpp:52
clang::VarDecl
Represents a variable declaration or definition.
Definition: Decl.h:876
clang::ast_matchers::binaryOperator
const internal::VariadicDynCastAllOfMatcher< Stmt, BinaryOperator > binaryOperator
Matches binary operator expressions.
Definition: ASTMatchersInternal.cpp:946
clang::ast_matchers::unless
const internal::VariadicOperatorMatcherFunc< 1, 1 > unless
Matches if the provided matcher does not match.
Definition: ASTMatchersInternal.cpp:1024
clang::BlockEntrance
Definition: ProgramPoint.h:225
clang::CXXRecordDecl
Represents a C++ struct/union/class.
Definition: DeclCXX.h:255
P
StringRef P
Definition: ASTMatchersInternal.cpp:563
clang::ast_matchers::unaryOperator
const internal::VariadicDynCastAllOfMatcher< Stmt, UnaryOperator > unaryOperator
Matches unary operator expressions.
Definition: ASTMatchersInternal.cpp:951
clang::ento::isLoopStmt
static bool isLoopStmt(const Stmt *S)
Definition: LoopUnrolling.cpp:71
LoopState::getUnrolled
static LoopState getUnrolled(const Stmt *S, const LocationContext *L, unsigned N)
Definition: LoopUnrolling.cpp:41
clang::ast_matchers::gotoStmt
const internal::VariadicDynCastAllOfMatcher< Stmt, GotoStmt > gotoStmt
Matches goto statements.
Definition: ASTMatchersInternal.cpp:903
clang::DeclContext::getParent
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:1860
clang::ento::ExplodedNode::getFirstPred
ExplodedNode * getFirstPred()
Definition: ExplodedGraph.h:210
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:89
clang::ento::madeNewBranch
bool madeNewBranch(ExplodedNode *N, const Stmt *LoopStmt)
Definition: LoopUnrolling.cpp:280
State
LineState State
Definition: UnwrappedLineFormatter.cpp:986
clang::ast_matchers::hasDescendant
const internal::ArgumentAdaptingMatcherFunc< internal::HasDescendantMatcher > hasDescendant
Matches AST nodes that have descendant AST nodes that match the provided matcher.
Definition: ASTMatchersInternal.cpp:1009
clang::ast_matchers::callExpr
const internal::VariadicDynCastAllOfMatcher< Stmt, CallExpr > callExpr
Matches call expressions.
Definition: ASTMatchersInternal.cpp:816
CheckerContext.h
clang::DeclStmt
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Definition: Stmt.h:1292
clang::ento::isCapturedByReference
static bool isCapturedByReference(ExplodedNode *N, const DeclRefExpr *DR)
Definition: LoopUnrolling.cpp:166
clang::ast_matchers::declRefExpr
const internal::VariadicDynCastAllOfMatcher< Stmt, DeclRefExpr > declRefExpr
Matches expressions that refer to declarations.
Definition: ASTMatchersInternal.cpp:890
clang::ento::callByRef
static internal::Matcher< Stmt > callByRef(internal::Matcher< Decl > VarNodeMatcher)
Definition: LoopUnrolling.cpp:108
clang::Builtin::ID
ID
Definition: Builtins.h:48
clang
Definition: CalledOnceCheck.h:17
LoopState::isUnrolled
bool isUnrolled() const
Definition: LoopUnrolling.cpp:45
clang::ast_matchers::referenceType
const AstTypeMatcher< ReferenceType > referenceType
Matches both lvalue and rvalue reference types.
Definition: ASTMatchersInternal.cpp:1051
clang::ento::ExplodedNode::getLocation
ProgramPoint getLocation() const
getLocation - Returns the edge associated with the given node.
Definition: ExplodedGraph.h:144
clang::Stmt
Stmt - This represents one statement.
Definition: Stmt.h:69
clang::ast_matchers::forStmt
const internal::VariadicDynCastAllOfMatcher< Stmt, ForStmt > forStmt
Matches for statements.
Definition: ASTMatchersInternal.cpp:894
clang::ast_matchers::match
SmallVector< BoundNodes, 1 > match(MatcherT Matcher, const NodeT &Node, ASTContext &Context)
Returns the results of matching Matcher on Node.
Definition: ASTMatchFinder.h:312
clang::ento::changeIntBoundNode
static internal::Matcher< Stmt > changeIntBoundNode(internal::Matcher< Decl > VarNodeMatcher)
Definition: LoopUnrolling.cpp:97
clang::CXXRecordDecl::getCaptureFields
void getCaptureFields(llvm::DenseMap< const VarDecl *, FieldDecl * > &Captures, FieldDecl *&ThisCapture) const
For a closure type, retrieve the mapping from captured variables and this to the non-static data memb...
Definition: DeclCXX.cpp:1557
clang::OverloadCandidateParamOrder::Normal
@ Normal
clang::ento::ExplodedNode::getStmtForDiagnostics
const Stmt * getStmtForDiagnostics() const
If the node's program point corresponds to a statement, retrieve that statement.
Definition: ExplodedGraph.cpp:321
clang::ento::forLoopMatcher
static internal::Matcher< Stmt > forLoopMatcher()
Definition: LoopUnrolling.cpp:142
clang::DeclRefExpr::refersToEnclosingVariableOrCapture
bool refersToEnclosingVariableOrCapture() const
Does this DeclRefExpr refer to an enclosing local or a captured variable?
Definition: Expr.h:1419
clang::ValueDecl::getType
QualType getType() const
Definition: Decl.h:687
clang::ento::hasSuspiciousStmt
static internal::Matcher< Stmt > hasSuspiciousStmt(StringRef NodeName)
Definition: LoopUnrolling.cpp:130
clang::ast_matchers::integerLiteral
const internal::VariadicDynCastAllOfMatcher< Stmt, IntegerLiteral > integerLiteral
Matches integer literals of all sizes / encodings, e.g.
Definition: ASTMatchersInternal.cpp:922
clang::ento::getAddrTo
static internal::Matcher< Stmt > getAddrTo(internal::Matcher< Decl > VarNodeMatcher)
Definition: LoopUnrolling.cpp:124
clang::ast_matchers::varDecl
const internal::VariadicDynCastAllOfMatcher< Decl, VarDecl > varDecl
Matches variable declarations.
Definition: ASTMatchersInternal.cpp:801
clang::ast_matchers::has
const internal::ArgumentAdaptingMatcherFunc< internal::HasMatcher > has
Matches AST nodes that have child AST nodes that match the provided matcher.
Definition: ASTMatchersInternal.cpp:1007
clang::ast_matchers::hasDeclaration
internal::PolymorphicMatcher< internal::HasDeclarationMatcher, void(internal::HasDeclarationSupportedTypes), internal::Matcher< Decl > > hasDeclaration(const internal::Matcher< Decl > &InnerMatcher)
Matches a node if the declaration associated with that node matches the given matcher.
Definition: ASTMatchers.h:3563
LoopState::getLocationContext
const LocationContext * getLocationContext() const
Definition: LoopUnrolling.cpp:48
clang::ast_matchers::declStmt
const internal::VariadicDynCastAllOfMatcher< Stmt, DeclStmt > declStmt
Matches declaration statements.
Definition: ASTMatchersInternal.cpp:810
clang::DeclRefExpr
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1217
clang::LocationContext::getDecl
const Decl * getDecl() const
Definition: AnalysisDeclContext.h:247
clang::ProgramPoint
Definition: ProgramPoint.h:59
MAXIMUM_STEP_UNROLLED
static const int MAXIMUM_STEP_UNROLLED
Definition: LoopUnrolling.cpp:25
clang::ast_matchers::parmVarDecl
const internal::VariadicDynCastAllOfMatcher< Decl, ParmVarDecl > parmVarDecl
Matches parameter variable declarations.
Definition: ASTMatchersInternal.cpp:756
llvm::IntrusiveRefCntPtr
Definition: LLVM.h:47
abs
__DEVICE__ long long abs(long long __n)
Definition: __clang_cuda_cmath.h:41
clang::ast_matchers::qualType
const internal::VariadicAllOfMatcher< QualType > qualType
Matches QualTypes in the clang AST.
Definition: ASTMatchersInternal.cpp:771