https://github.com/erichkeane created https://github.com/llvm/llvm-project/pull/186876
In preperation of actually lowering data members as fields to a record type, this patch does a minor refactor to make their single current use have a slightly simpler interface. This will prevent us from having to copy/paste this later. Also, this patch removes a pair of now-orphaned builders, instead preferring to use the ones that come from the parent builder type. >From 5c0a1499937d7d486d4e076dcab9ebfd6bc1af20 Mon Sep 17 00:00:00 2001 From: erichkeane <[email protected]> Date: Mon, 16 Mar 2026 13:09:10 -0700 Subject: [PATCH] [CIR][NFC] Unify the 'null data member attr' getters In preperation of actually lowering data members as fields to a record type, this patch does a minor refactor to make their single current use have a slightly simpler interface. This will prevent us from having to copy/paste this later. Also, this patch removes a pair of now-orphaned builders, instead preferring to use the ones that come from the parent builder type. --- clang/lib/CIR/CodeGen/CIRGenBuilder.h | 10 ---------- clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp | 10 +++------- clang/lib/CIR/CodeGen/CIRGenModule.cpp | 11 +++++++++++ clang/lib/CIR/CodeGen/CIRGenModule.h | 3 +++ 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/clang/lib/CIR/CodeGen/CIRGenBuilder.h b/clang/lib/CIR/CodeGen/CIRGenBuilder.h index 8bfdbebb2c51f..b9852b50dbc62 100644 --- a/clang/lib/CIR/CodeGen/CIRGenBuilder.h +++ b/clang/lib/CIR/CodeGen/CIRGenBuilder.h @@ -422,16 +422,6 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy { return getConstantInt(loc, getUInt64Ty(), c); } - /// Create constant nullptr for pointer-to-data-member type ty. - cir::ConstantOp getNullDataMemberPtr(cir::DataMemberType ty, - mlir::Location loc) { - return cir::ConstantOp::create(*this, loc, getNullDataMemberAttr(ty)); - } - - cir::ConstantOp getNullMethodPtr(cir::MethodType ty, mlir::Location loc) { - return cir::ConstantOp::create(*this, loc, getNullMethodAttr(ty)); - } - //===--------------------------------------------------------------------===// // UnaryOp creation helpers //===--------------------------------------------------------------------===// diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp index bef487d95156f..7127a90b84ac3 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp @@ -2232,13 +2232,9 @@ mlir::Value ScalarExprEmitter::VisitCastExpr(CastExpr *ce) { assert(!cir::MissingFeatures::cxxABI()); const MemberPointerType *mpt = ce->getType()->getAs<MemberPointerType>(); - if (mpt->isMemberFunctionPointerType()) { - auto ty = mlir::cast<cir::MethodType>(cgf.convertType(destTy)); - return builder.getNullMethodPtr(ty, cgf.getLoc(subExpr->getExprLoc())); - } - - auto ty = mlir::cast<cir::DataMemberType>(cgf.convertType(destTy)); - return builder.getNullDataMemberPtr(ty, cgf.getLoc(subExpr->getExprLoc())); + mlir::Location loc = cgf.getLoc(subExpr->getExprLoc()); + return cgf.getBuilder().getConstant( + loc, cgf.cgm.emitNullMemberAttr(destTy, mpt)); } case CK_ReinterpretMemberPointer: { diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp index cb931f969a41d..3c36ce8b3d50a 100644 --- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp @@ -1714,6 +1714,17 @@ void CIRGenModule::emitExplicitCastExprType(const ExplicitCastExpr *e, "emitExplicitCastExprType"); } +mlir::TypedAttr CIRGenModule::emitNullMemberAttr(QualType destTy, + const MemberPointerType *mpt) { + if (mpt->isMemberFunctionPointerType()) { + auto ty = mlir::cast<cir::MethodType>(convertType(destTy)); + return builder.getNullMethodAttr(ty); + } + + auto ty = mlir::cast<cir::DataMemberType>(convertType(destTy)); + return builder.getNullDataMemberAttr(ty); +} + mlir::Value CIRGenModule::emitMemberPointerConstant(const UnaryOperator *e) { assert(!cir::MissingFeatures::cxxABI()); diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.h b/clang/lib/CIR/CodeGen/CIRGenModule.h index bef154955b9b6..765a724e7150f 100644 --- a/clang/lib/CIR/CodeGen/CIRGenModule.h +++ b/clang/lib/CIR/CodeGen/CIRGenModule.h @@ -590,6 +590,9 @@ class CIRGenModule : public CIRGenTypeCache { mlir::TypedAttr emitNullConstantForBase(const CXXRecordDecl *record); mlir::Value emitMemberPointerConstant(const UnaryOperator *e); + /// Returns a null attribute to represent either a null method or null data + /// member, depending on the type of mpt. + mlir::TypedAttr emitNullMemberAttr(QualType t, const MemberPointerType *mpt); llvm::StringRef getMangledName(clang::GlobalDecl gd); // This function is to support the OpenACC 'bind' clause, which names an _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
