diff --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td index e295f7fc57bc..d922f0c2acd5 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td +++ b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td @@ -246,6 +246,13 @@ def UndefAttr : CIR_Attr<"Undef", "undef", [TypedAttrInterface]> { }]; let parameters = (ins AttributeSelfTypeParameter<"">:$type); + + let builders = [ + AttrBuilderWithInferredContext<(ins "mlir::Type":$type), [{ + return $_get(type.getContext(), type); + }]> + ]; + let assemblyFormat = [{}]; } diff --git a/clang/lib/CIR/CodeGen/CIRGenExprConst.cpp b/clang/lib/CIR/CodeGen/CIRGenExprConst.cpp index c05a9099c95b..50a76bc69951 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprConst.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprConst.cpp @@ -353,7 +353,7 @@ mlir::Attribute ConstantAggregateBuilder::buildFrom( ConstantAggregateBuilderUtils Utils(CGM); if (Elems.empty()) - return cir::UndefAttr::get(CGM.getBuilder().getContext(), DesiredTy); + return cir::UndefAttr::get(DesiredTy); auto Offset = [&](size_t I) { return Offsets[I] - StartOffset; }; diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp index a63efce20967..1a33133988fc 100644 --- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp @@ -1413,7 +1413,7 @@ void CIRGenModule::emitGlobalVarDefinition(const clang::VarDecl *d, d->getType()->isCUDADeviceBuiltinTextureType()); if (getLangOpts().CUDA && (isCudaSharedVar || isCudaShadowVar || isCudaDeviceShadowVar)) - init = UndefAttr::get(&getMLIRContext(), convertType(d->getType())); + init = cir::UndefAttr::get(convertType(d->getType())); else if (d->hasAttr()) assert(0 && "not implemented"); else if (!initExpr) { diff --git a/clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp b/clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp index 2b0888920ebe..a21ee0921fbb 100644 --- a/clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp +++ b/clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp @@ -43,8 +43,8 @@ llvm::SmallVector cir::AllocaOp::getPromotableSlots() { Value cir::AllocaOp::getDefaultValue(const MemorySlot &slot, OpBuilder &builder) { - return builder.create( - getLoc(), slot.elemType, builder.getAttr(slot.elemType)); + return builder.create(getLoc(), slot.elemType, + cir::UndefAttr::get(slot.elemType)); } void cir::AllocaOp::handleBlockArgument(const MemorySlot &slot,