[flang-commits] [flang] [flang][debug] Handle allocatable strings. (PR #95906)
via flang-commits
flang-commits at lists.llvm.org
Tue Jun 18 07:58:15 PDT 2024
================
@@ -205,16 +205,38 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertCharacterType(
if (charTy.getFKind() != 1)
encoding = llvm::dwarf::DW_ATE_UCS;
+ uint64_t sizeInBits = 0;
+ mlir::LLVM::DIExpressionAttr lenExpr = nullptr;
+ mlir::LLVM::DIExpressionAttr locExpr = nullptr;
+
+ if (allocatable) {
+ llvm::SmallVector<mlir::LLVM::DIExpressionElemAttr> ops;
+ auto addOp = [&](unsigned opc, llvm::ArrayRef<uint64_t> vals) {
+ ops.push_back(mlir::LLVM::DIExpressionElemAttr::get(context, opc, vals));
+ };
+ addOp(llvm::dwarf::DW_OP_push_object_address, {});
+ addOp(llvm::dwarf::DW_OP_plus_uconst, {lenOffset});
+ lenExpr = mlir::LLVM::DIExpressionAttr::get(context, ops);
+ ops.clear();
+
+ addOp(llvm::dwarf::DW_OP_push_object_address, {});
+ addOp(llvm::dwarf::DW_OP_deref, {});
+ locExpr = mlir::LLVM::DIExpressionAttr::get(context, ops);
+ } else if (charTy.hasConstantLen()) {
----------------
jeanPerier wrote:
Technically, I think it would be valid to fall here first. Allocatable may have non deferred length parameter.
For instance:
```
module m
character(len=16), allocatable :: str2
end module
use m
str2 = "hello" ! still length 16, padding is added.
end
```
It is still valid to read the descriptor that should also contain 16, but maybe it makes more sense to give the simpler description without a DIExpressionAttr. Do you know which DWARF must be generated here?
https://github.com/llvm/llvm-project/pull/95906
More information about the flang-commits
mailing list