[llvm] r229354 - DataLayout: Report when the datalayout type alignment/width is too large

David Majnemer david.majnemer at gmail.com
Sun Feb 15 21:41:53 PST 2015


Author: majnemer
Date: Sun Feb 15 23:41:53 2015
New Revision: 229354

URL: http://llvm.org/viewvc/llvm-project?rev=229354&view=rev
Log:
DataLayout: Report when the datalayout type alignment/width is too large

Added:
    llvm/trunk/test/Assembler/invalid-datalayout15.ll
    llvm/trunk/test/Assembler/invalid-datalayout16.ll
    llvm/trunk/test/Assembler/invalid-datalayout17.ll
Modified:
    llvm/trunk/lib/IR/DataLayout.cpp

Modified: llvm/trunk/lib/IR/DataLayout.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DataLayout.cpp?rev=229354&r1=229353&r2=229354&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DataLayout.cpp (original)
+++ llvm/trunk/lib/IR/DataLayout.cpp Sun Feb 15 23:41:53 2015
@@ -312,9 +312,6 @@ void DataLayout::parseSpecifier(StringRe
         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 DataLa
 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) {

Added: llvm/trunk/test/Assembler/invalid-datalayout15.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/invalid-datalayout15.ll?rev=229354&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/invalid-datalayout15.ll (added)
+++ llvm/trunk/test/Assembler/invalid-datalayout15.ll Sun Feb 15 23:41:53 2015
@@ -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

Added: llvm/trunk/test/Assembler/invalid-datalayout16.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/invalid-datalayout16.ll?rev=229354&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/invalid-datalayout16.ll (added)
+++ llvm/trunk/test/Assembler/invalid-datalayout16.ll Sun Feb 15 23:41:53 2015
@@ -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

Added: llvm/trunk/test/Assembler/invalid-datalayout17.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/invalid-datalayout17.ll?rev=229354&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/invalid-datalayout17.ll (added)
+++ llvm/trunk/test/Assembler/invalid-datalayout17.ll Sun Feb 15 23:41:53 2015
@@ -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





More information about the llvm-commits mailing list