[clang] bcf6608 - [DebugInfo] Fix for adding "returns cxx udt" option to functions in CodeView.
Amy Huang via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 7 09:10:38 PDT 2020
Author: Amy Huang
Date: 2020-04-07T09:10:27-07:00
New Revision: bcf66084eddd4d3dbe78fc4ed39a347d5d8d57d4
URL: https://github.com/llvm/llvm-project/commit/bcf66084eddd4d3dbe78fc4ed39a347d5d8d57d4
DIFF: https://github.com/llvm/llvm-project/commit/bcf66084eddd4d3dbe78fc4ed39a347d5d8d57d4.diff
LOG: [DebugInfo] Fix for adding "returns cxx udt" option to functions in CodeView.
Summary:
This change adds DIFlagNonTrivial to forward declarations of
DICompositeType. It adds the flag to nontrivial types and types with
unknown triviality.
It fixes adding the "CxxReturnUdt" flag to functions inconsistently,
since it is added based on whether the return type is marked NonTrivial, and
that changes if the return type was a forward declaration.
continues the discussion at https://reviews.llvm.org/D75215
Bug: https://bugs.llvm.org/show_bug.cgi?id=44785
Reviewers: rnk, dblaikie, aprantl
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D77436
Added:
clang/test/CodeGenCXX/debug-info-composite-triviality-fwd-decl.cpp
Modified:
clang/lib/CodeGen/CGDebugInfo.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index 8dc305bbfa8d..74c079b0bd09 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -991,11 +991,21 @@ CGDebugInfo::getOrCreateRecordFwdDecl(const RecordType *Ty,
uint64_t Size = 0;
uint32_t Align = 0;
+ llvm::DINode::DIFlags Flags = llvm::DINode::FlagFwdDecl;
+
+ // Add flag to nontrivial forward declarations. To be consistent with MSVC,
+ // add the flag if a record has no definition because we don't know whether
+ // it will be trivial or not.
+ if (const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD))
+ if (!CXXRD->hasDefinition() ||
+ (CXXRD->hasDefinition() && !CXXRD->isTrivial()))
+ Flags |= llvm::DINode::FlagNonTrivial;
+
// Create the type.
SmallString<256> Identifier = getTypeIdentifier(Ty, CGM, TheCU);
llvm::DICompositeType *RetTy = DBuilder.createReplaceableCompositeType(
- getTagForRecord(RD), RDName, Ctx, DefUnit, Line, 0, Size, Align,
- llvm::DINode::FlagFwdDecl, Identifier);
+ getTagForRecord(RD), RDName, Ctx, DefUnit, Line, 0, Size, Align, Flags,
+ Identifier);
if (CGM.getCodeGenOpts().DebugFwdTemplateParams)
if (auto *TSpecial = dyn_cast<ClassTemplateSpecializationDecl>(RD))
DBuilder.replaceArrays(RetTy, llvm::DINodeArray(),
diff --git a/clang/test/CodeGenCXX/debug-info-composite-triviality-fwd-decl.cpp b/clang/test/CodeGenCXX/debug-info-composite-triviality-fwd-decl.cpp
new file mode 100644
index 000000000000..4bf18279b3d5
--- /dev/null
+++ b/clang/test/CodeGenCXX/debug-info-composite-triviality-fwd-decl.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -emit-llvm -gcodeview -debug-info-kind=limited -x c %s -o - | FileCheck %s --check-prefix CHECK-C
+// RUN: %clang_cc1 -emit-llvm -gcodeview -debug-info-kind=limited -x c++ %s -o - | FileCheck %s --check-prefix CHECK-CXX
+//
+// Test for DIFlagNonTrivial on forward declared DICompositeTypes.
+
+struct Incomplete;
+struct Incomplete (*func_ptr)() = 0;
+// CHECK-C: !DICompositeType({{.*}}name: "Incomplete"
+// CHECK-C-NOT: DIFlagNonTrivial
+// CHECK-CXX: !DICompositeType({{.*}}name: "Incomplete"
+// CHECK-CXX-SAME: DIFlagNonTrivial
More information about the cfe-commits
mailing list