[llvm] r294448 - Revert "[Assembler] Enable nicer diagnostics for inline assembly."
Diana Picus via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 8 06:02:21 PST 2017
Author: rovka
Date: Wed Feb 8 08:02:16 2017
New Revision: 294448
URL: http://llvm.org/viewvc/llvm-project?rev=294448&view=rev
Log:
Revert "[Assembler] Enable nicer diagnostics for inline assembly."
This reverts commit r294433 because it seems it broke the buildbots.
Removed:
llvm/trunk/test/Assembler/inline-asm-diags.ll
Modified:
llvm/trunk/include/llvm/CodeGen/AsmPrinter.h
llvm/trunk/include/llvm/MC/MCContext.h
llvm/trunk/include/llvm/MC/MCParser/MCAsmParser.h
llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
llvm/trunk/lib/MC/MCContext.cpp
llvm/trunk/lib/MC/MCParser/AsmParser.cpp
Modified: llvm/trunk/include/llvm/CodeGen/AsmPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/AsmPrinter.h?rev=294448&r1=294447&r2=294448&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/AsmPrinter.h (original)
+++ llvm/trunk/include/llvm/CodeGen/AsmPrinter.h Wed Feb 8 08:02:16 2017
@@ -23,7 +23,6 @@
#include "llvm/IR/InlineAsm.h"
#include "llvm/Support/DataTypes.h"
#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/SourceMgr.h"
namespace llvm {
class AsmPrinterHandler;
@@ -138,19 +137,6 @@ 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;
Modified: llvm/trunk/include/llvm/MC/MCContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCContext.h?rev=294448&r1=294447&r2=294448&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCContext.h (original)
+++ llvm/trunk/include/llvm/MC/MCContext.h Wed Feb 8 08:02:16 2017
@@ -59,9 +59,6 @@ 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;
@@ -246,8 +243,6 @@ 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; }
Modified: llvm/trunk/include/llvm/MC/MCParser/MCAsmParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCParser/MCAsmParser.h?rev=294448&r1=294447&r2=294448&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCParser/MCAsmParser.h (original)
+++ llvm/trunk/include/llvm/MC/MCParser/MCAsmParser.h Wed Feb 8 08:02:16 2017
@@ -259,7 +259,7 @@ public:
/// \brief Create an MCAsmParser instance.
MCAsmParser *createMCAsmParser(SourceMgr &, MCContext &, MCStreamer &,
- const MCAsmInfo &, unsigned CB = 0);
+ const MCAsmInfo &);
} // end namespace llvm
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp?rev=294448&r1=294447&r2=294448&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp Wed Feb 8 08:02:16 2017
@@ -40,12 +40,19 @@ using namespace llvm;
#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) {
- AsmPrinter::SrcMgrDiagInfo *DiagInfo =
- static_cast<AsmPrinter::SrcMgrDiagInfo *>(diagInfo);
+ SrcMgrDiagInfo *DiagInfo = static_cast<SrcMgrDiagInfo *>(diagInfo);
assert(DiagInfo && "Diagnostic context not passed down?");
// If the inline asm had metadata associated with it, pull out a location
@@ -92,34 +99,35 @@ void AsmPrinter::EmitInlineAsm(StringRef
return;
}
- if (!DiagInfo) {
- DiagInfo = make_unique<SrcMgrDiagInfo>();
+ SourceMgr SrcMgr;
+ SrcMgr.setIncludeDirs(MCOptions.IASSearchPaths);
- MCContext &Context = MMI->getContext();
- Context.setInlineSourceManager(&DiagInfo->SrcMgr);
+ SrcMgrDiagInfo DiagInfo;
- LLVMContext &LLVMCtx = MMI->getModule()->getContext();
- if (LLVMCtx.getInlineAsmDiagnosticHandler()) {
- DiagInfo->DiagHandler = LLVMCtx.getInlineAsmDiagnosticHandler();
- DiagInfo->DiagContext = LLVMCtx.getInlineAsmDiagnosticContext();
- DiagInfo->SrcMgr.setDiagHandler(srcMgrDiagHandler, DiagInfo.get());
- }
+ // 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) {
+ // If the source manager has an issue, we arrange for srcMgrDiagHandler
+ // to be invoked, getting DiagInfo passed into it.
+ DiagInfo.LocInfo = LocMDNode;
+ DiagInfo.DiagHandler = LLVMCtx.getInlineAsmDiagnosticHandler();
+ DiagInfo.DiagContext = LLVMCtx.getInlineAsmDiagnosticContext();
+ SrcMgr.setDiagHandler(srcMgrDiagHandler, &DiagInfo);
+ HasDiagHandler = true;
}
- 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
- // string for SourceMgr to own.
- Buffer = MemoryBuffer::getMemBufferCopy(Str, "<inline asm>");
+ if (isNullTerminated)
+ Buffer = MemoryBuffer::getMemBuffer(Str, "<inline asm>");
+ else
+ Buffer = MemoryBuffer::getMemBufferCopy(Str, "<inline asm>");
// Tell SrcMgr about this buffer, it takes ownership of the buffer.
- unsigned BufNum = SrcMgr.AddNewSourceBuffer(std::move(Buffer), SMLoc());
+ SrcMgr.AddNewSourceBuffer(std::move(Buffer), SMLoc());
std::unique_ptr<MCAsmParser> Parser(
- createMCAsmParser(SrcMgr, OutContext, *OutStreamer, *MAI, BufNum));
+ createMCAsmParser(SrcMgr, OutContext, *OutStreamer, *MAI));
// We create a new MCInstrInfo here since we might be at the module level
// and not have a MachineFunction to initialize the TargetInstrInfo from and
@@ -143,13 +151,7 @@ void AsmPrinter::EmitInlineAsm(StringRef
int Res = Parser->Run(/*NoInitialTextSection*/ true,
/*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)
+ if (Res && !HasDiagHandler)
report_fatal_error("Error parsing inline asm\n");
}
Modified: llvm/trunk/lib/MC/MCContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCContext.cpp?rev=294448&r1=294447&r2=294448&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCContext.cpp (original)
+++ llvm/trunk/lib/MC/MCContext.cpp Wed Feb 8 08:02:16 2017
@@ -521,15 +521,13 @@ CodeViewContext &MCContext::getCVContext
void MCContext::reportError(SMLoc Loc, const Twine &Msg) {
HadError = true;
- // If we have a source manager use it. Otherwise, try using the inline source
- // manager.
- // If that fails, use the generic report_fatal_error().
- if (SrcMgr)
- SrcMgr->PrintMessage(Loc, SourceMgr::DK_Error, Msg);
- else if (InlineSrcMgr)
- InlineSrcMgr->PrintMessage(Loc, SourceMgr::DK_Error, Msg);
- else
+ // If we have a source manager use it. Otherwise just use the generic
+ // report_fatal_error().
+ if (!SrcMgr)
report_fatal_error(Msg, false);
+
+ // Use the source manager to print the message.
+ SrcMgr->PrintMessage(Loc, SourceMgr::DK_Error, Msg);
}
void MCContext::reportFatalError(SMLoc Loc, const Twine &Msg) {
Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=294448&r1=294447&r2=294448&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Wed Feb 8 08:02:16 2017
@@ -209,7 +209,7 @@ private:
public:
AsmParser(SourceMgr &SM, MCContext &Ctx, MCStreamer &Out,
- const MCAsmInfo &MAI, unsigned CB);
+ const MCAsmInfo &MAI);
~AsmParser() override;
bool Run(bool NoInitialTextSection, bool NoFinalize = false) override;
@@ -572,9 +572,9 @@ extern MCAsmParserExtension *createCOFFA
enum { DEFAULT_ADDRSPACE = 0 };
AsmParser::AsmParser(SourceMgr &SM, MCContext &Ctx, MCStreamer &Out,
- const MCAsmInfo &MAI, unsigned CB = 0)
+ const MCAsmInfo &MAI)
: Lexer(MAI), Ctx(Ctx), Out(Out), MAI(MAI), SrcMgr(SM),
- PlatformParser(nullptr), CurBuffer(CB ? CB : SM.getMainFileID()),
+ PlatformParser(nullptr), CurBuffer(SM.getMainFileID()),
MacrosEnabledFlag(true), CppHashInfo(), AssemblerDialect(~0U),
IsDarwin(false), ParsingInlineAsm(false) {
HadError = false;
@@ -608,10 +608,6 @@ AsmParser::AsmParser(SourceMgr &SM, MCCo
AsmParser::~AsmParser() {
assert((HadError || ActiveMacros.empty()) &&
"Unexpected active macro instantiation!");
-
- // Restore the saved diagnostics handler and context for use during
- // finalization.
- SrcMgr.setDiagHandler(SavedDiagHandler, SavedDiagContext);
}
void AsmParser::printMacroInstantiations() {
@@ -5524,7 +5520,6 @@ bool parseAssignmentExpression(StringRef
/// \brief Create an MCAsmParser instance.
MCAsmParser *llvm::createMCAsmParser(SourceMgr &SM, MCContext &C,
- MCStreamer &Out, const MCAsmInfo &MAI,
- unsigned CB) {
- return new AsmParser(SM, C, Out, MAI, CB);
+ MCStreamer &Out, const MCAsmInfo &MAI) {
+ return new AsmParser(SM, C, Out, MAI);
}
Removed: llvm/trunk/test/Assembler/inline-asm-diags.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/inline-asm-diags.ll?rev=294447&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/inline-asm-diags.ll (original)
+++ llvm/trunk/test/Assembler/inline-asm-diags.ll (removed)
@@ -1,9 +0,0 @@
-; RUN: not llc -filetype=obj < %s 2>&1 -o /dev/null | FileCheck %s
-
-module asm ".word 0x10"
-module asm ".word -bar"
-
-; CHECK: <inline asm>:2:7: error: expected relocatable expression
-
-module asm ".word -foo"
-; CHECK: <inline asm>:3:7: error: expected relocatable expression
More information about the llvm-commits
mailing list