Skip to content

Conversation

@bcardosolopes
Copy link
Member

Fix di_subprogram references to scopes composed of di_derived_types, which currently fail to parse with:

error: failed to parse LLVM_DISubprogramAttr parameter 'scope' which is to be a `DIScopeAttr`

Fix `di_subprogram` references to scopes composed of `di_derived_type`s, which
currently fail to parse with:

```
error: failed to parse LLVM_DISubprogramAttr parameter 'scope' which is to be a `DIScopeAttr`
```
@bcardosolopes bcardosolopes requested review from abidh and gysit and removed request for abidh May 1, 2025 21:06
@llvmbot
Copy link
Member

llvmbot commented May 1, 2025

@llvm/pr-subscribers-mlir-llvm

@llvm/pr-subscribers-mlir

Author: Bruno Cardoso Lopes (bcardosolopes)

Changes

Fix di_subprogram references to scopes composed of di_derived_types, which currently fail to parse with:

error: failed to parse LLVM_DISubprogramAttr parameter 'scope' which is to be a `DIScopeAttr`

Full diff: https://github.com/llvm/llvm-project/pull/138200.diff

2 Files Affected:

  • (modified) mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp (+2-2)
  • (modified) mlir/test/Dialect/LLVMIR/debuginfo.mlir (+19-2)
diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
index ffde597ac83c1..7dccd9d29ecbd 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
@@ -90,8 +90,8 @@ bool DINodeAttr::classof(Attribute attr) {
 
 bool DIScopeAttr::classof(Attribute attr) {
   return llvm::isa<DICommonBlockAttr, DICompileUnitAttr, DICompositeTypeAttr,
-                   DIFileAttr, DILocalScopeAttr, DIModuleAttr, DINamespaceAttr>(
-      attr);
+                   DIDerivedTypeAttr, DIFileAttr, DILocalScopeAttr,
+                   DIModuleAttr, DINamespaceAttr>(attr);
 }
 
 //===----------------------------------------------------------------------===//
diff --git a/mlir/test/Dialect/LLVMIR/debuginfo.mlir b/mlir/test/Dialect/LLVMIR/debuginfo.mlir
index 1147cb110199d..e480d65d956ab 100644
--- a/mlir/test/Dialect/LLVMIR/debuginfo.mlir
+++ b/mlir/test/Dialect/LLVMIR/debuginfo.mlir
@@ -131,6 +131,12 @@
   annotations = #llvm.di_annotation<name = "foo", value = "bar">
 >
 
+// CHECK-DAG: #[[SP3:.*]] = #llvm.di_subprogram<scope = #[[PTR2]], file = #[[FILE]], type = #[[SPTYPE1]]>
+#sp3 = #llvm.di_subprogram<
+  // Omit the optional parameters.
+  scope = #ptr2, file = #file, type = #spType1
+>
+
 // CHECK-DAG: #[[BLOCK0:.*]] = #llvm.di_lexical_block<scope = #[[SP0]], line = 1, column = 2>
 #block0 = #llvm.di_lexical_block<scope = #sp0, line = 1, column = 2>
 
@@ -140,6 +146,9 @@
 // CHECK-DAG: #[[BLOCK2:.*]] = #llvm.di_lexical_block<scope = #[[SP2]]>
 #block2 = #llvm.di_lexical_block<scope = #sp2>
 
+// CHECK-DAG: #[[BLOCK3:.*]] = #llvm.di_lexical_block<scope = #[[SP3]]>
+#block3 = #llvm.di_lexical_block<scope = #sp3>
+
 // CHECK-DAG: #[[VAR0:.*]] = #llvm.di_local_variable<scope = #[[BLOCK0]], name = "alloc", file = #[[FILE]], line = 6, arg = 1, alignInBits = 32, type = #[[INT0]]>
 #var0 = #llvm.di_local_variable<
   scope = #block0, name = "alloc", file = #file,
@@ -158,6 +167,12 @@
   scope = #block2, name = "arg2"
 >
 
+// CHECK-DAG: #[[VAR3:.*]] = #llvm.di_local_variable<scope = #[[BLOCK3]], name = "arg3">
+#var3 = #llvm.di_local_variable<
+  // Omit the optional parameters.
+  scope = #block3, name = "arg3"
+>
+
 // CHECK-DAG: #[[LABEL1:.*]] =  #llvm.di_label<scope = #[[BLOCK1]], name = "label", file = #[[FILE]], line = 42>
 #label1 = #llvm.di_label<scope = #block1, name = "label", file = #file, line = 42>
 
@@ -194,12 +209,14 @@ llvm.func @addr(%arg: i64) {
   llvm.return
 }
 
-// CHECK: llvm.func @value(%[[ARG1:.*]]: i32, %[[ARG2:.*]]: i32)
-llvm.func @value(%arg1: i32, %arg2: i32) {
+// CHECK: llvm.func @value(%[[ARG1:.*]]: i32, %[[ARG2:.*]]: i32, %[[ARG3:.*]]: i32)
+llvm.func @value(%arg1: i32, %arg2: i32, %arg3 : i32) {
   // CHECK: llvm.intr.dbg.value #[[VAR1]] #llvm.di_expression<[DW_OP_LLVM_fragment(16, 8), DW_OP_plus_uconst(2), DW_OP_deref]> = %[[ARG1]]
   llvm.intr.dbg.value #var1 #llvm.di_expression<[DW_OP_LLVM_fragment(16, 8), DW_OP_plus_uconst(2), DW_OP_deref]> = %arg1 : i32
   // CHECK: llvm.intr.dbg.value #[[VAR2]] = %[[ARG2]]
   llvm.intr.dbg.value #var2 = %arg2 : i32
+  // CHECK: llvm.intr.dbg.value #[[VAR3]] = %[[ARG3]]
+  llvm.intr.dbg.value #var3 = %arg3 : i32
   // CHECK: llvm.intr.dbg.label #[[LABEL1]]
   llvm.intr.dbg.label #label1
   // CHECK: llvm.intr.dbg.label #[[LABEL2]]

Copy link
Contributor

@gysit gysit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

LGTM

@bcardosolopes bcardosolopes merged commit 1277837 into llvm:main May 2, 2025
14 checks passed
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
llvm#138200)

Fix `di_subprogram` references to scopes composed of `di_derived_type`s,
which currently fail to parse with:

```
error: failed to parse LLVM_DISubprogramAttr parameter 'scope' which is to be a `DIScopeAttr`
```
GeorgeARM pushed a commit to GeorgeARM/llvm-project that referenced this pull request May 7, 2025
llvm#138200)

Fix `di_subprogram` references to scopes composed of `di_derived_type`s,
which currently fail to parse with:

```
error: failed to parse LLVM_DISubprogramAttr parameter 'scope' which is to be a `DIScopeAttr`
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants