[Mlir-commits] [mlir] ecb50ab - [MLIR][LLVM] Reject distinct generic metadata on import (#212455)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sat Aug 1 06:06:01 PDT 2026
Author: Akimasa Watanuki
Date: 2026-08-01T22:05:56+09:00
New Revision: ecb50ab04f9b11a71fb672e18060d557d9fa9343
URL: https://github.com/llvm/llvm-project/commit/ecb50ab04f9b11a71fb672e18060d557d9fa9343
DIFF: https://github.com/llvm/llvm-project/commit/ecb50ab04f9b11a71fb672e18060d557d9fa9343.diff
LOG: [MLIR][LLVM] Reject distinct generic metadata on import (#212455)
Reject distinct nodes when converting generic LLVM metadata into LLVM
dialect attributes because `MDNodeAttr` cannot preserve node identity.
Apply the policy recursively so top-level and nested nodes use the
existing unsupported-metadata failure path while finite acyclic uniqued
nodes remain importable.
Added:
Modified:
mlir/lib/Target/LLVMIR/ModuleImport.cpp
mlir/test/Target/LLVMIR/Import/import-failure.ll
Removed:
################################################################################
diff --git a/mlir/lib/Target/LLVMIR/ModuleImport.cpp b/mlir/lib/Target/LLVMIR/ModuleImport.cpp
index bb55678f91005..595dfa6b8dd7a 100644
--- a/mlir/lib/Target/LLVMIR/ModuleImport.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleImport.cpp
@@ -181,6 +181,9 @@ static Attribute convertMetadataToAttrImpl(
return MDFuncAttr::get(ctx, FlatSymbolRefAttr::get(ctx, fn->getName()));
}
if (auto *node = dyn_cast<llvm::MDNode>(md)) {
+ // Metadata attributes cannot preserve distinctness, so bail out.
+ if (node->isDistinct())
+ return {};
if (Attribute cached = attrMap.lookup(node))
return cached;
// If `node` is already on the current search path, this is a back-edge into
@@ -206,8 +209,9 @@ static Attribute convertMetadataToAttrImpl(
/// Converts the metadata node `md` to the matching LLVM dialect metadata
/// attribute. Returns a null attribute for shapes that the dialect's
-/// metadata-attribute hierarchy does not currently model, including cyclic
-/// metadata graphs that the immutable metadata attributes cannot express.
+/// metadata-attribute hierarchy does not currently model, including distinct
+/// nodes and cyclic metadata graphs that the immutable metadata attributes
+/// cannot express.
static Attribute convertMetadataToAttr(MLIRContext *ctx,
const llvm::Metadata *md) {
SmallPtrSet<const llvm::Metadata *, 8> path;
diff --git a/mlir/test/Target/LLVMIR/Import/import-failure.ll b/mlir/test/Target/LLVMIR/Import/import-failure.ll
index 57c8438bfd362..564fbf4d3df68 100644
--- a/mlir/test/Target/LLVMIR/Import/import-failure.ll
+++ b/mlir/test/Target/LLVMIR/Import/import-failure.ll
@@ -459,6 +459,31 @@ bb1:
; // -----
+; CHECK: error: unsupported metadata: !{{[0-9]+}} = distinct !{!"sp"}
+declare i32 @llvm.read_register.i32(metadata)
+
+define i32 @distinct_metadata_as_value() {
+ %r = call i32 @llvm.read_register.i32(metadata !0)
+ ret i32 %r
+}
+
+!0 = distinct !{!"sp"}
+
+; // -----
+
+; CHECK: error: unsupported metadata: !{{[0-9]+}} = !{!{{[0-9]+}}}
+declare i32 @llvm.read_register.i32(metadata)
+
+define i32 @nested_distinct_metadata_as_value() {
+ %r = call i32 @llvm.read_register.i32(metadata !0)
+ ret i32 %r
+}
+
+!0 = !{!1}
+!1 = distinct !{!"sp"}
+
+; // -----
+
; CHECK: error: unsupported metadata: !{{[0-9]+}} = distinct !{!{{[0-9]+}}}
declare i32 @llvm.read_register.i32(metadata)
More information about the Mlir-commits
mailing list