[flang-commits] [flang] [mlir] [MLIR][LLVM] Make DISubprogramAttr cyclic (PR #106571)

Abid Qadeer via flang-commits flang-commits at lists.llvm.org
Mon Sep 23 04:16:12 PDT 2024


abidh wrote:

Hi @gysit, @zyx-billy 
I noticed that `DIRecursiveTypeAttrInterface` only works for `DICompositeTypeAttr` if the cyclic reference it contains is of the same type. It does not work if the cyclic dependency is between 2 different type. Consider the following example, it is Fortran code but I guess similar example could be created in C code. The type `t2` contains a reference to type `t1` and vice versa.

```
 type t2
   type(t1), pointer :: p1
 end type
 type t1
   type(t2), pointer :: p2
 end type
```
If `t1` is processed first, the flow looks something like this:
1. We create a `DICompositeTypeAttr` for `t1` with isRecSelf=true
2. We process its members and create type for `t2`
3. 't2' needs type for 't1` and we use the type created in step1.
4. Both types are created. 

The `t1` reference contained inside `t2` is still isRecSelf=true. It will work in the `DebugTranslation.cpp` if we process the `t1` first. The `t1` will already be in `recursiveNodeMap` when `t2` is processed. The place holder reference will be correctly updated. 

But if `t2` is processed first then that reference is not resolved and we hit the `assert(!attr.getIsRecSelf() && "unbound DI recursive self reference");` assertions.

I was wondering if this is a known limitation or is there a workaround this problem?

https://github.com/llvm/llvm-project/pull/106571


More information about the flang-commits mailing list