diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst --- a/llvm/docs/LangRef.rst +++ b/llvm/docs/LangRef.rst @@ -2772,6 +2772,8 @@ This specifies the alignment for an integer type of a given bit ````. The value of ```` must be in the range [1,2^23). ```` is optional and defaults to ````. + For ``i8``, the ```` value must equal 8, + that is, ``i8`` must be naturally aligned. ``v:[:]`` This specifies the alignment for a vector type of a given bit ````. The value of ```` must be in the range [1,2^23). @@ -2839,7 +2841,7 @@ same as the default address space. - ``S0`` - natural stack alignment is unspecified - ``i1:8:8`` - i1 is 8-bit (byte) aligned -- ``i8:8:8`` - i8 is 8-bit (byte) aligned +- ``i8:8:8`` - i8 is 8-bit (byte) aligned as mandated - ``i16:16:16`` - i16 is 16-bit aligned - ``i32:32:32`` - i32 is 32-bit aligned - ``i64:32:64`` - i64 has ABI alignment of 32-bits but preferred diff --git a/llvm/lib/IR/DataLayout.cpp b/llvm/lib/IR/DataLayout.cpp --- a/llvm/lib/IR/DataLayout.cpp +++ b/llvm/lib/IR/DataLayout.cpp @@ -406,6 +406,9 @@ return reportError("Invalid ABI alignment, must be a 16bit integer"); if (ABIAlign != 0 && !isPowerOf2_64(ABIAlign)) return reportError("Invalid ABI alignment, must be a power of 2"); + if (AlignType == INTEGER_ALIGN && Size == 8 && ABIAlign != 1) + return reportError( + "Invalid ABI alignment, i8 must be naturally aligned"); // Preferred alignment. unsigned PrefAlign = ABIAlign; diff --git a/llvm/test/Assembler/datalayout-invalid-i8-alignment.ll b/llvm/test/Assembler/datalayout-invalid-i8-alignment.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Assembler/datalayout-invalid-i8-alignment.ll @@ -0,0 +1,5 @@ +; RUN: not llvm-as %s 2>&1 | FileCheck %s + +; CHECK: error: Invalid ABI alignment, i8 must be naturally aligned + +target datalayout = "i8:16"