[clang] [CIR][NFC] Unify the 'null data member attr' getters (PR #186876)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 16 13:13:41 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Erich Keane (erichkeane)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/186876.diff
4 Files Affected:
- (modified) clang/lib/CIR/CodeGen/CIRGenBuilder.h (-10)
- (modified) clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp (+3-7)
- (modified) clang/lib/CIR/CodeGen/CIRGenModule.cpp (+11)
- (modified) clang/lib/CIR/CodeGen/CIRGenModule.h (+3)
``````````diff
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/186876
More information about the cfe-commits
mailing list