LLVM IR allows globals with external linkage to have initializers, including
undef. The translation was incorrectly using undef as a indicator that the
initializer should be ignored in translation, leading to the impossibility to
create an external global with an explicit undef initializer. Fix this and use
nullptr as a marker instead.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
mlir/lib/Target/LLVMIR/ModuleTranslation.cpp | ||
---|---|---|
455 | This comment isn't 100% correct. My understanding of the LLVM semantics is that for an external linkage variable if you have an initializer the symbol is externally visible and defined within the module, if you do not have an initializer the symbol is defined in another translation unit and available here. As such I don't think we should be assigning the initializer by default (since the explicit inclusion or omission of the initializer is what defines the semantics). | |
mlir/test/Target/LLVMIR/llvmir.mlir | ||
38 | Per earlier comment I would also add a test which explicitly doesn't have an initializer in mlir and ensure it does not in llvm either. |
mlir/lib/Target/LLVMIR/ModuleTranslation.cpp | ||
---|---|---|
455 | Ignore my previous comment about not assigning undef by default, rereading this it should only occur for non-external variables. The comment here is fine, but I may recommend adding to the comment for shouldDropGlobalInitializer with the previous explanation. | |
mlir/test/Target/LLVMIR/llvmir.mlir | ||
38 | Ignore this comment, I'm seeing this behavior checked on line 78. |
This comment isn't 100% correct. My understanding of the LLVM semantics is that for an external linkage variable if you have an initializer the symbol is externally visible and defined within the module, if you do not have an initializer the symbol is defined in another translation unit and available here.
As such I don't think we should be assigning the initializer by default (since the explicit inclusion or omission of the initializer is what defines the semantics).