clangir
clangir copied to clipboard
Globals: LLVM lowering missing constant attribute
There is a small difference between LLVM-IR code generated by ClangIR and vanilla LLVM.
ClangIR generates (... -fclangir -emit-llvm ...):
@_ZN6compat1bE = weak_odr global i32 2
@compat_use_before_redecl = global ptr @_ZN6compat1bE
@_ZN6compat1aE = weak_odr global i32 1
@_ZN6compat1cE = weak_odr global i32 3
@_ZN6compat1eE = global i32 5
@_ZN6compat1fE = weak_odr global i32 6
@compat_use_after_redecl1 = global ptr @_ZN6compat1cE
@_ZN6compat1dE = linkonce_odr global i32 4
@compat_use_after_redecl2 = global ptr @_ZN6compat1dE
@_ZN6compat1gE = linkonce_odr global i32 7
@compat_use_after_redecl3 = global ptr @_ZN6compat1gE
Vanila LLVM (.. -emit-llvm ...):
@_ZN6compat1bE = weak_odr constant i32 2, comdat, align 4
@compat_use_before_redecl = constant ptr @_ZN6compat1bE, align 8
@_ZN6compat1aE = weak_odr constant i32 1, comdat, align 4
@_ZN6compat1cE = weak_odr constant i32 3, comdat, align 4
@_ZN6compat1eE = constant i32 5, align 4
@_ZN6compat1fE = weak_odr constant i32 6, comdat, align 4
@compat_use_after_redecl1 = constant ptr @_ZN6compat1cE, align 8
@_ZN6compat1dE = linkonce_odr constant i32 4, comdat, align 4
@compat_use_after_redecl2 = constant ptr @_ZN6compat1dE, align 8
@_ZN6compat1gE = linkonce_odr constant i32 7, comdat, align 4
@compat_use_after_redecl3 = constant ptr @_ZN6compat1gE, align 8
I.e. some align and constant were added by the vanilla LLVM. @bcardosolopes, is it OK?
Originally posted by @ivanmurashko in https://github.com/llvm/clangir/pull/794#discussion_r1727380963
cc: @ghehg
acknowledged, will take a look today and tomorrow.
@ghehg thanks for fixing the alignment part.
@luismarques the "constant" part of the work here should be a good start, @ghehg is going to look at comdat stuff soon
Seems like comdat part is done? @ghehg is there anything missing? Re-titling to cover for remaining constant.
yes, PR885 fixed the comdat issue here, and updated the exact test case. Alignment was fixed by https://github.com/llvm/clangir/pull/810 So, yes only remaining part is constant attr