[PATCH] D29769: [Assembler] Improve diagnostics for inline assembly.
Sanne Wouda via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 9 09:48:50 PST 2017
sanwou01 updated this revision to Diff 87826.
sanwou01 added a comment.
Missed an off-by-one error...
https://reviews.llvm.org/D29769
Files:
include/llvm/CodeGen/AsmPrinter.h
lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
Index: lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
===================================================================
--- lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
+++ lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
@@ -48,10 +48,16 @@
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 @@
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 @@
// 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 @@
/*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");
}
Index: include/llvm/CodeGen/AsmPrinter.h
===================================================================
--- include/llvm/CodeGen/AsmPrinter.h
+++ include/llvm/CodeGen/AsmPrinter.h
@@ -141,7 +141,7 @@
public:
struct SrcMgrDiagInfo {
SourceMgr SrcMgr;
- const MDNode *LocInfo;
+ std::vector<const MDNode *> LocInfos;
LLVMContext::InlineAsmDiagHandlerTy DiagHandler;
void *DiagContext;
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29769.87826.patch
Type: text/x-patch
Size: 2565 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170209/e017cd74/attachment.bin>
More information about the llvm-commits
mailing list