From aaf1a96408b1587b5fb80a3a7c424348cb09e577 Mon Sep 17 00:00:00 2001 From: Amy Huang Date: Thu, 3 Sep 2020 15:42:27 -0700 Subject: [PATCH] [DebugInfo] Add size to class declarations in debug info. This adds the size to forward declared class DITypes, if the size is known. Fixes an issue where we determine whether to emit fragments based on the type size, so fragments would sometimes be incorrectly emitted if there was no size. Bug: https://bugs.llvm.org/show_bug.cgi?id=47338 Differential Revision: https://reviews.llvm.org/D87062 --- clang/lib/CodeGen/CGDebugInfo.cpp | 4 ++++ clang/test/CodeGenCXX/debug-info-class.cpp | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 8a85a24910e4..1fdb6814c7bd 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -1031,6 +1031,10 @@ CGDebugInfo::getOrCreateRecordFwdDecl(const RecordType *Ty, uint64_t Size = 0; uint32_t Align = 0; + const RecordDecl *D = RD->getDefinition(); + if (D && D->isCompleteDefinition()) + Size = CGM.getContext().getTypeSize(Ty); + llvm::DINode::DIFlags Flags = llvm::DINode::FlagFwdDecl; // Add flag to nontrivial forward declarations. To be consistent with MSVC, diff --git a/clang/test/CodeGenCXX/debug-info-class.cpp b/clang/test/CodeGenCXX/debug-info-class.cpp index 94d5a0f1f082..e000532b8c3b 100644 --- a/clang/test/CodeGenCXX/debug-info-class.cpp +++ b/clang/test/CodeGenCXX/debug-info-class.cpp @@ -136,7 +136,7 @@ int main(int argc, char **argv) { // CHECK: [[C_DTOR]] = !DISubprogram(name: "~C" // CHECK: [[D:![0-9]+]] = !DICompositeType(tag: DW_TAG_structure_type, name: "D" -// CHECK-NOT: size: +// CHECK-SAME: size: // CHECK-SAME: DIFlagFwdDecl // CHECK-NOT: identifier: // CHECK-SAME: ){{$}}