Skip to content

Conversation

@valerydmit
Copy link
Contributor

@valerydmit valerydmit commented Nov 22, 2025

show_descriptor intrinsic prints details of a descriptor (extended Fortran pointer).
It accepts a descriptor for any type and rank, including scalars.
Requires use of flang_debug module.

Example:
program test
use flang_debug
implicit none
integer :: a(4) = (/ 1,3,5,7 /)
call show_descriptor(a(1:3))
end program test

and its output:
Descriptor @ 0x7ffe01ec6a98:
base_addr 0x563b7035103c
elem_len 4
version 20240719
rank 1
type 9 "INTEGER(kind=4)"
attribute 0
extra 0
addendum 0
alloc_idx 0
dim[0] lower_bound 1
extent 3
sm 4

@github-actions
Copy link

github-actions bot commented Nov 22, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@valerydmit
Copy link
Contributor Author

valerydmit commented Nov 22, 2025

Output examples:

Descriptor @ 0x7ffcec05b7e8:
  base_addr 0x555f2bf9e070
  elem_len  4
  version   20240719
  scalar
  type      27 "REAL(kind=4)"
  attribute 0
  extra     0
    addendum  0
    alloc_idx 0
Descriptor @ 0x7ffcec05b7b8:
  base_addr 0x555f2bf9e074
  elem_len  4
  version   20240719
  rank      1
  type      27 "REAL(kind=4)"
  attribute 0
  extra     0
    addendum  0
    alloc_idx 0
  dim[0] lower_bound 1
         extent      3
         sm          4
Descriptor @ 0x7ffcec05b758:
  base_addr 0x555f2bf9e0a0
  elem_len  8
  version   20240719
  rank      1
  type      34 "COMPLEX(kind=4)"
  attribute 0
  extra     0
    addendum  0
    alloc_idx 0
  dim[0] lower_bound 1
         extent      2
         sm          8
Descriptor @ 0x7ffcec05b758:
  base_addr 0x555f2bf9e0b0
  elem_len  12
  version   20240719
  scalar
  type      42 "DERIVED"
  attribute 0
  extra     1
    addendum  1
    alloc_idx 0
  derivedType @ 0x555f2bf9d980

@github-actions
Copy link

github-actions bot commented Nov 22, 2025

🐧 Linux x64 Test Results

  • 4085 tests passed
  • 202 tests skipped

}

void Descriptor::Dump(FILE *f) const {
static const char *GetTypeStr(ISO::CFI_type_t type, bool dumpRawType) {
Copy link
Member

Choose a reason for hiding this comment

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

StringRef instead if const char*?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using llvm::StringRef would be a precedent for flang-rt.

Copy link
Contributor

@vzakhari vzakhari left a comment

Choose a reason for hiding this comment

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

Thank you, Valery! It looks good to me.

I have one question inlined. Can you please also add unit tests into flang-rt/unittests/Runtime/?

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.

Thanks for adding this, just some high level feedback:

I think I would slightly favor it being defined in an interface in some new intrinsic flang_debug module for better control/error messages when people are switching between compilers (@klausler for opinions).

I understand that defining it fully via Fortran without some interception in semantics is likely hard (probably require some combo of IGNORE_TKR).

However, maybe defining it via renaming to a builtin is an option (see how this is done for __builtin_c_loc for instance).

Second point is that POINTER/ALLOCATABLE descriptors will print the address of a copy (because of the fir.load) and I think it may be useful to get the real address for those. However, this can easily be improved later by updating lowering (adding an entry point if needed to satisfy FIR type between fir.box and fir.ref<fir.box>) and is not a blocking point.

@eugeneepshteyn
Copy link
Contributor

@valerydmit
Copy link
Contributor Author

Thank you for all your inputs. I tried to address all the raised concerns (except handling pointer/allocatable, which I'd like to do in a follow up patch).

Copy link
Contributor

@vzakhari vzakhari left a comment

Choose a reason for hiding this comment

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

Thank you for the tests, Valery!

It LGTM, but please let Jean review the lowering part.

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.

Nit on the test, LGTM otherwise, thanks for the update.

! CHECK: %[[LOAD_1:.*]] = fir.load %[[DECLARE_0]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>
! CHECK: fir.call @_FortranAShowDescriptor(%[[LOAD_1]]) fastmath<contract> : (!fir.box<!fir.heap<!fir.array<?xi32>>>) -> ()

call __builtin_show_descriptor(a(1:3))
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you update the test to do use flang_debug and use show_descriptor?

User should not use the flang __builtin directly, and it would be good if the test also exercise the new module (I think bcc should pick the intrinsic modules, if it does not you can update the test to use flang_fc1).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Thanks

@valerydmit valerydmit marked this pull request as ready for review November 26, 2025 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants