blob: f514ed21f474a9f5af75b963d82cb205cabeb384 [file] [log] [blame]
Chris Lattnerf42cce72006-10-25 04:09:21 +00001//===--- Stmt.cpp - Statement AST Node Implementation ---------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner5b12ab82007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnerf42cce72006-10-25 04:09:21 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the Stmt class and statement subclasses.
11//
12//===----------------------------------------------------------------------===//
13
Benjamin Kramer444a1302012-12-01 17:12:56 +000014#include "clang/AST/ASTContext.h"
15#include "clang/AST/ASTDiagnostic.h"
Chris Lattner29375652006-12-04 18:06:35 +000016#include "clang/AST/ExprCXX.h"
Steve Naroff021ca182008-05-29 21:12:08 +000017#include "clang/AST/ExprObjC.h"
Alexey Bataev1a3320e2015-08-25 14:24:04 +000018#include "clang/AST/ExprOpenMP.h"
Benjamin Kramer444a1302012-12-01 17:12:56 +000019#include "clang/AST/Stmt.h"
Chris Lattnerf0b64d72009-04-26 01:32:48 +000020#include "clang/AST/StmtCXX.h"
21#include "clang/AST/StmtObjC.h"
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000022#include "clang/AST/StmtOpenMP.h"
Sebastian Redl54c04d42008-12-22 19:15:10 +000023#include "clang/AST/Type.h"
Jordan Rosea7d03842013-02-08 22:30:41 +000024#include "clang/Basic/CharInfo.h"
Chris Lattner1a8f3942010-04-23 16:29:58 +000025#include "clang/Basic/TargetInfo.h"
Benjamin Kramer444a1302012-12-01 17:12:56 +000026#include "clang/Lex/Token.h"
Chad Rosier14836ba2012-08-24 17:05:45 +000027#include "llvm/ADT/StringExtras.h"
Chandler Carruthbfb154a2011-07-04 06:13:27 +000028#include "llvm/Support/raw_ostream.h"
Chris Lattnerf42cce72006-10-25 04:09:21 +000029using namespace clang;
30
Steve Narofff84d11f2007-05-23 21:48:04 +000031static struct StmtClassNameTable {
Chris Lattner4d15a0d2007-08-25 01:42:24 +000032 const char *Name;
33 unsigned Counter;
34 unsigned Size;
Alexis Hunt656bb312010-05-05 15:24:00 +000035} StmtClassInfo[Stmt::lastStmtConstant+1];
Chris Lattner4d15a0d2007-08-25 01:42:24 +000036
37static StmtClassNameTable &getStmtInfoTableEntry(Stmt::StmtClass E) {
38 static bool Initialized = false;
39 if (Initialized)
40 return StmtClassInfo[E];
41
42 // Intialize the table on the first use.
43 Initialized = true;
Alexis Huntabb2ac82010-05-18 06:22:21 +000044#define ABSTRACT_STMT(STMT)
Douglas Gregorbe35ce92008-11-14 12:46:07 +000045#define STMT(CLASS, PARENT) \
46 StmtClassInfo[(unsigned)Stmt::CLASS##Class].Name = #CLASS; \
47 StmtClassInfo[(unsigned)Stmt::CLASS##Class].Size = sizeof(CLASS);
Alexis Hunt656bb312010-05-05 15:24:00 +000048#include "clang/AST/StmtNodes.inc"
Nico Weberde565e32008-08-05 23:15:29 +000049
Chris Lattner4d15a0d2007-08-25 01:42:24 +000050 return StmtClassInfo[E];
51}
52
Craig Topper37932912013-08-18 10:09:15 +000053void *Stmt::operator new(size_t bytes, const ASTContext& C,
Craig Topper5a050012013-08-18 17:45:38 +000054 unsigned alignment) {
Benjamin Kramerea70eb32012-12-01 15:09:41 +000055 return ::operator new(bytes, C, alignment);
56}
57
Steve Narofff1e53692007-03-23 22:27:02 +000058const char *Stmt::getStmtClassName() const {
John McCall925b16622010-10-26 08:39:16 +000059 return getStmtInfoTableEntry((StmtClass) StmtBits.sClass).Name;
Steve Narofff1e53692007-03-23 22:27:02 +000060}
Steve Narofff84d11f2007-05-23 21:48:04 +000061
62void Stmt::PrintStats() {
Chris Lattner4d15a0d2007-08-25 01:42:24 +000063 // Ensure the table is primed.
64 getStmtInfoTableEntry(Stmt::NullStmtClass);
Nico Weberde565e32008-08-05 23:15:29 +000065
Steve Narofff84d11f2007-05-23 21:48:04 +000066 unsigned sum = 0;
Chandler Carruthbfb154a2011-07-04 06:13:27 +000067 llvm::errs() << "\n*** Stmt/Expr Stats:\n";
Alexis Hunt656bb312010-05-05 15:24:00 +000068 for (int i = 0; i != Stmt::lastStmtConstant+1; i++) {
Craig Topper36250ad2014-05-12 05:36:57 +000069 if (StmtClassInfo[i].Name == nullptr) continue;
Chris Lattner4d15a0d2007-08-25 01:42:24 +000070 sum += StmtClassInfo[i].Counter;
Steve Narofff84d11f2007-05-23 21:48:04 +000071 }
Chandler Carruthbfb154a2011-07-04 06:13:27 +000072 llvm::errs() << " " << sum << " stmts/exprs total.\n";
Steve Narofff84d11f2007-05-23 21:48:04 +000073 sum = 0;
Alexis Hunt656bb312010-05-05 15:24:00 +000074 for (int i = 0; i != Stmt::lastStmtConstant+1; i++) {
Craig Topper36250ad2014-05-12 05:36:57 +000075 if (StmtClassInfo[i].Name == nullptr) continue;
Douglas Gregora30d0462009-05-26 14:40:08 +000076 if (StmtClassInfo[i].Counter == 0) continue;
Chandler Carruthbfb154a2011-07-04 06:13:27 +000077 llvm::errs() << " " << StmtClassInfo[i].Counter << " "
78 << StmtClassInfo[i].Name << ", " << StmtClassInfo[i].Size
79 << " each (" << StmtClassInfo[i].Counter*StmtClassInfo[i].Size
80 << " bytes)\n";
Chris Lattner4d15a0d2007-08-25 01:42:24 +000081 sum += StmtClassInfo[i].Counter*StmtClassInfo[i].Size;
Steve Narofff84d11f2007-05-23 21:48:04 +000082 }
Chandler Carruthbfb154a2011-07-04 06:13:27 +000083
84 llvm::errs() << "Total bytes = " << sum << "\n";
Steve Narofff84d11f2007-05-23 21:48:04 +000085}
86
87void Stmt::addStmtClass(StmtClass s) {
Chris Lattner4d15a0d2007-08-25 01:42:24 +000088 ++getStmtInfoTableEntry(s).Counter;
Steve Narofff84d11f2007-05-23 21:48:04 +000089}
90
Daniel Dunbar62905572012-03-05 21:42:49 +000091bool Stmt::StatisticsEnabled = false;
92void Stmt::EnableStatistics() {
93 StatisticsEnabled = true;
Steve Narofff84d11f2007-05-23 21:48:04 +000094}
95
John McCall4db5c3c2011-07-07 06:58:02 +000096Stmt *Stmt::IgnoreImplicit() {
97 Stmt *s = this;
98
Richard Smith520449d2015-02-05 06:15:50 +000099 if (auto *ewc = dyn_cast<ExprWithCleanups>(s))
John McCall4db5c3c2011-07-07 06:58:02 +0000100 s = ewc->getSubExpr();
101
Richard Smith520449d2015-02-05 06:15:50 +0000102 if (auto *mte = dyn_cast<MaterializeTemporaryExpr>(s))
103 s = mte->GetTemporaryExpr();
104
105 if (auto *bte = dyn_cast<CXXBindTemporaryExpr>(s))
106 s = bte->getSubExpr();
107
108 while (auto *ice = dyn_cast<ImplicitCastExpr>(s))
John McCall4db5c3c2011-07-07 06:58:02 +0000109 s = ice->getSubExpr();
110
111 return s;
112}
113
Alexander Musmana5f070a2014-10-01 06:03:56 +0000114/// \brief Skip no-op (attributed, compound) container stmts and skip captured
115/// stmt at the top, if \a IgnoreCaptured is true.
116Stmt *Stmt::IgnoreContainers(bool IgnoreCaptured) {
117 Stmt *S = this;
118 if (IgnoreCaptured)
119 if (auto CapS = dyn_cast_or_null<CapturedStmt>(S))
120 S = CapS->getCapturedStmt();
121 while (true) {
122 if (auto AS = dyn_cast_or_null<AttributedStmt>(S))
123 S = AS->getSubStmt();
124 else if (auto CS = dyn_cast_or_null<CompoundStmt>(S)) {
125 if (CS->size() != 1)
126 break;
127 S = CS->body_back();
128 } else
129 break;
130 }
131 return S;
132}
133
Chandler Carrutha626d642011-09-10 00:02:34 +0000134/// \brief Strip off all label-like statements.
135///
Richard Smithc202b282012-04-14 00:33:13 +0000136/// This will strip off label statements, case statements, attributed
137/// statements and default statements recursively.
Chandler Carrutha626d642011-09-10 00:02:34 +0000138const Stmt *Stmt::stripLabelLikeStatements() const {
139 const Stmt *S = this;
140 while (true) {
141 if (const LabelStmt *LS = dyn_cast<LabelStmt>(S))
142 S = LS->getSubStmt();
143 else if (const SwitchCase *SC = dyn_cast<SwitchCase>(S))
144 S = SC->getSubStmt();
Richard Smithc202b282012-04-14 00:33:13 +0000145 else if (const AttributedStmt *AS = dyn_cast<AttributedStmt>(S))
146 S = AS->getSubStmt();
Chandler Carrutha626d642011-09-10 00:02:34 +0000147 else
148 return S;
149 }
150}
151
John McCallbd066782011-02-09 08:16:59 +0000152namespace {
153 struct good {};
154 struct bad {};
John McCallf75152f2011-02-09 08:31:17 +0000155
156 // These silly little functions have to be static inline to suppress
157 // unused warnings, and they have to be defined to suppress other
158 // warnings.
Nick Lewyckybae992f2011-02-09 08:42:57 +0000159 static inline good is_good(good) { return good(); }
John McCallbd066782011-02-09 08:16:59 +0000160
161 typedef Stmt::child_range children_t();
Nick Lewyckybae992f2011-02-09 08:42:57 +0000162 template <class T> good implements_children(children_t T::*) {
163 return good();
164 }
Eli Friedmandc41d792013-09-10 22:57:15 +0000165 LLVM_ATTRIBUTE_UNUSED
Nick Lewyckybae992f2011-02-09 08:42:57 +0000166 static inline bad implements_children(children_t Stmt::*) {
167 return bad();
168 }
John McCallbd066782011-02-09 08:16:59 +0000169
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000170 typedef SourceLocation getLocStart_t() const;
171 template <class T> good implements_getLocStart(getLocStart_t T::*) {
Nick Lewyckybae992f2011-02-09 08:42:57 +0000172 return good();
173 }
Eli Friedmandc41d792013-09-10 22:57:15 +0000174 LLVM_ATTRIBUTE_UNUSED
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000175 static inline bad implements_getLocStart(getLocStart_t Stmt::*) {
176 return bad();
177 }
178
179 typedef SourceLocation getLocEnd_t() const;
180 template <class T> good implements_getLocEnd(getLocEnd_t T::*) {
181 return good();
182 }
Eli Friedmandc41d792013-09-10 22:57:15 +0000183 LLVM_ATTRIBUTE_UNUSED
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000184 static inline bad implements_getLocEnd(getLocEnd_t Stmt::*) {
Nick Lewyckybae992f2011-02-09 08:42:57 +0000185 return bad();
186 }
John McCallbd066782011-02-09 08:16:59 +0000187
188#define ASSERT_IMPLEMENTS_children(type) \
Eli Friedmandc41d792013-09-10 22:57:15 +0000189 (void) is_good(implements_children(&type::children))
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000190#define ASSERT_IMPLEMENTS_getLocStart(type) \
Eli Friedmandc41d792013-09-10 22:57:15 +0000191 (void) is_good(implements_getLocStart(&type::getLocStart))
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000192#define ASSERT_IMPLEMENTS_getLocEnd(type) \
Eli Friedmandc41d792013-09-10 22:57:15 +0000193 (void) is_good(implements_getLocEnd(&type::getLocEnd))
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000194}
John McCallbd066782011-02-09 08:16:59 +0000195
196/// Check whether the various Stmt classes implement their member
197/// functions.
Eli Friedmandc41d792013-09-10 22:57:15 +0000198LLVM_ATTRIBUTE_UNUSED
John McCallbd066782011-02-09 08:16:59 +0000199static inline void check_implementations() {
200#define ABSTRACT_STMT(type)
201#define STMT(type, base) \
202 ASSERT_IMPLEMENTS_children(type); \
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000203 ASSERT_IMPLEMENTS_getLocStart(type); \
204 ASSERT_IMPLEMENTS_getLocEnd(type);
John McCallbd066782011-02-09 08:16:59 +0000205#include "clang/AST/StmtNodes.inc"
206}
207
208Stmt::child_range Stmt::children() {
209 switch (getStmtClass()) {
210 case Stmt::NoStmtClass: llvm_unreachable("statement without class");
211#define ABSTRACT_STMT(type)
212#define STMT(type, base) \
213 case Stmt::type##Class: \
214 return static_cast<type*>(this)->children();
215#include "clang/AST/StmtNodes.inc"
216 }
217 llvm_unreachable("unknown statement kind!");
John McCallbd066782011-02-09 08:16:59 +0000218}
219
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000220// Amusing macro metaprogramming hack: check whether a class provides
221// a more specific implementation of getSourceRange.
222//
223// See also Expr.cpp:getExprLoc().
224namespace {
225 /// This implementation is used when a class provides a custom
226 /// implementation of getSourceRange.
227 template <class S, class T>
228 SourceRange getSourceRangeImpl(const Stmt *stmt,
229 SourceRange (T::*v)() const) {
230 return static_cast<const S*>(stmt)->getSourceRange();
231 }
232
233 /// This implementation is used when a class doesn't provide a custom
234 /// implementation of getSourceRange. Overload resolution should pick it over
235 /// the implementation above because it's more specialized according to
236 /// function template partial ordering.
237 template <class S>
238 SourceRange getSourceRangeImpl(const Stmt *stmt,
239 SourceRange (Stmt::*v)() const) {
240 return SourceRange(static_cast<const S*>(stmt)->getLocStart(),
241 static_cast<const S*>(stmt)->getLocEnd());
242 }
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000243}
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000244
John McCallbd066782011-02-09 08:16:59 +0000245SourceRange Stmt::getSourceRange() const {
246 switch (getStmtClass()) {
247 case Stmt::NoStmtClass: llvm_unreachable("statement without class");
248#define ABSTRACT_STMT(type)
249#define STMT(type, base) \
250 case Stmt::type##Class: \
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000251 return getSourceRangeImpl<type>(this, &type::getSourceRange);
John McCallbd066782011-02-09 08:16:59 +0000252#include "clang/AST/StmtNodes.inc"
253 }
254 llvm_unreachable("unknown statement kind!");
John McCallbd066782011-02-09 08:16:59 +0000255}
256
Daniel Dunbarb0ab5e92012-03-09 15:39:19 +0000257SourceLocation Stmt::getLocStart() const {
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000258// llvm::errs() << "getLocStart() for " << getStmtClassName() << "\n";
Daniel Dunbarb0ab5e92012-03-09 15:39:19 +0000259 switch (getStmtClass()) {
260 case Stmt::NoStmtClass: llvm_unreachable("statement without class");
261#define ABSTRACT_STMT(type)
262#define STMT(type, base) \
263 case Stmt::type##Class: \
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000264 return static_cast<const type*>(this)->getLocStart();
Daniel Dunbarb0ab5e92012-03-09 15:39:19 +0000265#include "clang/AST/StmtNodes.inc"
266 }
267 llvm_unreachable("unknown statement kind");
268}
269
270SourceLocation Stmt::getLocEnd() const {
271 switch (getStmtClass()) {
272 case Stmt::NoStmtClass: llvm_unreachable("statement without class");
273#define ABSTRACT_STMT(type)
274#define STMT(type, base) \
275 case Stmt::type##Class: \
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000276 return static_cast<const type*>(this)->getLocEnd();
Daniel Dunbarb0ab5e92012-03-09 15:39:19 +0000277#include "clang/AST/StmtNodes.inc"
278 }
279 llvm_unreachable("unknown statement kind");
280}
281
Craig Toppere6960e22013-08-22 05:28:54 +0000282CompoundStmt::CompoundStmt(const ASTContext &C, ArrayRef<Stmt*> Stmts,
Benjamin Kramere2a929d2012-07-04 17:03:41 +0000283 SourceLocation LB, SourceLocation RB)
Aaron Ballmance6c67e2014-10-22 21:06:18 +0000284 : Stmt(CompoundStmtClass), LBraceLoc(LB), RBraceLoc(RB) {
Nico Webera2a0eb92012-12-29 20:03:39 +0000285 CompoundStmtBits.NumStmts = Stmts.size();
286 assert(CompoundStmtBits.NumStmts == Stmts.size() &&
Benjamin Kramere2a929d2012-07-04 17:03:41 +0000287 "NumStmts doesn't fit in bits of CompoundStmtBits.NumStmts!");
288
Nico Webera2a0eb92012-12-29 20:03:39 +0000289 if (Stmts.size() == 0) {
Craig Topper36250ad2014-05-12 05:36:57 +0000290 Body = nullptr;
Benjamin Kramere2a929d2012-07-04 17:03:41 +0000291 return;
292 }
293
Nico Webera2a0eb92012-12-29 20:03:39 +0000294 Body = new (C) Stmt*[Stmts.size()];
295 std::copy(Stmts.begin(), Stmts.end(), Body);
Benjamin Kramere2a929d2012-07-04 17:03:41 +0000296}
297
Craig Topper9ee84ad2015-12-04 05:01:44 +0000298void CompoundStmt::setStmts(const ASTContext &C, ArrayRef<Stmt *> Stmts) {
299 if (Body)
Douglas Gregora9af1d12009-04-17 00:04:06 +0000300 C.Deallocate(Body);
Craig Topper9ee84ad2015-12-04 05:01:44 +0000301 CompoundStmtBits.NumStmts = Stmts.size();
302 assert(CompoundStmtBits.NumStmts == Stmts.size() &&
303 "NumStmts doesn't fit in bits of CompoundStmtBits.NumStmts!");
Douglas Gregora9af1d12009-04-17 00:04:06 +0000304
Craig Topper9ee84ad2015-12-04 05:01:44 +0000305 Body = new (C) Stmt*[Stmts.size()];
306 std::copy(Stmts.begin(), Stmts.end(), Body);
Douglas Gregora9af1d12009-04-17 00:04:06 +0000307}
Steve Narofff84d11f2007-05-23 21:48:04 +0000308
Chris Lattnereefa10e2007-05-28 06:56:27 +0000309const char *LabelStmt::getName() const {
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000310 return getDecl()->getIdentifier()->getNameStart();
Chris Lattnereefa10e2007-05-28 06:56:27 +0000311}
312
Craig Toppere6960e22013-08-22 05:28:54 +0000313AttributedStmt *AttributedStmt::Create(const ASTContext &C, SourceLocation Loc,
Alexander Kornienko20f6fc62012-07-09 10:04:07 +0000314 ArrayRef<const Attr*> Attrs,
315 Stmt *SubStmt) {
Aaron Ballmanf3d9b092014-05-13 14:55:01 +0000316 assert(!Attrs.empty() && "Attrs should not be empty");
317 void *Mem = C.Allocate(sizeof(AttributedStmt) + sizeof(Attr *) * Attrs.size(),
Alexander Kornienko20f6fc62012-07-09 10:04:07 +0000318 llvm::alignOf<AttributedStmt>());
319 return new (Mem) AttributedStmt(Loc, Attrs, SubStmt);
320}
321
Craig Toppere6960e22013-08-22 05:28:54 +0000322AttributedStmt *AttributedStmt::CreateEmpty(const ASTContext &C,
323 unsigned NumAttrs) {
Alexander Kornienko20f6fc62012-07-09 10:04:07 +0000324 assert(NumAttrs > 0 && "NumAttrs should be greater than zero");
Aaron Ballmanf3d9b092014-05-13 14:55:01 +0000325 void *Mem = C.Allocate(sizeof(AttributedStmt) + sizeof(Attr *) * NumAttrs,
Alexander Kornienko20f6fc62012-07-09 10:04:07 +0000326 llvm::alignOf<AttributedStmt>());
327 return new (Mem) AttributedStmt(EmptyShell(), NumAttrs);
328}
329
Craig Topperc571c812013-08-22 06:02:26 +0000330std::string AsmStmt::generateAsmString(const ASTContext &C) const {
Chad Rosierf70b7e22012-08-28 18:21:14 +0000331 if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
332 return gccAsmStmt->generateAsmString(C);
333 if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this))
334 return msAsmStmt->generateAsmString(C);
Chad Rosierbbbe9ab2012-08-28 17:43:23 +0000335 llvm_unreachable("unknown asm statement kind!");
336}
337
338StringRef AsmStmt::getOutputConstraint(unsigned i) const {
Chad Rosierf70b7e22012-08-28 18:21:14 +0000339 if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
340 return gccAsmStmt->getOutputConstraint(i);
341 if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this))
342 return msAsmStmt->getOutputConstraint(i);
Chad Rosierbbbe9ab2012-08-28 17:43:23 +0000343 llvm_unreachable("unknown asm statement kind!");
344}
345
346const Expr *AsmStmt::getOutputExpr(unsigned i) const {
Chad Rosierf70b7e22012-08-28 18:21:14 +0000347 if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
348 return gccAsmStmt->getOutputExpr(i);
349 if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this))
350 return msAsmStmt->getOutputExpr(i);
Chad Rosierbbbe9ab2012-08-28 17:43:23 +0000351 llvm_unreachable("unknown asm statement kind!");
352}
353
354StringRef AsmStmt::getInputConstraint(unsigned i) const {
Chad Rosierf70b7e22012-08-28 18:21:14 +0000355 if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
356 return gccAsmStmt->getInputConstraint(i);
357 if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this))
358 return msAsmStmt->getInputConstraint(i);
Chad Rosierbbbe9ab2012-08-28 17:43:23 +0000359 llvm_unreachable("unknown asm statement kind!");
360}
361
362const Expr *AsmStmt::getInputExpr(unsigned i) const {
Chad Rosierf70b7e22012-08-28 18:21:14 +0000363 if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
364 return gccAsmStmt->getInputExpr(i);
365 if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this))
366 return msAsmStmt->getInputExpr(i);
Chad Rosierbbbe9ab2012-08-28 17:43:23 +0000367 llvm_unreachable("unknown asm statement kind!");
368}
369
370StringRef AsmStmt::getClobber(unsigned i) const {
Chad Rosierf70b7e22012-08-28 18:21:14 +0000371 if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
372 return gccAsmStmt->getClobber(i);
373 if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this))
374 return msAsmStmt->getClobber(i);
Chad Rosierbbbe9ab2012-08-28 17:43:23 +0000375 llvm_unreachable("unknown asm statement kind!");
376}
377
Chad Rosiera1b5c8c2012-08-28 00:24:05 +0000378/// getNumPlusOperands - Return the number of output operands that have a "+"
379/// constraint.
380unsigned AsmStmt::getNumPlusOperands() const {
381 unsigned Res = 0;
382 for (unsigned i = 0, e = getNumOutputs(); i != e; ++i)
383 if (isOutputPlusConstraint(i))
384 ++Res;
385 return Res;
386}
387
Akira Hatanaka987f1862014-08-22 06:05:21 +0000388char GCCAsmStmt::AsmStringPiece::getModifier() const {
389 assert(isOperand() && "Only Operands can have modifiers.");
390 return isLetter(Str[0]) ? Str[0] : '\0';
391}
392
Chad Rosier6100ae12012-08-27 23:47:56 +0000393StringRef GCCAsmStmt::getClobber(unsigned i) const {
394 return getClobberStringLiteral(i)->getString();
395}
396
Chad Rosierde70e0e2012-08-25 00:11:56 +0000397Expr *GCCAsmStmt::getOutputExpr(unsigned i) {
Ted Kremenek5778acf2008-10-27 18:40:21 +0000398 return cast<Expr>(Exprs[i]);
399}
Chris Lattner72bbf172009-03-10 04:59:06 +0000400
401/// getOutputConstraint - Return the constraint string for the specified
402/// output operand. All output constraints are known to be non-empty (either
403/// '=' or '+').
Chad Rosierde70e0e2012-08-25 00:11:56 +0000404StringRef GCCAsmStmt::getOutputConstraint(unsigned i) const {
Anders Carlsson66de0812010-01-30 20:38:10 +0000405 return getOutputConstraintLiteral(i)->getString();
Ted Kremenek5778acf2008-10-27 18:40:21 +0000406}
Chris Lattner72bbf172009-03-10 04:59:06 +0000407
Chad Rosierde70e0e2012-08-25 00:11:56 +0000408Expr *GCCAsmStmt::getInputExpr(unsigned i) {
Ted Kremenek5778acf2008-10-27 18:40:21 +0000409 return cast<Expr>(Exprs[i + NumOutputs]);
410}
Chad Rosierde70e0e2012-08-25 00:11:56 +0000411void GCCAsmStmt::setInputExpr(unsigned i, Expr *E) {
Chris Lattner93ede022011-02-21 22:09:29 +0000412 Exprs[i + NumOutputs] = E;
413}
414
Chris Lattner72bbf172009-03-10 04:59:06 +0000415/// getInputConstraint - Return the specified input constraint. Unlike output
416/// constraints, these can be empty.
Chad Rosierde70e0e2012-08-25 00:11:56 +0000417StringRef GCCAsmStmt::getInputConstraint(unsigned i) const {
Anders Carlsson66de0812010-01-30 20:38:10 +0000418 return getInputConstraintLiteral(i)->getString();
Ted Kremenek5778acf2008-10-27 18:40:21 +0000419}
420
Craig Topperc571c812013-08-22 06:02:26 +0000421void GCCAsmStmt::setOutputsAndInputsAndClobbers(const ASTContext &C,
422 IdentifierInfo **Names,
423 StringLiteral **Constraints,
424 Stmt **Exprs,
425 unsigned NumOutputs,
426 unsigned NumInputs,
427 StringLiteral **Clobbers,
428 unsigned NumClobbers) {
Douglas Gregorf994f062009-04-17 20:57:14 +0000429 this->NumOutputs = NumOutputs;
430 this->NumInputs = NumInputs;
Anders Carlsson98323d22010-01-30 23:19:41 +0000431 this->NumClobbers = NumClobbers;
432
433 unsigned NumExprs = NumOutputs + NumInputs;
Chad Rosier42032fa2012-08-07 23:12:23 +0000434
Anders Carlsson98323d22010-01-30 23:19:41 +0000435 C.Deallocate(this->Names);
436 this->Names = new (C) IdentifierInfo*[NumExprs];
437 std::copy(Names, Names + NumExprs, this->Names);
Chad Rosier42032fa2012-08-07 23:12:23 +0000438
Anders Carlsson98323d22010-01-30 23:19:41 +0000439 C.Deallocate(this->Exprs);
440 this->Exprs = new (C) Stmt*[NumExprs];
441 std::copy(Exprs, Exprs + NumExprs, this->Exprs);
Chad Rosier42032fa2012-08-07 23:12:23 +0000442
Anders Carlsson98323d22010-01-30 23:19:41 +0000443 C.Deallocate(this->Constraints);
444 this->Constraints = new (C) StringLiteral*[NumExprs];
445 std::copy(Constraints, Constraints + NumExprs, this->Constraints);
Chad Rosier42032fa2012-08-07 23:12:23 +0000446
Anders Carlsson98323d22010-01-30 23:19:41 +0000447 C.Deallocate(this->Clobbers);
448 this->Clobbers = new (C) StringLiteral*[NumClobbers];
449 std::copy(Clobbers, Clobbers + NumClobbers, this->Clobbers);
Douglas Gregorf994f062009-04-17 20:57:14 +0000450}
451
Chris Lattnerd7d5fdf2009-03-10 06:33:24 +0000452/// getNamedOperand - Given a symbolic operand reference like %[foo],
453/// translate this into a numeric value needed to reference the same operand.
454/// This returns -1 if the operand name is invalid.
Chad Rosierde70e0e2012-08-25 00:11:56 +0000455int GCCAsmStmt::getNamedOperand(StringRef SymbolicName) const {
Chris Lattnerd7d5fdf2009-03-10 06:33:24 +0000456 unsigned NumPlusOperands = 0;
Mike Stump11289f42009-09-09 15:08:12 +0000457
Chris Lattnerd7d5fdf2009-03-10 06:33:24 +0000458 // Check if this is an output operand.
459 for (unsigned i = 0, e = getNumOutputs(); i != e; ++i) {
460 if (getOutputName(i) == SymbolicName)
461 return i;
Chris Lattnerd7d5fdf2009-03-10 06:33:24 +0000462 }
Mike Stump11289f42009-09-09 15:08:12 +0000463
Chris Lattnerd7d5fdf2009-03-10 06:33:24 +0000464 for (unsigned i = 0, e = getNumInputs(); i != e; ++i)
465 if (getInputName(i) == SymbolicName)
466 return getNumOutputs() + NumPlusOperands + i;
467
468 // Not found.
469 return -1;
470}
471
Chris Lattner35b58362009-03-10 23:21:44 +0000472/// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing
473/// it into pieces. If the asm string is erroneous, emit errors and return
474/// true, otherwise return false.
Chad Rosierde70e0e2012-08-25 00:11:56 +0000475unsigned GCCAsmStmt::AnalyzeAsmString(SmallVectorImpl<AsmStringPiece>&Pieces,
Craig Topperc571c812013-08-22 06:02:26 +0000476 const ASTContext &C, unsigned &DiagOffs) const {
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000477 StringRef Str = getAsmString()->getString();
Benjamin Kramer35b077e2010-08-17 12:54:38 +0000478 const char *StrStart = Str.begin();
479 const char *StrEnd = Str.end();
Chris Lattnera41b8472009-03-10 23:51:40 +0000480 const char *CurPtr = StrStart;
Mike Stump11289f42009-09-09 15:08:12 +0000481
Chris Lattner35b58362009-03-10 23:21:44 +0000482 // "Simple" inline asms have no constraints or operands, just convert the asm
483 // string to escape $'s.
484 if (isSimple()) {
485 std::string Result;
Chris Lattnera41b8472009-03-10 23:51:40 +0000486 for (; CurPtr != StrEnd; ++CurPtr) {
487 switch (*CurPtr) {
Chris Lattner35b58362009-03-10 23:21:44 +0000488 case '$':
489 Result += "$$";
490 break;
491 default:
Chris Lattnera41b8472009-03-10 23:51:40 +0000492 Result += *CurPtr;
Chris Lattner35b58362009-03-10 23:21:44 +0000493 break;
494 }
495 }
496 Pieces.push_back(AsmStringPiece(Result));
Chris Lattnera41b8472009-03-10 23:51:40 +0000497 return 0;
Chris Lattner35b58362009-03-10 23:21:44 +0000498 }
499
500 // CurStringPiece - The current string that we are building up as we scan the
501 // asm string.
502 std::string CurStringPiece;
Mike Stump11289f42009-09-09 15:08:12 +0000503
Douglas Gregore8bbc122011-09-02 00:18:52 +0000504 bool HasVariants = !C.getTargetInfo().hasNoAsmVariants();
Chad Rosier42032fa2012-08-07 23:12:23 +0000505
Richard Smithd18ab802016-05-16 22:52:23 +0000506 unsigned LastAsmStringToken = 0;
507 unsigned LastAsmStringOffset = 0;
508
Chris Lattner35b58362009-03-10 23:21:44 +0000509 while (1) {
510 // Done with the string?
Chris Lattnera41b8472009-03-10 23:51:40 +0000511 if (CurPtr == StrEnd) {
Chris Lattner35b58362009-03-10 23:21:44 +0000512 if (!CurStringPiece.empty())
513 Pieces.push_back(AsmStringPiece(CurStringPiece));
Chris Lattnera41b8472009-03-10 23:51:40 +0000514 return 0;
Chris Lattner35b58362009-03-10 23:21:44 +0000515 }
Mike Stump11289f42009-09-09 15:08:12 +0000516
Chris Lattnera41b8472009-03-10 23:51:40 +0000517 char CurChar = *CurPtr++;
Chris Lattnerda081a82010-04-05 18:44:00 +0000518 switch (CurChar) {
519 case '$': CurStringPiece += "$$"; continue;
Chris Lattner1a8f3942010-04-23 16:29:58 +0000520 case '{': CurStringPiece += (HasVariants ? "$(" : "{"); continue;
521 case '|': CurStringPiece += (HasVariants ? "$|" : "|"); continue;
522 case '}': CurStringPiece += (HasVariants ? "$)" : "}"); continue;
Chris Lattnerda081a82010-04-05 18:44:00 +0000523 case '%':
524 break;
525 default:
Chris Lattner35b58362009-03-10 23:21:44 +0000526 CurStringPiece += CurChar;
527 continue;
528 }
Chad Rosier42032fa2012-08-07 23:12:23 +0000529
Chris Lattner35b58362009-03-10 23:21:44 +0000530 // Escaped "%" character in asm string.
Chris Lattner3fa25c62009-03-11 00:06:36 +0000531 if (CurPtr == StrEnd) {
532 // % at end of string is invalid (no escape).
533 DiagOffs = CurPtr-StrStart-1;
534 return diag::err_asm_invalid_escape;
535 }
Mike Stump11289f42009-09-09 15:08:12 +0000536
Chris Lattnera41b8472009-03-10 23:51:40 +0000537 char EscapedChar = *CurPtr++;
Chris Lattner35b58362009-03-10 23:21:44 +0000538 if (EscapedChar == '%') { // %% -> %
539 // Escaped percentage sign.
540 CurStringPiece += '%';
541 continue;
542 }
Mike Stump11289f42009-09-09 15:08:12 +0000543
Chris Lattner35b58362009-03-10 23:21:44 +0000544 if (EscapedChar == '=') { // %= -> Generate an unique ID.
545 CurStringPiece += "${:uid}";
546 continue;
547 }
Mike Stump11289f42009-09-09 15:08:12 +0000548
Chris Lattner35b58362009-03-10 23:21:44 +0000549 // Otherwise, we have an operand. If we have accumulated a string so far,
550 // add it to the Pieces list.
551 if (!CurStringPiece.empty()) {
552 Pieces.push_back(AsmStringPiece(CurStringPiece));
553 CurStringPiece.clear();
554 }
Mike Stump11289f42009-09-09 15:08:12 +0000555
Akira Hatanaka987f1862014-08-22 06:05:21 +0000556 // Handle operands that have asmSymbolicName (e.g., %x[foo]) and those that
557 // don't (e.g., %x4). 'x' following the '%' is the constraint modifier.
558
559 const char *Begin = CurPtr - 1; // Points to the character following '%'.
560 const char *Percent = Begin - 1; // Points to '%'.
561
Jordan Rosea7d03842013-02-08 22:30:41 +0000562 if (isLetter(EscapedChar)) {
Benjamin Kramere87c38b2011-07-05 11:13:37 +0000563 if (CurPtr == StrEnd) { // Premature end.
564 DiagOffs = CurPtr-StrStart-1;
565 return diag::err_asm_invalid_escape;
566 }
Chris Lattnera41b8472009-03-10 23:51:40 +0000567 EscapedChar = *CurPtr++;
Chris Lattner35b58362009-03-10 23:21:44 +0000568 }
Mike Stump11289f42009-09-09 15:08:12 +0000569
Akira Hatanaka987f1862014-08-22 06:05:21 +0000570 const TargetInfo &TI = C.getTargetInfo();
571 const SourceManager &SM = C.getSourceManager();
572 const LangOptions &LO = C.getLangOpts();
573
574 // Handle operands that don't have asmSymbolicName (e.g., %x4).
Jordan Rosea7d03842013-02-08 22:30:41 +0000575 if (isDigit(EscapedChar)) {
Chris Lattner35b58362009-03-10 23:21:44 +0000576 // %n - Assembler operand n
Chris Lattner99d892b2009-03-11 22:52:17 +0000577 unsigned N = 0;
Mike Stump11289f42009-09-09 15:08:12 +0000578
Chris Lattner99d892b2009-03-11 22:52:17 +0000579 --CurPtr;
Jordan Rosea7d03842013-02-08 22:30:41 +0000580 while (CurPtr != StrEnd && isDigit(*CurPtr))
Chris Lattner84f3afa2009-03-11 23:09:16 +0000581 N = N*10 + ((*CurPtr++)-'0');
Mike Stump11289f42009-09-09 15:08:12 +0000582
Chris Lattner14311922009-03-11 00:23:13 +0000583 unsigned NumOperands =
584 getNumOutputs() + getNumPlusOperands() + getNumInputs();
585 if (N >= NumOperands) {
586 DiagOffs = CurPtr-StrStart-1;
587 return diag::err_asm_invalid_operand_number;
588 }
589
Akira Hatanaka987f1862014-08-22 06:05:21 +0000590 // Str contains "x4" (Operand without the leading %).
591 std::string Str(Begin, CurPtr - Begin);
592
593 // (BeginLoc, EndLoc) represents the range of the operand we are currently
594 // processing. Unlike Str, the range includes the leading '%'.
Richard Smithd18ab802016-05-16 22:52:23 +0000595 SourceLocation BeginLoc = getAsmString()->getLocationOfByte(
596 Percent - StrStart, SM, LO, TI, &LastAsmStringToken,
597 &LastAsmStringOffset);
598 SourceLocation EndLoc = getAsmString()->getLocationOfByte(
599 CurPtr - StrStart, SM, LO, TI, &LastAsmStringToken,
600 &LastAsmStringOffset);
Akira Hatanaka987f1862014-08-22 06:05:21 +0000601
Benjamin Kramer3204b152015-05-29 19:42:19 +0000602 Pieces.emplace_back(N, std::move(Str), BeginLoc, EndLoc);
Chris Lattner35b58362009-03-10 23:21:44 +0000603 continue;
604 }
Mike Stump11289f42009-09-09 15:08:12 +0000605
Akira Hatanaka987f1862014-08-22 06:05:21 +0000606 // Handle operands that have asmSymbolicName (e.g., %x[foo]).
Chris Lattner35b58362009-03-10 23:21:44 +0000607 if (EscapedChar == '[') {
Chris Lattner3fa25c62009-03-11 00:06:36 +0000608 DiagOffs = CurPtr-StrStart-1;
Mike Stump11289f42009-09-09 15:08:12 +0000609
Chris Lattner3fa25c62009-03-11 00:06:36 +0000610 // Find the ']'.
Chris Lattnera41b8472009-03-10 23:51:40 +0000611 const char *NameEnd = (const char*)memchr(CurPtr, ']', StrEnd-CurPtr);
Craig Topper36250ad2014-05-12 05:36:57 +0000612 if (NameEnd == nullptr)
Chris Lattner3fa25c62009-03-11 00:06:36 +0000613 return diag::err_asm_unterminated_symbolic_operand_name;
614 if (NameEnd == CurPtr)
615 return diag::err_asm_empty_symbolic_operand_name;
Mike Stump11289f42009-09-09 15:08:12 +0000616
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000617 StringRef SymbolicName(CurPtr, NameEnd - CurPtr);
Mike Stump11289f42009-09-09 15:08:12 +0000618
Chris Lattner35b58362009-03-10 23:21:44 +0000619 int N = getNamedOperand(SymbolicName);
Chris Lattner3fa25c62009-03-11 00:06:36 +0000620 if (N == -1) {
621 // Verify that an operand with that name exists.
622 DiagOffs = CurPtr-StrStart;
623 return diag::err_asm_unknown_symbolic_operand_name;
624 }
Akira Hatanaka987f1862014-08-22 06:05:21 +0000625
626 // Str contains "x[foo]" (Operand without the leading %).
627 std::string Str(Begin, NameEnd + 1 - Begin);
628
629 // (BeginLoc, EndLoc) represents the range of the operand we are currently
630 // processing. Unlike Str, the range includes the leading '%'.
Richard Smithd18ab802016-05-16 22:52:23 +0000631 SourceLocation BeginLoc = getAsmString()->getLocationOfByte(
632 Percent - StrStart, SM, LO, TI, &LastAsmStringToken,
633 &LastAsmStringOffset);
634 SourceLocation EndLoc = getAsmString()->getLocationOfByte(
635 NameEnd + 1 - StrStart, SM, LO, TI, &LastAsmStringToken,
636 &LastAsmStringOffset);
Akira Hatanaka987f1862014-08-22 06:05:21 +0000637
Benjamin Kramer3204b152015-05-29 19:42:19 +0000638 Pieces.emplace_back(N, std::move(Str), BeginLoc, EndLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000639
Chris Lattner3fa25c62009-03-11 00:06:36 +0000640 CurPtr = NameEnd+1;
Chris Lattner35b58362009-03-10 23:21:44 +0000641 continue;
642 }
Mike Stump11289f42009-09-09 15:08:12 +0000643
Chris Lattner0cdaa2e2009-03-10 23:57:07 +0000644 DiagOffs = CurPtr-StrStart-1;
Chris Lattnera41b8472009-03-10 23:51:40 +0000645 return diag::err_asm_invalid_escape;
Chris Lattner35b58362009-03-10 23:21:44 +0000646 }
647}
Chad Rosier3b0c2602012-08-27 20:23:31 +0000648
649/// Assemble final IR asm string (GCC-style).
Craig Topperc571c812013-08-22 06:02:26 +0000650std::string GCCAsmStmt::generateAsmString(const ASTContext &C) const {
Chad Rosier14836ba2012-08-24 17:05:45 +0000651 // Analyze the asm string to decompose it into its pieces. We know that Sema
652 // has already done this, so it is guaranteed to be successful.
Chad Rosierde70e0e2012-08-25 00:11:56 +0000653 SmallVector<GCCAsmStmt::AsmStringPiece, 4> Pieces;
Chad Rosier14836ba2012-08-24 17:05:45 +0000654 unsigned DiagOffs;
655 AnalyzeAsmString(Pieces, C, DiagOffs);
656
657 std::string AsmString;
658 for (unsigned i = 0, e = Pieces.size(); i != e; ++i) {
659 if (Pieces[i].isString())
660 AsmString += Pieces[i].getString();
661 else if (Pieces[i].getModifier() == '\0')
662 AsmString += '$' + llvm::utostr(Pieces[i].getOperandNo());
663 else
664 AsmString += "${" + llvm::utostr(Pieces[i].getOperandNo()) + ':' +
665 Pieces[i].getModifier() + '}';
666 }
667 return AsmString;
668}
Chris Lattner35b58362009-03-10 23:21:44 +0000669
Chad Rosier3b0c2602012-08-27 20:23:31 +0000670/// Assemble final IR asm string (MS-style).
Craig Topperc571c812013-08-22 06:02:26 +0000671std::string MSAsmStmt::generateAsmString(const ASTContext &C) const {
Chad Rosier3b0c2602012-08-27 20:23:31 +0000672 // FIXME: This needs to be translated into the IR string representation.
Chad Rosier0bca4692012-08-28 20:33:49 +0000673 return AsmStr;
Chad Rosier3b0c2602012-08-27 20:23:31 +0000674}
675
Chad Rosierfe31e622012-08-24 00:07:09 +0000676Expr *MSAsmStmt::getOutputExpr(unsigned i) {
677 return cast<Expr>(Exprs[i]);
678}
679
680Expr *MSAsmStmt::getInputExpr(unsigned i) {
681 return cast<Expr>(Exprs[i + NumOutputs]);
682}
683void MSAsmStmt::setInputExpr(unsigned i, Expr *E) {
684 Exprs[i + NumOutputs] = E;
685}
686
Chris Lattner86f5e132008-01-30 05:01:46 +0000687//===----------------------------------------------------------------------===//
688// Constructors
689//===----------------------------------------------------------------------===//
690
Craig Toppere6960e22013-08-22 05:28:54 +0000691GCCAsmStmt::GCCAsmStmt(const ASTContext &C, SourceLocation asmloc,
692 bool issimple, bool isvolatile, unsigned numoutputs,
693 unsigned numinputs, IdentifierInfo **names,
694 StringLiteral **constraints, Expr **exprs,
695 StringLiteral *asmstr, unsigned numclobbers,
696 StringLiteral **clobbers, SourceLocation rparenloc)
Chad Rosierfe3352e2012-08-27 19:38:01 +0000697 : AsmStmt(GCCAsmStmtClass, asmloc, issimple, isvolatile, numoutputs,
698 numinputs, numclobbers), RParenLoc(rparenloc), AsmStr(asmstr) {
Nico Weberde565e32008-08-05 23:15:29 +0000699
Chad Rosier42032fa2012-08-07 23:12:23 +0000700 unsigned NumExprs = NumOutputs + NumInputs;
701
Anders Carlsson98323d22010-01-30 23:19:41 +0000702 Names = new (C) IdentifierInfo*[NumExprs];
703 std::copy(names, names + NumExprs, Names);
704
705 Exprs = new (C) Stmt*[NumExprs];
706 std::copy(exprs, exprs + NumExprs, Exprs);
707
708 Constraints = new (C) StringLiteral*[NumExprs];
709 std::copy(constraints, constraints + NumExprs, Constraints);
710
711 Clobbers = new (C) StringLiteral*[NumClobbers];
712 std::copy(clobbers, clobbers + NumClobbers, Clobbers);
Anders Carlsson94ea8aa2007-11-22 01:36:19 +0000713}
714
Craig Toppere6960e22013-08-22 05:28:54 +0000715MSAsmStmt::MSAsmStmt(const ASTContext &C, SourceLocation asmloc,
Chad Rosier7dbef3e2012-08-16 00:06:53 +0000716 SourceLocation lbraceloc, bool issimple, bool isvolatile,
Chad Rosierf8037a12012-10-16 21:55:39 +0000717 ArrayRef<Token> asmtoks, unsigned numoutputs,
John McCallf413f5e2013-05-03 00:10:13 +0000718 unsigned numinputs,
Chad Rosierf8037a12012-10-16 21:55:39 +0000719 ArrayRef<StringRef> constraints, ArrayRef<Expr*> exprs,
720 StringRef asmstr, ArrayRef<StringRef> clobbers,
721 SourceLocation endloc)
722 : AsmStmt(MSAsmStmtClass, asmloc, issimple, isvolatile, numoutputs,
723 numinputs, clobbers.size()), LBraceLoc(lbraceloc),
John McCallf413f5e2013-05-03 00:10:13 +0000724 EndLoc(endloc), NumAsmToks(asmtoks.size()) {
Chad Rosier7dbef3e2012-08-16 00:06:53 +0000725
John McCallf413f5e2013-05-03 00:10:13 +0000726 initialize(C, asmstr, asmtoks, constraints, exprs, clobbers);
727}
Chad Rosier7dbef3e2012-08-16 00:06:53 +0000728
Craig Toppere6960e22013-08-22 05:28:54 +0000729static StringRef copyIntoContext(const ASTContext &C, StringRef str) {
Benjamin Kramer2ab0d882015-08-04 12:34:23 +0000730 return str.copy(C);
John McCallf413f5e2013-05-03 00:10:13 +0000731}
732
Craig Toppere6960e22013-08-22 05:28:54 +0000733void MSAsmStmt::initialize(const ASTContext &C, StringRef asmstr,
John McCallf413f5e2013-05-03 00:10:13 +0000734 ArrayRef<Token> asmtoks,
735 ArrayRef<StringRef> constraints,
736 ArrayRef<Expr*> exprs,
737 ArrayRef<StringRef> clobbers) {
738 assert(NumAsmToks == asmtoks.size());
739 assert(NumClobbers == clobbers.size());
740
Craig Toppercaf138e2015-12-05 07:41:42 +0000741 assert(exprs.size() == NumOutputs + NumInputs);
742 assert(exprs.size() == constraints.size());
John McCallf413f5e2013-05-03 00:10:13 +0000743
744 AsmStr = copyIntoContext(C, asmstr);
Chad Rosier99fc3812012-08-07 00:29:06 +0000745
Craig Toppercaf138e2015-12-05 07:41:42 +0000746 Exprs = new (C) Stmt*[exprs.size()];
747 std::copy(exprs.begin(), exprs.end(), Exprs);
Chad Rosierfe31e622012-08-24 00:07:09 +0000748
Craig Toppercaf138e2015-12-05 07:41:42 +0000749 AsmToks = new (C) Token[asmtoks.size()];
750 std::copy(asmtoks.begin(), asmtoks.end(), AsmToks);
Chad Rosier3ed0bd92012-08-08 19:48:07 +0000751
Craig Toppercaf138e2015-12-05 07:41:42 +0000752 Constraints = new (C) StringRef[exprs.size()];
753 std::transform(constraints.begin(), constraints.end(), Constraints,
754 [&](StringRef Constraint) {
755 return copyIntoContext(C, Constraint);
756 });
Chad Rosier3dd7bf22012-08-28 20:28:20 +0000757
Chad Rosierbaf53f92012-08-10 21:36:25 +0000758 Clobbers = new (C) StringRef[NumClobbers];
Craig Toppercaf138e2015-12-05 07:41:42 +0000759 // FIXME: Avoid the allocation/copy if at all possible.
760 std::transform(clobbers.begin(), clobbers.end(), Clobbers,
761 [&](StringRef Clobber) {
762 return copyIntoContext(C, Clobber);
763 });
Chad Rosier32503022012-06-11 20:47:18 +0000764}
765
Craig Toppere6960e22013-08-22 05:28:54 +0000766IfStmt::IfStmt(const ASTContext &C, SourceLocation IL, VarDecl *var, Expr *cond,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +0000767 Stmt *then, SourceLocation EL, Stmt *elsev)
768 : Stmt(IfStmtClass), IfLoc(IL), ElseLoc(EL)
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000769{
770 setConditionVariable(C, var);
Pavel Labath515f4db2013-09-03 14:41:16 +0000771 SubExprs[COND] = cond;
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000772 SubExprs[THEN] = then;
Chad Rosier42032fa2012-08-07 23:12:23 +0000773 SubExprs[ELSE] = elsev;
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000774}
775
776VarDecl *IfStmt::getConditionVariable() const {
777 if (!SubExprs[VAR])
Craig Topper36250ad2014-05-12 05:36:57 +0000778 return nullptr;
Chad Rosier42032fa2012-08-07 23:12:23 +0000779
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000780 DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]);
781 return cast<VarDecl>(DS->getSingleDecl());
782}
783
Craig Toppere6960e22013-08-22 05:28:54 +0000784void IfStmt::setConditionVariable(const ASTContext &C, VarDecl *V) {
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000785 if (!V) {
Craig Topper36250ad2014-05-12 05:36:57 +0000786 SubExprs[VAR] = nullptr;
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000787 return;
788 }
Chad Rosier42032fa2012-08-07 23:12:23 +0000789
Daniel Dunbar62ee6412012-03-09 18:35:03 +0000790 SourceRange VarRange = V->getSourceRange();
791 SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(),
792 VarRange.getEnd());
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000793}
794
Craig Toppere6960e22013-08-22 05:28:54 +0000795ForStmt::ForStmt(const ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar,
Chad Rosier42032fa2012-08-07 23:12:23 +0000796 Expr *Inc, Stmt *Body, SourceLocation FL, SourceLocation LP,
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000797 SourceLocation RP)
Chad Rosier42032fa2012-08-07 23:12:23 +0000798 : Stmt(ForStmtClass), ForLoc(FL), LParenLoc(LP), RParenLoc(RP)
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000799{
800 SubExprs[INIT] = Init;
801 setConditionVariable(C, condVar);
Pavel Labath515f4db2013-09-03 14:41:16 +0000802 SubExprs[COND] = Cond;
803 SubExprs[INC] = Inc;
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000804 SubExprs[BODY] = Body;
805}
806
807VarDecl *ForStmt::getConditionVariable() const {
808 if (!SubExprs[CONDVAR])
Craig Topper36250ad2014-05-12 05:36:57 +0000809 return nullptr;
Chad Rosier42032fa2012-08-07 23:12:23 +0000810
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000811 DeclStmt *DS = cast<DeclStmt>(SubExprs[CONDVAR]);
812 return cast<VarDecl>(DS->getSingleDecl());
813}
814
Craig Toppere6960e22013-08-22 05:28:54 +0000815void ForStmt::setConditionVariable(const ASTContext &C, VarDecl *V) {
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000816 if (!V) {
Craig Topper36250ad2014-05-12 05:36:57 +0000817 SubExprs[CONDVAR] = nullptr;
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000818 return;
819 }
Chad Rosier42032fa2012-08-07 23:12:23 +0000820
Daniel Dunbar62ee6412012-03-09 18:35:03 +0000821 SourceRange VarRange = V->getSourceRange();
822 SubExprs[CONDVAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(),
823 VarRange.getEnd());
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000824}
825
Craig Toppere6960e22013-08-22 05:28:54 +0000826SwitchStmt::SwitchStmt(const ASTContext &C, VarDecl *Var, Expr *cond)
Benjamin Kramer475386d2015-04-02 15:29:07 +0000827 : Stmt(SwitchStmtClass), FirstCase(nullptr, false) {
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000828 setConditionVariable(C, Var);
Pavel Labath515f4db2013-09-03 14:41:16 +0000829 SubExprs[COND] = cond;
Craig Topper36250ad2014-05-12 05:36:57 +0000830 SubExprs[BODY] = nullptr;
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000831}
832
833VarDecl *SwitchStmt::getConditionVariable() const {
834 if (!SubExprs[VAR])
Craig Topper36250ad2014-05-12 05:36:57 +0000835 return nullptr;
Chad Rosier42032fa2012-08-07 23:12:23 +0000836
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000837 DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]);
838 return cast<VarDecl>(DS->getSingleDecl());
839}
840
Craig Toppere6960e22013-08-22 05:28:54 +0000841void SwitchStmt::setConditionVariable(const ASTContext &C, VarDecl *V) {
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000842 if (!V) {
Craig Topper36250ad2014-05-12 05:36:57 +0000843 SubExprs[VAR] = nullptr;
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000844 return;
845 }
Chad Rosier42032fa2012-08-07 23:12:23 +0000846
Daniel Dunbar62ee6412012-03-09 18:35:03 +0000847 SourceRange VarRange = V->getSourceRange();
848 SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(),
849 VarRange.getEnd());
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000850}
851
John McCallbd066782011-02-09 08:16:59 +0000852Stmt *SwitchCase::getSubStmt() {
Chris Lattner80d51eb2011-02-28 00:18:06 +0000853 if (isa<CaseStmt>(this))
854 return cast<CaseStmt>(this)->getSubStmt();
John McCallbd066782011-02-09 08:16:59 +0000855 return cast<DefaultStmt>(this)->getSubStmt();
856}
857
Craig Toppere6960e22013-08-22 05:28:54 +0000858WhileStmt::WhileStmt(const ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body,
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000859 SourceLocation WL)
Chris Lattner80d51eb2011-02-28 00:18:06 +0000860 : Stmt(WhileStmtClass) {
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000861 setConditionVariable(C, Var);
Pavel Labath515f4db2013-09-03 14:41:16 +0000862 SubExprs[COND] = cond;
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000863 SubExprs[BODY] = body;
864 WhileLoc = WL;
865}
866
867VarDecl *WhileStmt::getConditionVariable() const {
868 if (!SubExprs[VAR])
Craig Topper36250ad2014-05-12 05:36:57 +0000869 return nullptr;
Chad Rosier42032fa2012-08-07 23:12:23 +0000870
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000871 DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]);
872 return cast<VarDecl>(DS->getSingleDecl());
873}
874
Craig Toppere6960e22013-08-22 05:28:54 +0000875void WhileStmt::setConditionVariable(const ASTContext &C, VarDecl *V) {
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000876 if (!V) {
Craig Topper36250ad2014-05-12 05:36:57 +0000877 SubExprs[VAR] = nullptr;
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000878 return;
879 }
Daniel Dunbar62ee6412012-03-09 18:35:03 +0000880
881 SourceRange VarRange = V->getSourceRange();
882 SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(),
883 VarRange.getEnd());
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000884}
885
Ted Kremenek066dd932007-08-24 21:09:09 +0000886// IndirectGotoStmt
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000887LabelDecl *IndirectGotoStmt::getConstantTarget() {
John McCall9de91602010-10-28 08:53:48 +0000888 if (AddrLabelExpr *E =
889 dyn_cast<AddrLabelExpr>(getTarget()->IgnoreParenImpCasts()))
890 return E->getLabel();
Craig Topper36250ad2014-05-12 05:36:57 +0000891 return nullptr;
John McCall9de91602010-10-28 08:53:48 +0000892}
Ted Kremenek066dd932007-08-24 21:09:09 +0000893
Ted Kremenek066dd932007-08-24 21:09:09 +0000894// ReturnStmt
Ted Kremenekc6501db2008-06-17 03:11:08 +0000895const Expr* ReturnStmt::getRetValue() const {
896 return cast_or_null<Expr>(RetExpr);
897}
898Expr* ReturnStmt::getRetValue() {
899 return cast_or_null<Expr>(RetExpr);
Ted Kremenek066dd932007-08-24 21:09:09 +0000900}
John Wiegley1c0675e2011-04-28 01:08:34 +0000901
Warren Huntf6be4cb2014-07-25 20:52:51 +0000902SEHTryStmt::SEHTryStmt(bool IsCXXTry,
903 SourceLocation TryLoc,
904 Stmt *TryBlock,
905 Stmt *Handler)
906 : Stmt(SEHTryStmtClass),
907 IsCXXTry(IsCXXTry),
908 TryLoc(TryLoc)
909{
910 Children[TRY] = TryBlock;
John Wiegley1c0675e2011-04-28 01:08:34 +0000911 Children[HANDLER] = Handler;
912}
913
Warren Huntf6be4cb2014-07-25 20:52:51 +0000914SEHTryStmt* SEHTryStmt::Create(const ASTContext &C, bool IsCXXTry,
Craig Toppere6960e22013-08-22 05:28:54 +0000915 SourceLocation TryLoc, Stmt *TryBlock,
Warren Huntf6be4cb2014-07-25 20:52:51 +0000916 Stmt *Handler) {
917 return new(C) SEHTryStmt(IsCXXTry,TryLoc,TryBlock,Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000918}
919
920SEHExceptStmt* SEHTryStmt::getExceptHandler() const {
921 return dyn_cast<SEHExceptStmt>(getHandler());
922}
923
924SEHFinallyStmt* SEHTryStmt::getFinallyHandler() const {
925 return dyn_cast<SEHFinallyStmt>(getHandler());
926}
927
928SEHExceptStmt::SEHExceptStmt(SourceLocation Loc,
929 Expr *FilterExpr,
930 Stmt *Block)
931 : Stmt(SEHExceptStmtClass),
932 Loc(Loc)
933{
Pavel Labath515f4db2013-09-03 14:41:16 +0000934 Children[FILTER_EXPR] = FilterExpr;
John Wiegley1c0675e2011-04-28 01:08:34 +0000935 Children[BLOCK] = Block;
936}
937
Craig Toppere6960e22013-08-22 05:28:54 +0000938SEHExceptStmt* SEHExceptStmt::Create(const ASTContext &C, SourceLocation Loc,
939 Expr *FilterExpr, Stmt *Block) {
John Wiegley1c0675e2011-04-28 01:08:34 +0000940 return new(C) SEHExceptStmt(Loc,FilterExpr,Block);
941}
942
943SEHFinallyStmt::SEHFinallyStmt(SourceLocation Loc,
944 Stmt *Block)
945 : Stmt(SEHFinallyStmtClass),
946 Loc(Loc),
947 Block(Block)
948{}
949
Craig Toppere6960e22013-08-22 05:28:54 +0000950SEHFinallyStmt* SEHFinallyStmt::Create(const ASTContext &C, SourceLocation Loc,
John Wiegley1c0675e2011-04-28 01:08:34 +0000951 Stmt *Block) {
952 return new(C)SEHFinallyStmt(Loc,Block);
953}
Tareq A. Siraj24110cc2013-04-16 18:53:08 +0000954
Samuel Antao4af1b7b2015-12-02 17:44:43 +0000955CapturedStmt::Capture::Capture(SourceLocation Loc, VariableCaptureKind Kind,
956 VarDecl *Var)
957 : VarAndKind(Var, Kind), Loc(Loc) {
958 switch (Kind) {
959 case VCK_This:
960 assert(!Var && "'this' capture cannot have a variable!");
961 break;
962 case VCK_ByRef:
963 assert(Var && "capturing by reference must have a variable!");
964 break;
965 case VCK_ByCopy:
966 assert(Var && "capturing by copy must have a variable!");
967 assert(
968 (Var->getType()->isScalarType() || (Var->getType()->isReferenceType() &&
969 Var->getType()
970 ->castAs<ReferenceType>()
971 ->getPointeeType()
972 ->isScalarType())) &&
973 "captures by copy are expected to have a scalar type!");
974 break;
975 case VCK_VLAType:
976 assert(!Var &&
977 "Variable-length array type capture cannot have a variable!");
978 break;
979 }
980}
981
Chandler Carruth21c90602015-12-30 03:24:14 +0000982CapturedStmt::VariableCaptureKind
983CapturedStmt::Capture::getCaptureKind() const {
984 return VarAndKind.getInt();
985}
986
987VarDecl *CapturedStmt::Capture::getCapturedVar() const {
988 assert((capturesVariable() || capturesVariableByCopy()) &&
989 "No variable available for 'this' or VAT capture");
990 return VarAndKind.getPointer();
991}
992
Tareq A. Siraj24110cc2013-04-16 18:53:08 +0000993CapturedStmt::Capture *CapturedStmt::getStoredCaptures() const {
994 unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (NumCaptures + 1);
995
996 // Offset of the first Capture object.
Rui Ueyama83aa9792016-01-14 21:00:27 +0000997 unsigned FirstCaptureOffset = llvm::alignTo(Size, llvm::alignOf<Capture>());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +0000998
999 return reinterpret_cast<Capture *>(
1000 reinterpret_cast<char *>(const_cast<CapturedStmt *>(this))
1001 + FirstCaptureOffset);
1002}
1003
Wei Pan17fbf6e2013-05-04 03:59:06 +00001004CapturedStmt::CapturedStmt(Stmt *S, CapturedRegionKind Kind,
1005 ArrayRef<Capture> Captures,
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00001006 ArrayRef<Expr *> CaptureInits,
Tareq A. Siraj6dfa25a2013-04-16 19:37:38 +00001007 CapturedDecl *CD,
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00001008 RecordDecl *RD)
1009 : Stmt(CapturedStmtClass), NumCaptures(Captures.size()),
Wei Pan17fbf6e2013-05-04 03:59:06 +00001010 CapDeclAndKind(CD, Kind), TheRecordDecl(RD) {
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00001011 assert( S && "null captured statement");
Tareq A. Siraj6dfa25a2013-04-16 19:37:38 +00001012 assert(CD && "null captured declaration for captured statement");
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00001013 assert(RD && "null record declaration for captured statement");
1014
1015 // Copy initialization expressions.
1016 Stmt **Stored = getStoredStmts();
1017 for (unsigned I = 0, N = NumCaptures; I != N; ++I)
1018 *Stored++ = CaptureInits[I];
1019
1020 // Copy the statement being captured.
1021 *Stored = S;
1022
1023 // Copy all Capture objects.
1024 Capture *Buffer = getStoredCaptures();
1025 std::copy(Captures.begin(), Captures.end(), Buffer);
1026}
1027
1028CapturedStmt::CapturedStmt(EmptyShell Empty, unsigned NumCaptures)
1029 : Stmt(CapturedStmtClass, Empty), NumCaptures(NumCaptures),
Craig Topper36250ad2014-05-12 05:36:57 +00001030 CapDeclAndKind(nullptr, CR_Default), TheRecordDecl(nullptr) {
1031 getStoredStmts()[NumCaptures] = nullptr;
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00001032}
1033
Craig Toppere6960e22013-08-22 05:28:54 +00001034CapturedStmt *CapturedStmt::Create(const ASTContext &Context, Stmt *S,
Wei Pan17fbf6e2013-05-04 03:59:06 +00001035 CapturedRegionKind Kind,
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00001036 ArrayRef<Capture> Captures,
1037 ArrayRef<Expr *> CaptureInits,
Tareq A. Siraj6dfa25a2013-04-16 19:37:38 +00001038 CapturedDecl *CD,
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00001039 RecordDecl *RD) {
1040 // The layout is
1041 //
1042 // -----------------------------------------------------------
1043 // | CapturedStmt, Init, ..., Init, S, Capture, ..., Capture |
1044 // ----------------^-------------------^----------------------
1045 // getStoredStmts() getStoredCaptures()
1046 //
1047 // where S is the statement being captured.
1048 //
1049 assert(CaptureInits.size() == Captures.size() && "wrong number of arguments");
1050
1051 unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (Captures.size() + 1);
1052 if (!Captures.empty()) {
1053 // Realign for the following Capture array.
Rui Ueyama83aa9792016-01-14 21:00:27 +00001054 Size = llvm::alignTo(Size, llvm::alignOf<Capture>());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00001055 Size += sizeof(Capture) * Captures.size();
1056 }
1057
1058 void *Mem = Context.Allocate(Size);
Wei Pan17fbf6e2013-05-04 03:59:06 +00001059 return new (Mem) CapturedStmt(S, Kind, Captures, CaptureInits, CD, RD);
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00001060}
1061
Craig Toppere6960e22013-08-22 05:28:54 +00001062CapturedStmt *CapturedStmt::CreateDeserialized(const ASTContext &Context,
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00001063 unsigned NumCaptures) {
1064 unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (NumCaptures + 1);
1065 if (NumCaptures > 0) {
1066 // Realign for the following Capture array.
Rui Ueyama83aa9792016-01-14 21:00:27 +00001067 Size = llvm::alignTo(Size, llvm::alignOf<Capture>());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00001068 Size += sizeof(Capture) * NumCaptures;
1069 }
1070
1071 void *Mem = Context.Allocate(Size);
1072 return new (Mem) CapturedStmt(EmptyShell(), NumCaptures);
1073}
1074
1075Stmt::child_range CapturedStmt::children() {
Tareq A. Siraj6dfa25a2013-04-16 19:37:38 +00001076 // Children are captured field initilizers.
1077 return child_range(getStoredStmts(), getStoredStmts() + NumCaptures);
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00001078}
1079
Chandler Carruth21c90602015-12-30 03:24:14 +00001080CapturedDecl *CapturedStmt::getCapturedDecl() {
1081 return CapDeclAndKind.getPointer();
1082}
1083const CapturedDecl *CapturedStmt::getCapturedDecl() const {
1084 return CapDeclAndKind.getPointer();
1085}
1086
1087/// \brief Set the outlined function declaration.
1088void CapturedStmt::setCapturedDecl(CapturedDecl *D) {
1089 assert(D && "null CapturedDecl");
1090 CapDeclAndKind.setPointer(D);
1091}
1092
1093/// \brief Retrieve the captured region kind.
1094CapturedRegionKind CapturedStmt::getCapturedRegionKind() const {
1095 return CapDeclAndKind.getInt();
1096}
1097
1098/// \brief Set the captured region kind.
1099void CapturedStmt::setCapturedRegionKind(CapturedRegionKind Kind) {
1100 CapDeclAndKind.setInt(Kind);
1101}
1102
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00001103bool CapturedStmt::capturesVariable(const VarDecl *Var) const {
Aaron Ballmanc656303a2014-03-14 18:08:33 +00001104 for (const auto &I : captures()) {
1105 if (!I.capturesVariable())
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00001106 continue;
1107
1108 // This does not handle variable redeclarations. This should be
1109 // extended to capture variables with redeclarations, for example
1110 // a thread-private variable in OpenMP.
Aaron Ballmanc656303a2014-03-14 18:08:33 +00001111 if (I.getCapturedVar() == Var)
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00001112 return true;
1113 }
1114
1115 return false;
1116}