[flang-commits] [flang] [flang][debug] Support derived types. (PR #99476)
via flang-commits
flang-commits at lists.llvm.org
Wed Jul 24 04:09:39 PDT 2024
================
@@ -154,6 +156,58 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertBoxedSequenceType(
dataLocation, /*rank=*/nullptr, allocated, associated);
}
+mlir::LLVM::DITypeAttr DebugTypeGenerator::convertRecordType(
+ fir::RecordType Ty, mlir::LLVM::DIFileAttr fileAttr,
+ mlir::LLVM::DIScopeAttr scope, mlir::Location loc) {
+ mlir::MLIRContext *context = module.getContext();
+ auto result = fir::NameUniquer::deconstruct(Ty.getName());
+ if (result.first != fir::NameUniquer::NameKind::DERIVED_TYPE)
+ return genPlaceholderType(context);
+
+ std::optional<mlir::DataLayout> dl =
+ fir::support::getOrSetDataLayout(module, /*allowDefaultLayout=*/true);
+ if (!dl) {
+ mlir::emitError(module.getLoc(), "Missing data layout attribute in module");
+ return genPlaceholderType(context);
+ }
+ unsigned line = 1;
+ mlir::LLVM::DITypeAttr parentTypeAttr = nullptr;
+ fir::TypeInfoOp tiOp = symbolTable->lookup<fir::TypeInfoOp>(Ty.getName());
+ if (tiOp) {
+ line = getLineFromLoc(tiOp.getLoc());
+ if (fir::RecordType parentTy = tiOp.getIfParentType())
+ parentTypeAttr =
+ convertRecordType(parentTy, fileAttr, scope, tiOp.getLoc());
+ }
+
+ llvm::SmallVector<mlir::LLVM::DINodeAttr> elements;
+ std::uint64_t offset = 0;
+ for (auto [fieldName, fieldTy] : Ty.getTypeList()) {
+ bool success = true;
+ auto [byteSize, byteAlign] =
+ fir::getTypeSizeAndAlignment(loc, fieldTy, *dl, kindMapping, &success);
+ if (!success)
+ return genPlaceholderType(context);
----------------
jinisusan wrote:
fir::getTypeSizeAndAlignment() does not seem to deal with pointer types (as you have mentioned, we still have unsupported types with which we are dealing in an incremental manner). Hence if the derived type has a pointer member in it (as in the example below), a DICompositeType does not get created for that derived type. Not sure if it would make better sense to create a DICompositeType with whatever members we have discovered so far instead of bailing out. This would provide better debuggability than no DIE getting created eventually for the derived type at all.
type dtype
integer :: i
real :: fi
character :: ci
real, pointer :: justaptr
end type dtype
https://github.com/llvm/llvm-project/pull/99476
More information about the flang-commits
mailing list