[Mlir-commits] [mlir] [mlir][tblgen] Suppress deprecation warnings in deprecated create wrappers (PR #234953)
Morris Hafner
llvmlistbot at llvm.org
Fri Oct 23 16:54:06 PDT 2026
https://github.com/mmha updated https://github.com/llvm/llvm-project/pull/234953
>From 0a8673c73ce84eb566506b4e05688807df3faee5 Mon Sep 17 00:00:00 2001
From: Morris Hafner <mmha at users.noreply.github.com>
Date: Fri, 23 Oct 2026 16:01:43 +0200
Subject: [PATCH 1/2] [mlir][tblgen] Suppress deprecation warnings in legacy
create wrappers
MSVC diagnoses deprecated calls inside deprecated functions. Scope warning
suppression to generated legacy create wrapper bodies, preserving diagnostics
for callers that use deprecated APIs.
Validated with MSVC 19.51 under Wine: 226 C4996 warnings across representative
Arith, Func, UB, and LLVM operation translation units drop to zero. An
intentional deprecated API caller still emits its expected warning.
Assisted-by: Codex
---
mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
index 48158b6b148aab..62d057af2132b4 100644
--- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
@@ -2446,13 +2446,25 @@ void OpEmitter::genInlineCreateBody(
nonBuilderStateArgs = ", " + nonBuilderStateArgs;
}
- if (cWithLoc)
+ // MSVC diagnoses deprecated calls even inside deprecated functions.
+ // Keep compatibility wrappers quiet without hiding warnings at call sites.
+ if (cWithLoc) {
+ if (deprecated)
+ cWithLoc->body() << "LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_PUSH\n";
cWithLoc->body() << llvm::formatv(inlineCreateBody, locParamName,
nonBuilderStateArgs,
opClass.getClassName());
- if (cImplicitLoc)
+ if (deprecated)
+ cWithLoc->body() << "LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_POP\n";
+ }
+ if (cImplicitLoc) {
+ if (deprecated)
+ cImplicitLoc->body() << "LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_PUSH\n";
cImplicitLoc->body() << llvm::formatv(inlineCreateBodyImplicitLoc,
nonBuilderStateArgs);
+ if (deprecated)
+ cImplicitLoc->body() << "LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_POP\n";
+ }
}
void OpEmitter::genSeparateArgParamBuilder() {
>From 68a155ad16b7dad9703863deac2eeabfbc049261 Mon Sep 17 00:00:00 2001
From: Morris Hafner <mmha at users.noreply.github.com>
Date: Sat, 24 Oct 2026 01:53:57 +0200
Subject: [PATCH 2/2] Add test
---
mlir/test/mlir-tblgen/op-decl-and-defs.td | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/mlir/test/mlir-tblgen/op-decl-and-defs.td b/mlir/test/mlir-tblgen/op-decl-and-defs.td
index ed398e3319cb8e..5bc9117f450bb1 100644
--- a/mlir/test/mlir-tblgen/op-decl-and-defs.td
+++ b/mlir/test/mlir-tblgen/op-decl-and-defs.td
@@ -166,8 +166,26 @@ def NS_AOp : NS_Op<"a_op", [IsolatedFromAbove, IsolatedFromAbove]> {
// DEFS: ::mlir::detail::appendAttributeProperty(attrs, "attr1", prop.attr1);
// DEFS: void AOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes, unsigned numRegions) {
// DEFS: buildPropertiesAndDiscardableAttributes(odsState, attributes);
+// DEFS: AOp AOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes, unsigned numRegions) {
+// DEFS-NEXT: LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_PUSH
+// DEFS: build(builder, __state__,
+// DEFS: return ::llvm::cast<AOp>(__res__);
+// DEFS-NEXT: LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_POP
+// DEFS-NEXT: }
+// DEFS: AOp AOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes, unsigned numRegions) {
+// DEFS-NEXT: LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_PUSH
+// DEFS: return create(builder, builder.getLoc(),
+// DEFS-NEXT: LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_POP
+// DEFS-NEXT: }
// DEFS: void AOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes, unsigned numRegions) {
// DEFS: odsState.useProperties(const_cast<Properties&>(properties));
+// DEFS: AOp AOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes, unsigned numRegions) {
+// DEFS-NOT: LLVM_SUPPRESS_DEPRECATED_DECLARATIONS
+// DEFS: return ::llvm::cast<AOp>(__res__);
+// DEFS-NEXT: }
+// DEFS: AOp AOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes, unsigned numRegions) {
+// DEFS-NEXT: return create(builder, builder.getLoc(),
+// DEFS-NEXT: }
// DEFS-LABEL: void AOp::buildPropertiesAndDiscardableAttributes
// DEFS: Properties &properties = odsState.getOrAddProperties<Properties>();
// DEFS-NEXT: populateDefaultProperties(odsState.name, properties);
More information about the Mlir-commits
mailing list