[llvm] r230938 - Teach DataLayout that pointer ABI and preferred alignments are required to be powers of two.

Owen Anderson resistor at mac.com
Sun Mar 1 22:33:52 PST 2015


Author: resistor
Date: Mon Mar  2 00:33:51 2015
New Revision: 230938

URL: http://llvm.org/viewvc/llvm-project?rev=230938&view=rev
Log:
Teach DataLayout that pointer ABI and preferred alignments are required to be powers of two.

Previously this resulted in asserts and/or crashes (depending on build configuration) at various phases in the optimizer.

Added:
    llvm/trunk/test/Assembler/invalid-datalayout20.ll
    llvm/trunk/test/Assembler/invalid-datalayout21.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=230938&r1=230937&r2=230938&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DataLayout.cpp (original)
+++ llvm/trunk/lib/IR/DataLayout.cpp Mon Mar  2 00:33:51 2015
@@ -268,12 +268,18 @@ void DataLayout::parseSpecifier(StringRe
             "Missing alignment specification for pointer in datalayout string");
       Split = split(Rest, ':');
       unsigned PointerABIAlign = inBytes(getInt(Tok));
+      if (!isPowerOf2_64(PointerABIAlign))
+        report_fatal_error(
+            "Pointer ABI alignment must be a power of 2");
 
       // Preferred alignment.
       unsigned PointerPrefAlign = PointerABIAlign;
       if (!Rest.empty()) {
         Split = split(Rest, ':');
         PointerPrefAlign = inBytes(getInt(Tok));
+        if (!isPowerOf2_64(PointerPrefAlign))
+          report_fatal_error(
+            "Pointer preferred alignment must be a power of 2");
       }
 
       setPointerAlignment(AddrSpace, PointerABIAlign, PointerPrefAlign,

Added: llvm/trunk/test/Assembler/invalid-datalayout20.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/invalid-datalayout20.ll?rev=230938&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/invalid-datalayout20.ll (added)
+++ llvm/trunk/test/Assembler/invalid-datalayout20.ll Mon Mar  2 00:33:51 2015
@@ -0,0 +1,6 @@
+; RUN: not llvm-as < %s 2>&1 | FileCheck %s
+
+target datalayout = "p:64:24:64"
+
+; CHECK: Pointer ABI alignment must be a power of 2
+

Added: llvm/trunk/test/Assembler/invalid-datalayout21.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/invalid-datalayout21.ll?rev=230938&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/invalid-datalayout21.ll (added)
+++ llvm/trunk/test/Assembler/invalid-datalayout21.ll Mon Mar  2 00:33:51 2015
@@ -0,0 +1,6 @@
+; RUN: not llvm-as < %s 2>&1 | FileCheck %s
+
+target datalayout = "p:64:64:24"
+
+; CHECK: Pointer preferred alignment must be a power of 2
+





More information about the llvm-commits mailing list