[ms-inline asm] Address a FIXME by computing the number of asm statements when
building the AsmString.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161988 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp
index 2aabd9e..f2fd7e5 100644
--- a/lib/Sema/SemaStmt.cpp
+++ b/lib/Sema/SemaStmt.cpp
@@ -2840,17 +2840,20 @@
 
 // Build the unmodified MSAsmString.
 static std::string buildMSAsmString(Sema &SemaRef,
-                                    ArrayRef<Token> AsmToks) {                                    
+                                    ArrayRef<Token> AsmToks,
+                                    unsigned &NumAsmStrings) {
   assert (!AsmToks.empty() && "Didn't expect an empty AsmToks!");
   SmallString<512> Asm;
   SmallString<512> TokenBuf;
   TokenBuf.resize(512);
 
+  NumAsmStrings = 0;
   for (unsigned i = 0, e = AsmToks.size(); i < e; ++i) {
     bool isNewAsm = i == 0 || AsmToks[i].isAtStartOfLine() ||
       AsmToks[i].is(tok::kw_asm);
 
     if (isNewAsm) {
+      ++NumAsmStrings;
       if (i)
         Asm += '\n';
       if (AsmToks[i].is(tok::kw_asm)) {
@@ -2889,18 +2892,12 @@
     return Owned(NS);
   }
 
-  std::string AsmString = buildMSAsmString(*this, AsmToks);
+  unsigned NumAsmStrings;
+  std::string AsmString = buildMSAsmString(*this, AsmToks, NumAsmStrings);
 
   bool IsSimple;
   std::vector<std::string> PatchedAsmStrings;
-
-  // FIXME: Count this while parsing.
-  unsigned NumAsmStrings = 0;
-  for (unsigned i = 0, e = AsmToks.size(); i != e; ++i)
-    if (i == 0 || AsmToks[i].isAtStartOfLine() || AsmToks[i].is(tok::kw_asm))
-      ++NumAsmStrings;
-
-  PatchedAsmStrings.resize(NumAsmStrings ? NumAsmStrings : 1);
+  PatchedAsmStrings.resize(NumAsmStrings);
 
   // Rewrite operands to appease the AsmParser.
   patchMSAsmStrings(*this, IsSimple, AsmLoc, AsmToks, Context.getTargetInfo(),