[flang-commits] [flang] [flang][debug] Support derived types. (PR #99476)
Abid Qadeer via flang-commits
flang-commits at lists.llvm.org
Fri Jul 26 07:38:33 PDT 2024
================
@@ -154,6 +156,59 @@ 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()) {
+ auto result = fir::getTypeSizeAndAlignment(loc, fieldTy, *dl, kindMapping);
+ // If we get a type whose size we can't determine, we will break the loop
+ // and generate the derived type with whatever components we have
+ // assembled thus far.
+ if (!result)
+ break;
+ auto [byteSize, byteAlign] = *result;
+ mlir::LLVM::DITypeAttr elemTy = convertType(fieldTy, fileAttr, scope, loc);
----------------
abidh wrote:
I have added a test for now to make sure we don't crash for such cases. I will handle it when I add support for allocatable components. This is is common issue in C like language so there are ways to handle it.
https://github.com/llvm/llvm-project/pull/99476
More information about the flang-commits
mailing list