[llvm] r253327 - [Assembler] Allow non-fatal errors after parsing
Oliver Stannard via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 17 01:58:07 PST 2015
Author: olista01
Date: Tue Nov 17 03:58:07 2015
New Revision: 253327
URL: http://llvm.org/viewvc/llvm-project?rev=253327&view=rev
Log:
[Assembler] Allow non-fatal errors after parsing
This adds reportError to MCContext, which can be used as an alternative to
reportFatalError when the assembler wants to try to continue processing the
rest of the file after the error is reported, so that all of the errors ina
file can be reported. It records the fact that an error was encountered, so we
can avoid emitting an object file if any errors occurred.
This patch doesn't add any uses of this function (a later patch will convert
most uses of reportFatalError to use it), but there is a small functional
change: we use the SourceManager to print the error message, even if we have a
null SMLoc. This means that we get a SourceManager-style message, with the file
and line information shown as <unknown>, rather than the "LLVM ERROR" style
used by report_fatal_error.
Modified:
llvm/trunk/include/llvm/MC/MCContext.h
llvm/trunk/lib/MC/MCContext.cpp
llvm/trunk/lib/MC/MCParser/AsmParser.cpp
llvm/trunk/test/MC/Mips/micromips-diagnostic-fixup.s
llvm/trunk/test/MC/Mips/mips-diagnostic-fixup.s
Modified: llvm/trunk/include/llvm/MC/MCContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCContext.h?rev=253327&r1=253326&r2=253327&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCContext.h (original)
+++ llvm/trunk/include/llvm/MC/MCContext.h Tue Nov 17 03:58:07 2015
@@ -213,6 +213,8 @@ namespace llvm {
/// Do automatic reset in destructor
bool AutoReset;
+ bool HadError;
+
MCSymbol *createSymbolImpl(const StringMapEntry<bool> *Name,
bool CanBeUnnamed);
MCSymbol *createSymbol(StringRef Name, bool AlwaysAddSuffix,
@@ -514,11 +516,13 @@ namespace llvm {
}
void deallocate(void *Ptr) {}
+ bool hadError() { return HadError; }
+ void reportError(SMLoc L, const Twine &Msg);
// Unrecoverable error has occurred. Display the best diagnostic we can
// and bail via exit(1). For now, most MC backend errors are unrecoverable.
// FIXME: We should really do something about that.
LLVM_ATTRIBUTE_NORETURN void reportFatalError(SMLoc L,
- const Twine &Msg) const;
+ const Twine &Msg);
};
} // end namespace llvm
Modified: llvm/trunk/lib/MC/MCContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCContext.cpp?rev=253327&r1=253326&r2=253327&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCContext.cpp (original)
+++ llvm/trunk/lib/MC/MCContext.cpp Tue Nov 17 03:58:07 2015
@@ -42,7 +42,7 @@ MCContext::MCContext(const MCAsmInfo *ma
CurrentDwarfLoc(0, 0, 0, DWARF2_FLAG_IS_STMT, 0, 0), DwarfLocSeen(false),
GenDwarfForAssembly(false), GenDwarfFileNumber(0), DwarfVersion(4),
AllowTemporaryLabels(true), DwarfCompileUnitID(0),
- AutoReset(DoAutoReset) {
+ AutoReset(DoAutoReset), HadError(false) {
std::error_code EC = llvm::sys::fs::current_path(CompilationDir);
if (EC)
@@ -102,6 +102,8 @@ void MCContext::reset() {
DwarfLocSeen = false;
GenDwarfForAssembly = false;
GenDwarfFileNumber = 0;
+
+ HadError = false;
}
//===----------------------------------------------------------------------===//
@@ -475,14 +477,24 @@ void MCContext::finalizeDwarfSections(MC
[&](MCSection *Sec) { return !MCOS.mayHaveInstructions(*Sec); });
}
-void MCContext::reportFatalError(SMLoc Loc, const Twine &Msg) const {
- // If we have a source manager and a location, use it. Otherwise just
- // use the generic report_fatal_error().
- if (!SrcMgr || Loc == SMLoc())
+//===----------------------------------------------------------------------===//
+// Error Reporting
+//===----------------------------------------------------------------------===//
+
+void MCContext::reportError(SMLoc Loc, const Twine &Msg) {
+ HadError = true;
+
+ // 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) {
+ reportError(Loc, Msg);
// If we reached here, we are failing ungracefully. Run the interrupt handlers
// to make sure any special cleanups get done, in particular that we remove
Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=253327&r1=253326&r2=253327&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Tue Nov 17 03:58:07 2015
@@ -703,7 +703,7 @@ bool AsmParser::Run(bool NoInitialTextSe
if (!HadError && !NoFinalize)
Out.Finish();
- return HadError;
+ return HadError || getContext().hadError();
}
void AsmParser::checkForValidSection() {
Modified: llvm/trunk/test/MC/Mips/micromips-diagnostic-fixup.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/Mips/micromips-diagnostic-fixup.s?rev=253327&r1=253326&r2=253327&view=diff
==============================================================================
--- llvm/trunk/test/MC/Mips/micromips-diagnostic-fixup.s (original)
+++ llvm/trunk/test/MC/Mips/micromips-diagnostic-fixup.s Tue Nov 17 03:58:07 2015
@@ -1,6 +1,6 @@
# RUN: not llvm-mc %s -triple=mipsel-unknown-linux -mcpu=mips32r2 -arch=mips -mattr=+micromips 2>&1 -filetype=obj | FileCheck %s
#
-# CHECK: LLVM ERROR: out of range PC16 fixup
+# CHECK: error: out of range PC16 fixup
.text
b foo
Modified: llvm/trunk/test/MC/Mips/mips-diagnostic-fixup.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/Mips/mips-diagnostic-fixup.s?rev=253327&r1=253326&r2=253327&view=diff
==============================================================================
--- llvm/trunk/test/MC/Mips/mips-diagnostic-fixup.s (original)
+++ llvm/trunk/test/MC/Mips/mips-diagnostic-fixup.s Tue Nov 17 03:58:07 2015
@@ -1,6 +1,6 @@
# RUN: not llvm-mc %s -triple=mipsel-unknown-linux -mcpu=mips32r2 -arch=mips 2>&1 -filetype=obj | FileCheck %s
#
-# CHECK: LLVM ERROR: out of range PC16 fixup
+# CHECK: error: out of range PC16 fixup
.text
b foo
More information about the llvm-commits
mailing list