[ms-inline asm] Stmt destructors are never called, so allocate the AsmToks using
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
diff --git a/include/clang/AST/Stmt.h b/include/clang/AST/Stmt.h
index 45e0892..8dbcf5d 100644
--- a/include/clang/AST/Stmt.h
+++ b/include/clang/AST/Stmt.h
@@ -1621,17 +1621,19 @@
 ///
 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 @@
   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; }
diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h
index f332bbe..1eec97b 100644
--- a/include/clang/Sema/Sema.h
+++ b/include/clang/Sema/Sema.h
@@ -2543,7 +2543,7 @@
                           bool MSAsm = false);
 
   StmtResult ActOnMSAsmStmt(SourceLocation AsmLoc,
-                            SmallVectorImpl<Token> &AsmToks,
+                            ArrayRef<Token> AsmToks,
                             std::string &AsmString,
                             SourceLocation EndLoc);
 
diff --git a/lib/AST/Stmt.cpp b/lib/AST/Stmt.cpp
index 763f8bd..5e7a13e 100644
--- a/lib/AST/Stmt.cpp
+++ b/lib/AST/Stmt.cpp
@@ -584,13 +584,14 @@
 }
 
 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,
diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp
index 69f28ec..56e87e4 100644
--- a/lib/Parse/ParseStmt.cpp
+++ b/lib/Parse/ParseStmt.cpp
@@ -1818,7 +1818,8 @@
 
   // 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.
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp
index 718a7e6..5df1a50 100644
--- a/lib/Sema/SemaStmt.cpp
+++ b/lib/Sema/SemaStmt.cpp
@@ -2748,7 +2748,7 @@
 }
 
 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.
diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h
index 71af263..76cd51f 100644
--- a/lib/Sema/TreeTransform.h
+++ b/lib/Sema/TreeTransform.h
@@ -1185,7 +1185,7 @@
   /// 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 @@
 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());
 }