DataLayout: Report when the datalayout type alignment/width is too large

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229354 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
David Majnemer 2015-02-16 05:41:53 +00:00
parent 6de0a12927
commit c859e73a24
4 changed files with 20 additions and 6 deletions

View File

@ -312,9 +312,6 @@ void DataLayout::parseSpecifier(StringRef Desc) {
PrefAlign = inBytes(getInt(Tok));
}
if (ABIAlign > PrefAlign)
report_fatal_error(
"Preferred alignment cannot be less than the ABI alignment");
setAlignment(AlignType, ABIAlign, PrefAlign, Size);
break;
@ -391,9 +388,17 @@ bool DataLayout::operator==(const DataLayout &Other) const {
void
DataLayout::setAlignment(AlignTypeEnum align_type, unsigned abi_align,
unsigned pref_align, uint32_t bit_width) {
assert(abi_align <= pref_align && "Preferred alignment worse than ABI!");
assert(pref_align < (1 << 16) && "Alignment doesn't fit in bitfield");
assert(bit_width < (1 << 24) && "Bit width doesn't fit in bitfield");
if (!isUInt<24>(bit_width))
report_fatal_error("Invalid bit width, must be a 24bit integer");
if (!isUInt<16>(abi_align))
report_fatal_error("Invalid ABI alignment, must be a 16bit integer");
if (!isUInt<16>(pref_align))
report_fatal_error("Invalid preferred alignment, must be a 16bit integer");
if (pref_align < abi_align)
report_fatal_error(
"Preferred alignment cannot be less than the ABI alignment");
for (LayoutAlignElem &Elem : Alignments) {
if (Elem.AlignType == (unsigned)align_type &&
Elem.TypeBitWidth == bit_width) {

View File

@ -0,0 +1,3 @@
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "i64:16:16777216"
; CHECK: Invalid preferred alignment, must be a 16bit integer

View File

@ -0,0 +1,3 @@
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "i64:16777216:16777216"
; CHECK: Invalid ABI alignment, must be a 16bit integer

View File

@ -0,0 +1,3 @@
; RUN: not llvm-as < %s 2>&1 | FileCheck %s
target datalayout = "i16777216:16:16"
; CHECK: Invalid bit width, must be a 24bit integer