From: Owen Anderson Date: Mon, 2 Mar 2015 06:33:51 +0000 (+0000) Subject: Teach DataLayout that pointer ABI and preferred alignments are required to be powers... X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=ddfdffbb10b3702b1a1e685b1c4e7b7808c222cf;p=oota-llvm.git 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@230938 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/IR/DataLayout.cpp b/lib/IR/DataLayout.cpp index c414e80f410..4eb6d78d381 100644 --- a/lib/IR/DataLayout.cpp +++ b/lib/IR/DataLayout.cpp @@ -268,12 +268,18 @@ void DataLayout::parseSpecifier(StringRef Desc) { "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, diff --git a/test/Assembler/invalid-datalayout20.ll b/test/Assembler/invalid-datalayout20.ll new file mode 100644 index 00000000000..a9ac1d7fe09 --- /dev/null +++ b/test/Assembler/invalid-datalayout20.ll @@ -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 + diff --git a/test/Assembler/invalid-datalayout21.ll b/test/Assembler/invalid-datalayout21.ll new file mode 100644 index 00000000000..a39d1d7a14a --- /dev/null +++ b/test/Assembler/invalid-datalayout21.ll @@ -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 +