[flang-commits] [flang] [flang][debug] Support fixed size character type. (PR #95462)

Abid Qadeer via flang-commits flang-commits at lists.llvm.org
Fri Jun 14 07:02:22 PDT 2024


================
@@ -190,6 +190,33 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertSequenceType(
       /* associated */ nullptr);
 }
 
+mlir::LLVM::DITypeAttr DebugTypeGenerator::convertCharacterType(
+    fir::CharacterType charTy, mlir::LLVM::DIFileAttr fileAttr,
+    mlir::LLVM::DIScopeAttr scope, mlir::Location loc) {
+  mlir::MLIRContext *context = module.getContext();
+  if (!charTy.hasConstantLen())
+    return genPlaceholderType(context);
+
+  // DWARF 5 says the following about the character encoding in 5.1.1.2.
+  // "DW_ATE_ASCII and DW_ATE_UCS specify encodings for the Fortran 2003
+  // string kinds ASCII (ISO/IEC 646:1991) and ISO_10646 (UCS-4 in ISO/IEC
+  // 10646:2000)."
+  unsigned encoding = llvm::dwarf::DW_ATE_ASCII;
+  if (charTy.getFKind() != 1)
+    encoding = llvm::dwarf::DW_ATE_UCS;
+
+  // FIXME: Currently the DIStringType in llvm does not have the option to set
+  // type of the underlying character. This restricts out ability to represent
+  // string with non-default characters. Please see issue #95440 for more
+  // details.
+  return mlir::LLVM::DIStringTypeAttr::get(
+      context, llvm::dwarf::DW_TAG_string_type,
+      mlir::StringAttr::get(context, ""),
----------------
abidh wrote:

It is name of the type. We currently don't give it a name so debugger makes one itself.

```
character(len=20) :: second

(GDB) ptype second
type = character*20
```
If we want, we could pass a different name like "character (kind=1, len=20)" and then debugger will show that instead. 
For most of the types, we are not passing a name at the moment as debugger can mostly generate name from the information passed. For things like derived types, we will have to pass the name.

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


More information about the flang-commits mailing list