Skip to content

Commit b626e81

Browse files
committed
[CIR][NFC] Decompose emitNullConstant into a attribute version
This will enable handling for records (coming next)
1 parent 445bb50 commit b626e81

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

clang/lib/CIR/CodeGen/CIRGenExprConst.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2094,12 +2094,16 @@ mlir::Attribute ConstantEmitter::tryEmitPrivate(const APValue &Value,
20942094
}
20952095

20962096
mlir::Value CIRGenModule::emitNullConstant(QualType T, mlir::Location loc) {
2097+
return builder.getConstant(loc, emitNullConstant(T));
2098+
}
2099+
2100+
mlir::TypedAttr CIRGenModule::emitNullConstant(QualType T) {
20972101
if (T->getAs<PointerType>()) {
2098-
return builder.getNullPtr(getTypes().convertTypeForMem(T), loc);
2102+
return builder.getConstNullPtrAttr(getTypes().convertTypeForMem(T));
20992103
}
21002104

21012105
if (getTypes().isZeroInitializable(T))
2102-
return builder.getNullValue(getTypes().convertTypeForMem(T), loc);
2106+
return builder.getZeroInitAttr(getTypes().convertTypeForMem(T));
21032107

21042108
if (getASTContext().getAsConstantArrayType(T)) {
21052109
llvm_unreachable("NYI");

clang/lib/CIR/CodeGen/CIRGenModule.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,7 @@ class CIRGenModule : public CIRGenTypeCache {
734734
/// expression of the given type. This is usually, but not always, an LLVM
735735
/// null constant.
736736
mlir::Value emitNullConstant(QualType T, mlir::Location loc);
737+
mlir::TypedAttr emitNullConstant(QualType T);
737738

738739
/// Return a null constant appropriate for zero-initializing a base class with
739740
/// the given type. This is usually, but not always, an LLVM null constant.

0 commit comments

Comments
 (0)