This revision was automatically updated to reflect the committed changes.
Closed by commit rGbcf66084eddd: [DebugInfo] Fix for adding "returns cxx 
udt" option to functions in CodeView. (authored by akhuang).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77436/new/

https://reviews.llvm.org/D77436

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-composite-triviality-fwd-decl.cpp


Index: clang/test/CodeGenCXX/debug-info-composite-triviality-fwd-decl.cpp
===================================================================
--- /dev/null
+++ 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
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===================================================================
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -991,11 +991,21 @@
   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(),


Index: clang/test/CodeGenCXX/debug-info-composite-triviality-fwd-decl.cpp
===================================================================
--- /dev/null
+++ 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
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===================================================================
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -991,11 +991,21 @@
   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(),
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to