Skip to content

Commit

Permalink
Teach DataLayout that alignments on basic types must be powers of two.
Browse files Browse the repository at this point in the history
Fixes assertion failures/crashes on bad datalayout specifications.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@230940 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
resistor committed Mar 2, 2015
1 parent c7292fd commit 8fae284
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/IR/DataLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,10 @@ DataLayout::setAlignment(AlignTypeEnum align_type, unsigned 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 (abi_align != 0 && !isPowerOf2_64(abi_align))
report_fatal_error("Invalid ABI alignment, must be a power of 2");
if (pref_align != 0 && !isPowerOf2_64(pref_align))
report_fatal_error("Invalid preferred alignment, must be a power of 2");

if (pref_align < abi_align)
report_fatal_error(
Expand Down
6 changes: 6 additions & 0 deletions test/Assembler/invalid-datalayout23.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
; RUN: not llvm-as < %s 2>&1 | FileCheck %s

target datalayout = "i32:24:32"

; CHECK: Invalid ABI alignment, must be a power of 2

6 changes: 6 additions & 0 deletions test/Assembler/invalid-datalayout24.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
; RUN: not llvm-as < %s 2>&1 | FileCheck %s

target datalayout = "i32:32:24"

; CHECK: Invalid preferred alignment, must be a power of 2

0 comments on commit 8fae284

Please sign in to comment.