clangir
clangir copied to clipboard
Pass explicit alignment to globals
ClangIR and Vanilla LLVM have the following diff in the generated IR:
// LLVM-LABEL: @literals
-// LLVM: global %struct.anon {
+// LLVM: global %struct.anon.1 {
// LLVM: [10 x i8] c"1\00\00\00\00\00\00\00\00\00",
// LLVM: [10 x i8] zeroinitializer,
// LLVM: [10 x i8] zeroinitializer
-// LLVM: }, align 1
+// LLVM: }
From langref:
An explicit alignment may be specified for a global, which must be a power of 2. If not present, or if the alignment is set to zero, the alignment of the global is set by the target to whatever it feels convenient. If an explicit alignment is specified, the global is forced to have exactly that alignment.
We should make it explicit to avoid alignment issues in the future.
Originally posted by @ivanmurashko in https://github.com/llvm/clangir/pull/617#discussion_r1612824120