diff options
author | dim <dim@FreeBSD.org> | 2017-05-06 11:13:33 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2017-05-06 11:13:33 +0000 |
commit | 5b1f711beb02bbe85b317f6e7ee75fdaa2cc75ad (patch) | |
tree | 63c166780c39404b0bd523e9521de5b1d1651d3d /contrib/llvm/include | |
parent | cab775df1a1541c50fce19e4c67bfde02af8b97d (diff) | |
download | FreeBSD-src-5b1f711beb02bbe85b317f6e7ee75fdaa2cc75ad.zip FreeBSD-src-5b1f711beb02bbe85b317f6e7ee75fdaa2cc75ad.tar.gz |
MFC r317458:
Pull in r294458 from upstream llvm trunk (by Sanne Wouda):
[Assembler] Enable nicer diagnostics for inline assembly.
Fixed test.
Summary:
Enables source location in diagnostic messages from the backend.
This is after parsing, during finalization. This requires the
SourceMgr, the inline assembly string buffer, and DiagInfo to still
be alive after EmitInlineAsm returns.
This patch creates a single SourceMgr for inline assembly inside the
AsmPrinter. MCContext gets a pointer to this SourceMgr. Using one
SourceMgr per call to EmitInlineAsm would make it difficult for
MCContext to figure out in which SourceMgr the SMLoc is located,
while a single SourceMgr can figure it out if it has multiple
buffers.
The Str argument to EmitInlineAsm is copied into a buffer and owned
by the inline asm SourceMgr. This ensures that DiagHandlers won't
print garbage. (Clang emits a "note: instantiated into assembly
here", which refers to this string.)
The AsmParser gets destroyed before finalization, which means that
the DiagHandlers the AsmParser installs into the SourceMgr will be
stale. Restore the saved DiagHandlers.
Since now we're using just one SourceMgr for multiple inline asm
strings, we need to tell the AsmParser which buffer it needs to parse
currently. Hand a buffer id -- returned from SourceMgr::
AddNewSourceBuffer -- to the AsmParser.
Reviewers: rnk, grosbach, compnerd, rengolin, rovka, anemet
Reviewed By: rnk
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D29441
This improves error reporting for some inline assembly constructs that
clang does not approve of: instead of crashing with a "fatal backend
error", it will now show a normal error message, and point out the
location of the problematic assembly.
Reported by: mmel
Diffstat (limited to 'contrib/llvm/include')
-rw-r--r-- | contrib/llvm/include/llvm/CodeGen/AsmPrinter.h | 14 | ||||
-rw-r--r-- | contrib/llvm/include/llvm/MC/MCContext.h | 5 | ||||
-rw-r--r-- | contrib/llvm/include/llvm/MC/MCParser/MCAsmParser.h | 2 |
3 files changed, 20 insertions, 1 deletions
diff --git a/contrib/llvm/include/llvm/CodeGen/AsmPrinter.h b/contrib/llvm/include/llvm/CodeGen/AsmPrinter.h index 4daca03..db3a6fc 100644 --- a/contrib/llvm/include/llvm/CodeGen/AsmPrinter.h +++ b/contrib/llvm/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; @@ -137,6 +138,19 @@ private: /// maintains ownership of the emitters. SmallVector<HandlerInfo, 1> Handlers; +public: + struct SrcMgrDiagInfo { + SourceMgr SrcMgr; + const MDNode *LocInfo; + LLVMContext::InlineAsmDiagHandlerTy DiagHandler; + void *DiagContext; + }; + +private: + /// Structure for generating diagnostics for inline assembly. Only initialised + /// when necessary. + mutable std::unique_ptr<SrcMgrDiagInfo> DiagInfo; + /// If the target supports dwarf debug info, this pointer is non-null. DwarfDebug *DD; diff --git a/contrib/llvm/include/llvm/MC/MCContext.h b/contrib/llvm/include/llvm/MC/MCContext.h index f846b63..5d4c47f 100644 --- a/contrib/llvm/include/llvm/MC/MCContext.h +++ b/contrib/llvm/include/llvm/MC/MCContext.h @@ -59,6 +59,9 @@ namespace llvm { /// The SourceMgr for this object, if any. const SourceMgr *SrcMgr; + /// The SourceMgr for inline assembly, if any. + SourceMgr *InlineSrcMgr; + /// The MCAsmInfo for this target. const MCAsmInfo *MAI; @@ -240,6 +243,8 @@ namespace llvm { const SourceMgr *getSourceManager() const { return SrcMgr; } + void setInlineSourceManager(SourceMgr *SM) { InlineSrcMgr = SM; } + const MCAsmInfo *getAsmInfo() const { return MAI; } const MCRegisterInfo *getRegisterInfo() const { return MRI; } diff --git a/contrib/llvm/include/llvm/MC/MCParser/MCAsmParser.h b/contrib/llvm/include/llvm/MC/MCParser/MCAsmParser.h index eb85a3a..4dc15d6 100644 --- a/contrib/llvm/include/llvm/MC/MCParser/MCAsmParser.h +++ b/contrib/llvm/include/llvm/MC/MCParser/MCAsmParser.h @@ -258,7 +258,7 @@ public: /// \brief Create an MCAsmParser instance. MCAsmParser *createMCAsmParser(SourceMgr &, MCContext &, MCStreamer &, - const MCAsmInfo &); + const MCAsmInfo &, unsigned CB = 0); } // End llvm namespace |