Index: include/llvm/CodeGen/AsmPrinter.h =================================================================== --- include/llvm/CodeGen/AsmPrinter.h +++ include/llvm/CodeGen/AsmPrinter.h @@ -23,6 +23,7 @@ #include "llvm/IR/InlineAsm.h" #include "llvm/Support/DataTypes.h" #include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/SourceMgr.h" namespace llvm { class AsmPrinterHandler; @@ -109,6 +110,9 @@ MCSymbol *CurrentFnEnd; MCSymbol *CurExceptionSym; + /// A SourceMgr for inline assembly. + mutable std::unique_ptr InlineSrcMgr; + // The garbage collection metadata printer table. void *GCMetadataPrinters; // Really a DenseMap. @@ -137,6 +141,27 @@ /// maintains ownership of the emitters. SmallVector Handlers; +public: + struct SrcMgrDiagInfo { + const MDNode *LocInfo; + LLVMContext::InlineAsmDiagHandlerTy DiagHandler; + void *DiagContext; + }; + +private: + mutable std::vector> DiagInfos; + + SourceMgr *getInlineSourceManager() const { + if (!InlineSrcMgr) + InlineSrcMgr = make_unique(); + + return InlineSrcMgr.get(); + } + + SrcMgrDiagInfo &getNewDiagInfo() const { + DiagInfos.push_back(make_unique()); + return *DiagInfos.back(); + } /// If the target supports dwarf debug info, this pointer is non-null. DwarfDebug *DD; Index: lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp =================================================================== --- lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp +++ lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp @@ -40,19 +40,12 @@ #define DEBUG_TYPE "asm-printer" -namespace { - struct SrcMgrDiagInfo { - const MDNode *LocInfo; - LLVMContext::InlineAsmDiagHandlerTy DiagHandler; - void *DiagContext; - }; -} - /// srcMgrDiagHandler - This callback is invoked when the SourceMgr for an /// inline asm has an error in it. diagInfo is a pointer to the SrcMgrDiagInfo /// struct above. static void srcMgrDiagHandler(const SMDiagnostic &Diag, void *diagInfo) { - SrcMgrDiagInfo *DiagInfo = static_cast(diagInfo); + AsmPrinter::SrcMgrDiagInfo *DiagInfo = + static_cast(diagInfo); assert(DiagInfo && "Diagnostic context not passed down?"); // If the inline asm had metadata associated with it, pull out a location @@ -99,15 +92,15 @@ return; } - SourceMgr SrcMgr; + SourceMgr &SrcMgr = *getInlineSourceManager(); SrcMgr.setIncludeDirs(MCOptions.IASSearchPaths); - SrcMgrDiagInfo DiagInfo; // If the current LLVMContext has an inline asm handler, set it in SourceMgr. LLVMContext &LLVMCtx = MMI->getModule()->getContext(); bool HasDiagHandler = false; if (LLVMCtx.getInlineAsmDiagnosticHandler() != nullptr) { + SrcMgrDiagInfo &DiagInfo = getNewDiagInfo(); // If the source manager has an issue, we arrange for srcMgrDiagHandler // to be invoked, getting DiagInfo passed into it. DiagInfo.LocInfo = LocMDNode;