From c859e73a24cc6a7be15dd219112e80241d8d818d Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Mon, 16 Feb 2015 05:41:53 +0000 Subject: [PATCH] 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 --- lib/IR/DataLayout.cpp | 17 +++++++++++------ test/Assembler/invalid-datalayout15.ll | 3 +++ test/Assembler/invalid-datalayout16.ll | 3 +++ test/Assembler/invalid-datalayout17.ll | 3 +++ 4 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 test/Assembler/invalid-datalayout15.ll create mode 100644 test/Assembler/invalid-datalayout16.ll create mode 100644 test/Assembler/invalid-datalayout17.ll diff --git a/lib/IR/DataLayout.cpp b/lib/IR/DataLayout.cpp index 0dcc8427dcd..d1506b20cff 100644 --- a/lib/IR/DataLayout.cpp +++ b/lib/IR/DataLayout.cpp @@ -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) { diff --git a/test/Assembler/invalid-datalayout15.ll b/test/Assembler/invalid-datalayout15.ll new file mode 100644 index 00000000000..ea240b73fd2 --- /dev/null +++ b/test/Assembler/invalid-datalayout15.ll @@ -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 diff --git a/test/Assembler/invalid-datalayout16.ll b/test/Assembler/invalid-datalayout16.ll new file mode 100644 index 00000000000..0dd1abb629b --- /dev/null +++ b/test/Assembler/invalid-datalayout16.ll @@ -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 diff --git a/test/Assembler/invalid-datalayout17.ll b/test/Assembler/invalid-datalayout17.ll new file mode 100644 index 00000000000..519f5c10ab3 --- /dev/null +++ b/test/Assembler/invalid-datalayout17.ll @@ -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