[clang] [CIR] Make UndefAttr use AttrBuilderWithInferredContext (PR #136605)
Henrich Lauko via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 22 00:01:35 PDT 2025
https://github.com/xlauko updated https://github.com/llvm/llvm-project/pull/136605
>From ab355262c3a7da4d8089a49d531870bff14d5f8c Mon Sep 17 00:00:00 2001
From: xlauko <xlauko at mail.muni.cz>
Date: Mon, 21 Apr 2025 22:03:35 +0200
Subject: [PATCH] [CIR] Make UndefAttr use AttrBuilderWithInferredContext
---
clang/include/clang/CIR/Dialect/IR/CIRAttrs.td | 7 +++++++
clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp | 4 ++--
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
index 214db1b1caeeb..dfe15a10fa54e 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
@@ -93,6 +93,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/Dialect/IR/CIRMemorySlot.cpp b/clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp
index 9cd5c54e6c19e..fe8a5e7428a81 100644
--- a/clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp
@@ -34,8 +34,8 @@ llvm::SmallVector<MemorySlot> cir::AllocaOp::getPromotableSlots() {
Value cir::AllocaOp::getDefaultValue(const MemorySlot &slot,
OpBuilder &builder) {
- return builder.create<cir::ConstantOp>(
- getLoc(), slot.elemType, builder.getAttr<cir::UndefAttr>(slot.elemType));
+ return builder.create<cir::ConstantOp>(getLoc(), slot.elemType,
+ cir::UndefAttr::get(slot.elemType));
}
void cir::AllocaOp::handleBlockArgument(const MemorySlot &slot,
More information about the cfe-commits
mailing list