diff --git a/lib/IR/DataLayout.cpp b/lib/IR/DataLayout.cpp index ab90388fae3..1b9ff3922d1 100644 --- a/lib/IR/DataLayout.cpp +++ b/lib/IR/DataLayout.cpp @@ -378,7 +378,10 @@ void DataLayout::parseSpecifier(StringRef Desc) { } break; case 'S': { // Stack natural alignment. - StackNaturalAlign = MaybeAlign(inBytes(getInt(Tok))); + uint64_t Alignment = inBytes(getInt(Tok)); + if (Alignment != 0 && !llvm::isPowerOf2_64(Alignment)) + report_fatal_error("Alignment is neither 0 nor a power of 2"); + StackNaturalAlign = MaybeAlign(Alignment); break; } case 'F': { @@ -394,7 +397,10 @@ void DataLayout::parseSpecifier(StringRef Desc) { "datalayout string"); } Tok = Tok.substr(1); - FunctionPtrAlign = MaybeAlign(inBytes(getInt(Tok))); + uint64_t Alignment = inBytes(getInt(Tok)); + if (Alignment != 0 && !llvm::isPowerOf2_64(Alignment)) + report_fatal_error("Alignment is neither 0 nor a power of 2"); + FunctionPtrAlign = MaybeAlign(Alignment); break; } case 'P': { // Function address space. diff --git a/test/Assembler/datalayout-invalid-function-ptr-alignment.ll b/test/Assembler/datalayout-invalid-function-ptr-alignment.ll new file mode 100644 index 00000000000..21cd6a6dc78 --- /dev/null +++ b/test/Assembler/datalayout-invalid-function-ptr-alignment.ll @@ -0,0 +1,5 @@ +; RUN: not llvm-as %s 2>&1 | FileCheck %s + +; CHECK: LLVM ERROR: Alignment is neither 0 nor a power of 2 + +target datalayout = "Fi24" diff --git a/test/Assembler/datalayout-invalid-stack-natural-alignment.ll b/test/Assembler/datalayout-invalid-stack-natural-alignment.ll new file mode 100644 index 00000000000..c8d7ba62ab8 --- /dev/null +++ b/test/Assembler/datalayout-invalid-stack-natural-alignment.ll @@ -0,0 +1,5 @@ +; RUN: not llvm-as %s 2>&1 | FileCheck %s + +; CHECK: LLVM ERROR: Alignment is neither 0 nor a power of 2 + +target datalayout = "S24" diff --git a/test/Bitcode/invalid-functionptr-align.ll b/test/Bitcode/invalid-functionptr-align.ll new file mode 100644 index 00000000000..4ff797a4b01 --- /dev/null +++ b/test/Bitcode/invalid-functionptr-align.ll @@ -0,0 +1,5 @@ +; Bitcode with invalid function pointer alignment. + +; RUN: not llvm-dis %s.bc -o - 2>&1 | FileCheck %s + +CHECK: LLVM ERROR: Alignment is neither 0 nor a power of 2 diff --git a/test/Bitcode/invalid-functionptr-align.ll.bc b/test/Bitcode/invalid-functionptr-align.ll.bc new file mode 100644 index 00000000000..38e4ed8f110 Binary files /dev/null and b/test/Bitcode/invalid-functionptr-align.ll.bc differ