[Mlir-commits] [mlir] [MLIR][LLVMIR] Add support for empty global ctor/dtor lists (PR #128969)
Tobias Gysi
llvmlistbot at llvm.org
Thu Feb 27 11:31:15 PST 2025
================
@@ -1071,32 +1071,39 @@ LogicalResult
ModuleImport::convertGlobalCtorsAndDtors(llvm::GlobalVariable *globalVar) {
if (!globalVar->hasInitializer() || !globalVar->hasAppendingLinkage())
return failure();
- auto *initializer =
- dyn_cast<llvm::ConstantArray>(globalVar->getInitializer());
- if (!initializer)
+ llvm::Constant *initializer = globalVar->getInitializer();
+
+ bool knownInit = isa<llvm::ConstantArray>(initializer) ||
+ isa<llvm::ConstantAggregateZero>(initializer);
+ if (!knownInit)
return failure();
SmallVector<Attribute> funcs;
SmallVector<int32_t> priorities;
- for (llvm::Value *operand : initializer->operands()) {
- auto *aggregate = dyn_cast<llvm::ConstantAggregate>(operand);
- if (!aggregate || aggregate->getNumOperands() != 3)
- return failure();
+ if (isa<llvm::ConstantArray>(initializer)) {
----------------
gysit wrote:
I suspect the if is not needed since an aggregate zero probably has an empty operands list (especially since this should be an empty array in this case). However, constants are always a bit tricky so maybe it is better to be conservative here.
https://github.com/llvm/llvm-project/pull/128969
More information about the Mlir-commits
mailing list