llvm / clangir

A new (MLIR based) high-level IR for clang.
https://clangir.org
Other
308 stars 84 forks source link

Pass explicit alignment to globals #626

Open bcardosolopes opened 1 month ago

bcardosolopes commented 1 month ago

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_