Skip to content

[flang][debug] Improve handling of cyclic derived types with classes. #129588

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 4, 2025

Conversation

abidh
Copy link
Contributor

@abidh abidh commented Mar 3, 2025

While checking if a type should be cached or not, we use getDerivedType to peel outer layers and get to the base type. This function did not peel the fir.class which caused the algorithm to fail.

Fixes #128606.

While checking if a type should be cached or not, we use
getDerivedType to peel outer layers to get to the base type. This
function did not peel the `fir.class` which caused the algorithm to
fail.

Fixes llvm#128606.
@abidh abidh requested review from tblah, akuhlens and jeanPerier March 3, 2025 20:34
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:fir-hlfir labels Mar 3, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 3, 2025

@llvm/pr-subscribers-flang-fir-hlfir

Author: Abid Qadeer (abidh)

Changes

While checking if a type should be cached or not, we use getDerivedType to peel outer layers and get to the base type. This function did not peel the fir.class which caused the algorithm to fail.

Fixes #128606.


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

2 Files Affected:

  • (modified) flang/lib/Optimizer/Dialect/FIRType.cpp (+2-1)
  • (added) flang/test/Integration/debug-cyclic-derived-type-4.f90 (+22)
diff --git a/flang/lib/Optimizer/Dialect/FIRType.cpp b/flang/lib/Optimizer/Dialect/FIRType.cpp
index 719cb1b9d75aa..f8fd55c79be12 100644
--- a/flang/lib/Optimizer/Dialect/FIRType.cpp
+++ b/flang/lib/Optimizer/Dialect/FIRType.cpp
@@ -210,7 +210,8 @@ mlir::Type getDerivedType(mlir::Type ty) {
           return seq.getEleTy();
         return p.getEleTy();
       })
-      .Case<fir::BoxType>([](auto p) { return getDerivedType(p.getEleTy()); })
+      .Case<fir::BaseBoxType>(
+          [](auto p) { return getDerivedType(p.getEleTy()); })
       .Default([](mlir::Type t) { return t; });
 }
 
diff --git a/flang/test/Integration/debug-cyclic-derived-type-4.f90 b/flang/test/Integration/debug-cyclic-derived-type-4.f90
new file mode 100644
index 0000000000000..783412e08ba7b
--- /dev/null
+++ b/flang/test/Integration/debug-cyclic-derived-type-4.f90
@@ -0,0 +1,22 @@
+! RUN: %flang_fc1 -emit-llvm -debug-info-kind=standalone %s -o - | FileCheck  %s
+
+! Same as debug-cyclic-derived-type-2.f90 but using class instead of type.
+module m
+ type t2
+   class(t1), pointer :: p1
+ end type
+ type t1
+   class(t2), pointer :: p2
+   integer abc
+ end type
+ type(t1) :: tee1
+end module
+
+program test
+  use m
+  type(t2) :: lc2
+  print *, lc2%p1%abc
+end program test
+
+! CHECK-DAG: DICompositeType(tag: DW_TAG_structure_type, name: "t1"{{.*}})
+! CHECK-DAG: DICompositeType(tag: DW_TAG_structure_type, name: "t2"{{.*}})

Copy link
Contributor

@jeanPerier jeanPerier left a comment

Choose a reason for hiding this comment

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

Makes sense, thanks!

@abidh abidh merged commit e27b8b2 into llvm:main Mar 4, 2025
14 checks passed
jph-13 pushed a commit to jph-13/llvm-project that referenced this pull request Mar 21, 2025
…llvm#129588)

While checking if a type should be cached or not, we use
`getDerivedType` to peel outer layers and get to the base type. This
function did not peel the `fir.class` which caused the algorithm to
fail.

Fixes llvm#128606.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:fir-hlfir flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[flang][debug] Unexpected Assertion `!attr.getIsRecSelf() && "unbound DI recursive self reference"' failure
3 participants