From 8fae2845b1aa7c9e83796dfb656f9a74bf846205 Mon Sep 17 00:00:00 2001 From: Owen Anderson Date: Mon, 2 Mar 2015 09:35:03 +0000 Subject: [PATCH] Teach DataLayout that alignments on basic types must be powers of two. 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 --- lib/IR/DataLayout.cpp | 4 ++++ test/Assembler/invalid-datalayout23.ll | 6 ++++++ test/Assembler/invalid-datalayout24.ll | 6 ++++++ 3 files changed, 16 insertions(+) create mode 100644 test/Assembler/invalid-datalayout23.ll create mode 100644 test/Assembler/invalid-datalayout24.ll diff --git a/lib/IR/DataLayout.cpp b/lib/IR/DataLayout.cpp index b6eaf6f2d99..573e904f2ee 100644 --- a/lib/IR/DataLayout.cpp +++ b/lib/IR/DataLayout.cpp @@ -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( diff --git a/test/Assembler/invalid-datalayout23.ll b/test/Assembler/invalid-datalayout23.ll new file mode 100644 index 00000000000..430326327bc --- /dev/null +++ b/test/Assembler/invalid-datalayout23.ll @@ -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 + diff --git a/test/Assembler/invalid-datalayout24.ll b/test/Assembler/invalid-datalayout24.ll new file mode 100644 index 00000000000..616ec64518a --- /dev/null +++ b/test/Assembler/invalid-datalayout24.ll @@ -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 + -- 2.34.1