From: Reid Kleckner Date: Mon, 28 Jul 2014 23:12:59 +0000 (+0000) Subject: Add a location to MS inline asm blobs X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3bd4314719834ba3a679c549dece25c9f1835387;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@214141 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGStmt.cpp b/lib/CodeGen/CGStmt.cpp index 62a80a334e..d75b97ddf6 100644 --- a/lib/CodeGen/CGStmt.cpp +++ b/lib/CodeGen/CGStmt.cpp @@ -2023,10 +2023,15 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) { 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(&S)) + // call. + if (const GCCAsmStmt *gccAsmStmt = dyn_cast(&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 RegResults;