[clang] [CIR] Implement CXXScalarValueInitExpr for ComplexType (PR #147143)
Amr Hesham via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 7 12:53:28 PDT 2025
================
@@ -161,6 +162,17 @@ mlir::Value ComplexExprEmitter::VisitChooseExpr(ChooseExpr *e) {
return Visit(e->getChosenSubExpr());
}
+mlir::Value
+ComplexExprEmitter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *e) {
+ mlir::Location loc = cgf.getLoc(e->getExprLoc());
+ QualType complexElemTy =
+ e->getType()->castAs<clang::ComplexType>()->getElementType();
+ mlir::Type complexElemLLVMTy = cgf.convertType(complexElemTy);
+ mlir::TypedAttr defaultValue = builder.getZeroInitAttr(complexElemLLVMTy);
+ auto complexAttr = cir::ConstComplexAttr::get(defaultValue, defaultValue);
+ return builder.create<cir::ConstantOp>(loc, complexAttr);
----------------
AmrDeveloper wrote:
I used getNullValue, it's nicer and required some changes in `CIRToLLVMConstantOpLowering::matchAndRewrite` because previously we expected the value to be ConstComplexAttr, so I supported ZeroAttr too, I will backport this change after merging
https://github.com/llvm/llvm-project/pull/147143
More information about the cfe-commits
mailing list