diff options
author | Amr Hesham <amr96@programmer.net> | 2025-03-19 21:29:37 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-19 21:29:37 +0100 |
commit | 6aeae62aef63c7c11ab67a880716afdc92ac8422 (patch) | |
tree | 939f61ada1bdb0a6f54f387df48e8d515a2855b2 /clang/lib/CIR/CodeGen/CIRGenModule.cpp | |
parent | a810141281cce5073d9a827a917c34d72bbd62b1 (diff) | |
download | llvm-6aeae62aef63c7c11ab67a880716afdc92ac8422.zip llvm-6aeae62aef63c7c11ab67a880716afdc92ac8422.tar.gz llvm-6aeae62aef63c7c11ab67a880716afdc92ac8422.tar.bz2 |
[CIR] Upstream global initialization for ArrayType (#131657)
This change adds global initialization for ArrayType
Issue #130197
Diffstat (limited to 'clang/lib/CIR/CodeGen/CIRGenModule.cpp')
-rw-r--r-- | clang/lib/CIR/CodeGen/CIRGenModule.cpp | 38 |
1 files changed, 5 insertions, 33 deletions
diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp index 36bfc2c..9776a4e 100644 --- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp @@ -11,6 +11,7 @@ //===----------------------------------------------------------------------===// #include "CIRGenModule.h" +#include "CIRGenConstantEmitter.h" #include "CIRGenFunction.h" #include "clang/AST/ASTContext.h" @@ -128,7 +129,8 @@ void CIRGenModule::emitGlobalFunctionDefinition(clang::GlobalDecl gd, void CIRGenModule::emitGlobalVarDefinition(const clang::VarDecl *vd, bool isTentative) { - mlir::Type type = convertType(vd->getType()); + const QualType astTy = vd->getType(); + const mlir::Type type = convertType(vd->getType()); if (clang::IdentifierInfo *identifier = vd->getIdentifier()) { auto varOp = builder.create<cir::GlobalOp>(getLoc(vd->getSourceRange()), identifier->getName(), type); @@ -141,38 +143,8 @@ void CIRGenModule::emitGlobalVarDefinition(const clang::VarDecl *vd, if (initExpr) { mlir::Attribute initializer; if (APValue *value = initDecl->evaluateValue()) { - switch (value->getKind()) { - case APValue::Int: { - if (mlir::isa<cir::BoolType>(type)) - initializer = - builder.getCIRBoolAttr(value->getInt().getZExtValue()); - else - initializer = builder.getAttr<cir::IntAttr>(type, value->getInt()); - break; - } - case APValue::Float: { - initializer = builder.getAttr<cir::FPAttr>(type, value->getFloat()); - break; - } - case APValue::LValue: { - if (value->getLValueBase()) { - errorNYI(initExpr->getSourceRange(), - "non-null pointer initialization"); - } else { - if (auto ptrType = mlir::dyn_cast<cir::PointerType>(type)) { - initializer = builder.getConstPtrAttr( - ptrType, value->getLValueOffset().getQuantity()); - } else { - llvm_unreachable( - "non-pointer variable initialized with a pointer"); - } - } - break; - } - default: - errorNYI(initExpr->getSourceRange(), "unsupported initializer kind"); - break; - } + ConstantEmitter emitter(*this); + initializer = emitter.tryEmitPrivateForMemory(*value, astTy); } else { errorNYI(initExpr->getSourceRange(), "non-constant initializer"); } |