]> granicus.if.org Git - clang/commitdiff
[ms-inline asm] Stmt destructors are never called, so allocate the AsmToks using
authorChad Rosier <mcrosier@apple.com>
Tue, 7 Aug 2012 00:29:06 +0000 (00:29 +0000)
committerChad Rosier <mcrosier@apple.com>
Tue, 7 Aug 2012 00:29:06 +0000 (00:29 +0000)
the ASTContext BumpPtr.  Also use the preferred llvm::ArrayRef interface.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161373 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Stmt.h
include/clang/Sema/Sema.h
lib/AST/Stmt.cpp
lib/Parse/ParseStmt.cpp
lib/Sema/SemaStmt.cpp
lib/Sema/TreeTransform.h

index 45e0892ce3a25329ea18907c7484fd58c0d4bfc8..8dbcf5dd5e4029c67866a507159510e40516d869 100644 (file)
@@ -1621,17 +1621,19 @@ public:
 ///
 class MSAsmStmt : public Stmt {
   SourceLocation AsmLoc, EndLoc;
-  SmallVector<Token, 4> AsmToks;
   std::string AsmStr;
 
   bool IsSimple;
   bool IsVolatile;
 
+  unsigned NumAsmToks;
+
+  Token *AsmToks;
   Stmt **Exprs;
 
 public:
   MSAsmStmt(ASTContext &C, SourceLocation asmloc,
-            SmallVectorImpl<Token> &asmtoks, std::string &asmstr,
+            ArrayRef<Token> asmtoks, std::string &asmstr,
             SourceLocation endloc);
 
   SourceLocation getAsmLoc() const { return AsmLoc; }
@@ -1639,7 +1641,8 @@ public:
   SourceLocation getEndLoc() const { return EndLoc; }
   void setEndLoc(SourceLocation L) { EndLoc = L; }
 
-  SmallVectorImpl<Token> &getAsmToks() { return AsmToks; }
+  unsigned getNumAsmToks() { return NumAsmToks; }
+  Token *getAsmToks() { return AsmToks; }
 
   bool isVolatile() const { return IsVolatile; }
   void setVolatile(bool V) { IsVolatile = V; }
index f332bbeae9f694638cae6767b5cb51ef9364c1a4..1eec97bd9f8333543676317b9ac6b7ee8f2cfc42 100644 (file)
@@ -2543,7 +2543,7 @@ public:
                           bool MSAsm = false);
 
   StmtResult ActOnMSAsmStmt(SourceLocation AsmLoc,
-                            SmallVectorImpl<Token> &AsmToks,
+                            ArrayRef<Token> AsmToks,
                             std::string &AsmString,
                             SourceLocation EndLoc);
 
index 763f8bd33a3085d2e6fcc20c403c560f5b4efb57..5e7a13e09d9d6f10caf8055beb6acfa33c16628a 100644 (file)
@@ -584,13 +584,14 @@ AsmStmt::AsmStmt(ASTContext &C, SourceLocation asmloc, bool issimple,
 }
 
 MSAsmStmt::MSAsmStmt(ASTContext &C, SourceLocation asmloc,
-                     SmallVectorImpl<Token> &asmtoks,
+                     ArrayRef<Token> asmtoks,
                      std::string &asmstr, SourceLocation endloc)
   : Stmt(MSAsmStmtClass), AsmLoc(asmloc), EndLoc(endloc),
-    AsmToks(asmtoks.size()), AsmStr(asmstr),
-    IsSimple(true), IsVolatile(true) {
-  for (unsigned i = 0, e = asmtoks.size(); i != e; ++i)
-    AsmToks.push_back(asmtoks[i]);
+    AsmStr(asmstr), IsSimple(true), IsVolatile(true), NumAsmToks(asmtoks.size()) {
+
+  AsmToks = new (C) Token[NumAsmToks];
+  for (unsigned i = 0, e = NumAsmToks; i != e; ++i)
+    AsmToks[i] = asmtoks[i];
 }
 
 ObjCForCollectionStmt::ObjCForCollectionStmt(Stmt *Elem, Expr *Collect,
index 69f28ecd6db9681f3ca3d21e95ed7040457ae433..56e87e4904449316379968792bb9ab9fbd412415 100644 (file)
@@ -1818,7 +1818,8 @@ StmtResult Parser::ParseMicrosoftAsmStatement(SourceLocation AsmLoc) {
 
   // FIXME: We should be passing source locations for better diagnostics.
   std::string AsmString = Asm.c_str();
-  return Actions.ActOnMSAsmStmt(AsmLoc, AsmToks, AsmString, EndLoc);
+  return Actions.ActOnMSAsmStmt(AsmLoc, llvm::makeArrayRef(AsmToks), AsmString,
+                                EndLoc);
 }
 
 /// ParseAsmStatement - Parse a GNU extended asm statement.
index 718a7e6b53835e362241e22e37240d632e492345..5df1a50655c7fb57ebe1fbcb8dbb8e986dba6ff6 100644 (file)
@@ -2748,7 +2748,7 @@ StmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc, bool IsSimple,
 }
 
 StmtResult Sema::ActOnMSAsmStmt(SourceLocation AsmLoc,
-                                SmallVectorImpl<Token> &AsmToks,
+                                ArrayRef<Token> AsmToks,
                                 std::string &AsmString,
                                 SourceLocation EndLoc) {
   // MS-style inline assembly is not fully supported, so emit a warning.
index 71af26364274741e0266ba74efaa01c8e2cd6ba6..76cd51f3e8c9ffa655922b9f465269fdfa127506 100644 (file)
@@ -1185,7 +1185,7 @@ public:
   /// By default, performs semantic analysis to build the new statement.
   /// Subclasses may override this routine to provide different behavior.
   StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc,
-                              SmallVectorImpl<Token> &AsmToks,
+                              ArrayRef<Token> AsmToks,
                               std::string &AsmString,
                               SourceLocation EndLoc) {
     return getSema().ActOnMSAsmStmt(AsmLoc, AsmToks, AsmString, EndLoc);
@@ -5610,9 +5610,11 @@ TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
 template<typename Derived>
 StmtResult
 TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
+  ArrayRef<Token> AsmToks =
+    llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
   // No need to transform the asm string literal.
   return getDerived().RebuildMSAsmStmt(S->getAsmLoc(),
-                                       S->getAsmToks(),
+                                       AsmToks,
                                        *S->getAsmString(),
                                        S->getEndLoc());
 }