1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-26 12:43:36 +01:00

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.

llvm-svn: 303041
This commit is contained in:
Arnaud A. de Grandmaison 2017-05-15 08:43:27 +00:00
parent bbf2eba3b0
commit 5d50c74fd1
2 changed files with 14 additions and 0 deletions

View File

@ -133,6 +133,11 @@ void MCObjectStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size,
// 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;
}

View File

@ -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