[Mlir-commits] [mlir] [MLIR] Fix duplicated attribute nodes in MLIR bytecode deserialization (PR #151267)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Jul 31 17:59:49 PDT 2025
================
@@ -0,0 +1,32 @@
+// RUN: mlir-opt -emit-bytecode %s | mlir-translate --mlir-to-llvmir | FileCheck %s
+
+#di_basic_type = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "int", sizeInBits = 32, encoding = DW_ATE_signed>
+#di_file = #llvm.di_file<"foo.c" in "/mlir/">
+#di_file1 = #llvm.di_file<"foo.c" in "/mlir/">
+#di_subprogram = #llvm.di_subprogram<recId = distinct[0]<>, isRecSelf = true>
+#di_compile_unit = #llvm.di_compile_unit<id = distinct[1]<>, sourceLanguage = DW_LANG_C11, file = #di_file, producer = "MLIR", isOptimized = true, emissionKind = Full, nameTableKind = None>
+#di_local_variable = #llvm.di_local_variable<scope = #di_subprogram, name = "a", file = #di_file1, line = 2, type = #di_basic_type>
+#di_subroutine_type = #llvm.di_subroutine_type<types = #di_basic_type>
+#di_subprogram1 = #llvm.di_subprogram<recId = distinct[0]<>, id = distinct[2]<>, compileUnit = #di_compile_unit, scope = #di_file1, name = "main", file = #di_file1, line = 1, scopeLine = 1, subprogramFlags = "Definition|Optimized", type = #di_subroutine_type, retainedNodes = #di_local_variable>
+#di_local_variable1 = #llvm.di_local_variable<scope = #di_subprogram1, name = "a", file = #di_file1, line = 2, type = #di_basic_type>
+
+module attributes {dlti.dl_spec = #dlti.dl_spec<i64 = dense<64> : vector<2xi64>, !llvm.ptr = dense<64> : vector<4xi64>>, llvm.ident = "MLIR", llvm.target_triple = "x86_64-unknown-linux-gnu"} {
----------------
hankluo6 wrote:
>Can we check this as a round-tripping to MLIR targeted kind of test (with minimal attribute to show the discrepancy) instead of involving a translation to LLVM IR and relying on the specific of DI.
The issue is only reproducible during `mlir-translate` from MLIR bytecode to LLVM IR, because that’s the only place where the LLVM IR verifier checks that two `DISubprogram` attributes refer to the same object:
https://github.com/llvm/llvm-project/blob/68b9bb5e9bc3dcd5ff33fe250184debd3cc3dff5/llvm/lib/IR/Verifier.cpp#L6936-L6945
`mlir-opt` will create multiple identical attribute objects with the same content, and since it doesn't check whether they're the exact same object, no error is triggered.
>However I'm not sure I understand exactly what triggers the issue, is this specific to the implementation of the LLVM attributes? Can we reproduce this with one of the test dialect attributes and simplify this further?
This is a potential issue for attributes in general: when parsing MLIR bytecode, the parser creates separate attribute instances even if they are logically equal. That isn't a problem usually if we care only about the content, but when we expect the objects should be the same as in the above case, it can lead to issues. We can't reproduce it with other dialects using `mlir-translate` or `mlir-opt` since there is no such checking.
Since the problem only happens in `mlir-translate` when translating to LLVM IR, I’m not sure what the test should be. Should I put it under `mlir/test/mlir-translate` instead? Thanks!
https://github.com/llvm/llvm-project/pull/151267
More information about the Mlir-commits
mailing list