[flang-commits] [flang] [flang][debug] Handle allocatable strings. (PR #95906)

Abid Qadeer via flang-commits flang-commits at lists.llvm.org
Wed Jun 19 03:38:25 PDT 2024


================
@@ -192,10 +194,8 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertSequenceType(
 
 mlir::LLVM::DITypeAttr DebugTypeGenerator::convertCharacterType(
     fir::CharacterType charTy, mlir::LLVM::DIFileAttr fileAttr,
-    mlir::LLVM::DIScopeAttr scope, mlir::Location loc) {
+    mlir::LLVM::DIScopeAttr scope, mlir::Location loc, bool allocatable) {
----------------
abidh wrote:

That is good observation. I have fixed the name.

A question unrelated to this PR. You mentioned assumed shape character array. Do you mean something like `str` in the `ff` below. I have been working on it and it had to follow `typeparams` on `fircg.ext_declare` to get the length. Essentially I create an artificial variable in debug info which will point to 2nd result of `unboxchar` and tell dwarf that this variable contains the length of the string. The length of the string in `DIStringType` can be described by an integer, an expression or a variable. 

I was wondering if my approach to get length of the string in this case seems right to you?

```
program test
  character(len=20) :: first;
  first="Hello World!"
  call ff(first)
contains
  subroutine ff(str)
    character(len=*) :: str
    str="Bye"
   print *, str
  end subroutine ff
end program test

func.func private @_QFPff(%arg0: !fir.ref<!fir.char<1,?>> {fir.bindc_name = "str"}, %arg1: i64 )  {
    %0 = fir.emboxchar %arg0, %arg1 : (!fir.ref<!fir.char<1,?>>, i64) -> !fir.boxchar<1>
    %1 = fir.undefined !fir.dscope
    %2:2 = fir.unboxchar %0 : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1,?>>, index)
    %3 = fircg.ext_declare %2#0 typeparams %2#1 dummy_scope %1 {uniq_name = "_QFFffEstr"} : (!fir.ref<!fir.char<1,?>>, index, !fir.dscope) -> !fir.ref<!fir.char<1,?>> loc(#loc8)
...
}```

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


More information about the flang-commits mailing list