]> granicus.if.org Git - llvm/commitdiff
[Assembler] Improve diagnostics for inline assembly.
authorSanne Wouda <sanne.wouda@arm.com>
Mon, 13 Feb 2017 13:58:00 +0000 (13:58 +0000)
committerSanne Wouda <sanne.wouda@arm.com>
Mon, 13 Feb 2017 13:58:00 +0000 (13:58 +0000)
Summary:
Keep a vector of LocInfos around; one for each call to EmitInlineAsm.
Since each call to EmitInlineAsm creates a new buffer in the inline asm
SourceMgr, we can use the buffer number to map to the right LocInfo.

Reviewers: rengolin, grosbach, rnk, echristo

Reviewed By: rnk

Subscribers: mehdi_amini, llvm-commits

Differential Revision: https://reviews.llvm.org/D29769

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294947 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/AsmPrinter.h
lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp

index 1c832986c80b9cfd295cefe58601d1336cc1f1fc..2d43dbe7b6d80cb1c3a846ad27ddb01473c55294 100644 (file)
@@ -141,7 +141,7 @@ private:
 public:
   struct SrcMgrDiagInfo {
     SourceMgr SrcMgr;
-    const MDNode *LocInfo;
+    std::vector<const MDNode *> LocInfos;
     LLVMContext::InlineAsmDiagHandlerTy DiagHandler;
     void *DiagContext;
   };
index 165b8eea0943e65a99329f7ccde664f7f8a813e4..683e622e3d5379fb884324194f6133c24e221901 100644 (file)
@@ -48,10 +48,16 @@ static void srcMgrDiagHandler(const SMDiagnostic &Diag, void *diagInfo) {
       static_cast<AsmPrinter::SrcMgrDiagInfo *>(diagInfo);
   assert(DiagInfo && "Diagnostic context not passed down?");
 
+  // Look up a LocInfo for the buffer this diagnostic is coming from.
+  unsigned BufNum = DiagInfo->SrcMgr.FindBufferContainingLoc(Diag.getLoc());
+  const MDNode *LocInfo = nullptr;
+  if (BufNum > 0 && BufNum <= DiagInfo->LocInfos.size())
+    LocInfo = DiagInfo->LocInfos[BufNum-1];
+
   // If the inline asm had metadata associated with it, pull out a location
   // cookie corresponding to which line the error occurred on.
   unsigned LocCookie = 0;
-  if (const MDNode *LocInfo = DiagInfo->LocInfo) {
+  if (LocInfo) {
     unsigned ErrorLine = Diag.getLineNo()-1;
     if (ErrorLine >= LocInfo->getNumOperands())
       ErrorLine = 0;
@@ -108,7 +114,6 @@ void AsmPrinter::EmitInlineAsm(StringRef Str, const MCSubtargetInfo &STI,
 
   SourceMgr &SrcMgr = DiagInfo->SrcMgr;
   SrcMgr.setIncludeDirs(MCOptions.IASSearchPaths);
-  DiagInfo->LocInfo = LocMDNode;
 
   std::unique_ptr<MemoryBuffer> Buffer;
   // The inline asm source manager will outlive Str, so make a copy of the
@@ -118,6 +123,12 @@ void AsmPrinter::EmitInlineAsm(StringRef Str, const MCSubtargetInfo &STI,
   // Tell SrcMgr about this buffer, it takes ownership of the buffer.
   unsigned BufNum = SrcMgr.AddNewSourceBuffer(std::move(Buffer), SMLoc());
 
+  // Store LocMDNode in DiagInfo, using BufNum as an identifier.
+  if (LocMDNode) {
+    DiagInfo->LocInfos.resize(BufNum);
+    DiagInfo->LocInfos[BufNum-1] = LocMDNode;
+  }
+
   std::unique_ptr<MCAsmParser> Parser(
       createMCAsmParser(SrcMgr, OutContext, *OutStreamer, *MAI, BufNum));
 
@@ -144,11 +155,6 @@ void AsmPrinter::EmitInlineAsm(StringRef Str, const MCSubtargetInfo &STI,
                         /*NoFinalize*/ true);
   emitInlineAsmEnd(STI, &TAP->getSTI());
 
-  // LocInfo cannot be used for error generation from the backend.
-  // FIXME: associate LocInfo with the SourceBuffer to improve backend
-  // messages.
-  DiagInfo->LocInfo = nullptr;
-
   if (Res && !DiagInfo->DiagHandler)
     report_fatal_error("Error parsing inline asm\n");
 }