[llvm] r303041 - MCObjectStreamer : fail with a diagnostic when emitting an out of range value.
Arnaud A. de Grandmaison via llvm-commits
llvm-commits at lists.llvm.org
Mon May 15 01:43:28 PDT 2017
Author: aadg
Date: Mon May 15 03:43:27 2017
New Revision: 303041
URL: http://llvm.org/viewvc/llvm-project?rev=303041&view=rev
Log:
MCObjectStreamer : fail with a diagnostic when emitting an out of range value.
We were previously silently emitting bogus data in release mode,
making it very hard to diagnose the error, or crashing with an
assert in debug mode. A proper diagnostic is now always emitted
when the value to be emitted is out of range.
Modified:
llvm/trunk/lib/MC/MCObjectStreamer.cpp
llvm/trunk/test/MC/AArch64/label-arithmetic-diags-elf.s
Modified: llvm/trunk/lib/MC/MCObjectStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCObjectStreamer.cpp?rev=303041&r1=303040&r2=303041&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCObjectStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCObjectStreamer.cpp Mon May 15 03:43:27 2017
@@ -133,6 +133,11 @@ void MCObjectStreamer::EmitValueImpl(con
// Avoid fixups when possible.
int64_t AbsValue;
if (Value->evaluateAsAbsolute(AbsValue, getAssembler())) {
+ if (!isUIntN(8 * Size, AbsValue) && !isIntN(8 * Size, AbsValue)) {
+ getContext().reportError(
+ Loc, "value evaluated as " + Twine(AbsValue) + " is out of range.");
+ return;
+ }
EmitIntValue(AbsValue, Size);
return;
}
Modified: llvm/trunk/test/MC/AArch64/label-arithmetic-diags-elf.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AArch64/label-arithmetic-diags-elf.s?rev=303041&r1=303040&r2=303041&view=diff
==============================================================================
--- llvm/trunk/test/MC/AArch64/label-arithmetic-diags-elf.s (original)
+++ llvm/trunk/test/MC/AArch64/label-arithmetic-diags-elf.s Mon May 15 03:43:27 2017
@@ -1,5 +1,14 @@
// RUN: not llvm-mc -triple aarch64-elf -filetype=obj %s -o /dev/null 2>&1 | FileCheck %s
+ .data
+b:
+ .fill 300
+e:
+ .byte e - b
+ // CHECK: error: value evaluated as 300 is out of range.
+ // CHECK-NEXT: .byte e - b
+ // CHECK-NEXT: ^
+
.section sec_x
start:
.space 5000
More information about the llvm-commits
mailing list