r214141 - Add a location to MS inline asm blobs

Reid Kleckner reid at kleckner.net
Mon Jul 28 16:13:00 PDT 2014


Author: rnk
Date: Mon Jul 28 18:12:59 2014
New Revision: 214141

URL: http://llvm.org/viewvc/llvm-project?rev=214141&view=rev
Log:
Add a location to MS inline asm blobs

This isn't nearly as elaborate as the GCC inline asm which emits an
array of source locations, but it's very, very hard to trigger backend
diagnostics in MS inline asm because we parse it up front with good
source information, unlike GCC inline asm.

Currently I can trigger a "inline assembly requires more registers than
available" diagnostic with this code:

  void foo();
  void bar() {
    __asm pusha
    __asm call foo
    __asm popa
  }

However, if I committed that as a test case, I would have to remove it
once I fix PR20052.

Modified:
    cfe/trunk/lib/CodeGen/CGStmt.cpp

Modified: cfe/trunk/lib/CodeGen/CGStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmt.cpp?rev=214141&r1=214140&r2=214141&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGStmt.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmt.cpp Mon Jul 28 18:12:59 2014
@@ -2023,10 +2023,15 @@ void CodeGenFunction::EmitAsmStmt(const
                        llvm::Attribute::NoUnwind);
 
   // Slap the source location of the inline asm into a !srcloc metadata on the
-  // call.  FIXME: Handle metadata for MS-style inline asms.
-  if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(&S))
+  // call.
+  if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(&S)) {
     Result->setMetadata("srcloc", getAsmSrcLocInfo(gccAsmStmt->getAsmString(),
                                                    *this));
+  } else {
+    // At least put the line number on MS inline asm blobs.
+    auto Loc = llvm::ConstantInt::get(Int32Ty, S.getAsmLoc().getRawEncoding());
+    Result->setMetadata("srcloc", llvm::MDNode::get(getLLVMContext(), Loc));
+  }
 
   // Extract all of the register value results from the asm.
   std::vector<llvm::Value*> RegResults;





More information about the cfe-commits mailing list