[cfe-commits] r161966 - /cfe/trunk/lib/Sema/SemaStmt.cpp

Chad Rosier mcrosier at apple.com
Wed Aug 15 11:09:19 PDT 2012


Author: mcrosier
Date: Wed Aug 15 13:09:18 2012
New Revision: 161966

URL: http://llvm.org/viewvc/llvm-project?rev=161966&view=rev
Log:
[ms-inline asm] Capturing loop-scoped (std::string)Reg with a StringRef is bad.

Modified:
    cfe/trunk/lib/Sema/SemaStmt.cpp

Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=161966&r1=161965&r2=161966&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Wed Aug 15 13:09:18 2012
@@ -2857,7 +2857,9 @@
                                 SourceLocation EndLoc) {
   // MS-style inline assembly is not fully supported, so emit a warning.
   Diag(AsmLoc, diag::warn_unsupported_msasm);
+  unsigned NumClobberRegs = 0;
   SmallVector<StringRef,4> Clobbers;
+  SmallVector<std::string,4> ClobberRegs;
 
   // Empty asm statements don't need to instantiate the AsmParser, etc.
   if (AsmToks.empty()) {
@@ -2962,13 +2964,13 @@
       TheTarget->createMCInstPrinter(1, *MAI, *MII, *MRI, *STI);
 
     // Build the list of clobbers.
+    ClobberRegs.resize(NumClobberRegs + Desc.getNumDefs());
     for (unsigned i = 0, e = Desc.getNumDefs(); i != e; ++i) {
       const llvm::MCOperand &Op = Inst.getOperand(i);
       if (!Op.isReg())
         continue;
 
-      std::string Reg;
-      llvm::raw_string_ostream OS(Reg);
+      llvm::raw_string_ostream OS(ClobberRegs[NumClobberRegs]);
       IP->printRegName(OS, Op.getReg());
 
       StringRef Clobber(OS.str());
@@ -2976,7 +2978,7 @@
         return StmtError(Diag(AsmLoc, diag::err_asm_unknown_register_name) <<
                          Clobber);
       // FIXME: Asm blocks may result in redundant clobbers.
-      Clobbers.push_back(Reg);
+      Clobbers.push_back(ClobberRegs[NumClobberRegs++]);
     }
   }
 





More information about the cfe-commits mailing list