[PATCH] D153898: [DebugInfo] Enable debug info emission for extern variables in C++

Fangrui Song via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 6 12:59:26 PDT 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rGa9f5119a78aa: [DebugInfo] Enable debug info emission for extern variables in C++ (authored by chiyuze, committed by MaskRay).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153898

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/CodeGen/debug-info-extern-basic.cpp


Index: clang/test/CodeGen/debug-info-extern-basic.cpp
===================================================================
--- /dev/null
+++ clang/test/CodeGen/debug-info-extern-basic.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -x c++ -debug-info-kind=limited -triple bpf-linux-gnu -emit-llvm %s -o - | FileCheck %s
+
+namespace foo {
+
+template <typename T>
+struct S {
+  T x;
+};
+
+extern S<char> s;
+
+int test(void) {
+  return s.x;
+}
+
+}  // namespace foo
+
+// CHECK: distinct !DIGlobalVariable(name: "s", scope: ![[NAMESPACE:[0-9]+]],{{.*}} type: ![[STRUCT_TYPE:[0-9]+]], isLocal: false, isDefinition: false)
+// CHECK: ![[NAMESPACE]] = !DINamespace(name: "foo", scope: null)
+// CHECK: ![[STRUCT_TYPE]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "S<char>",{{.*}}size: 8, flags: DIFlagTypePassByValue, elements: ![[ELEMENT_TYPE:[0-9]+]], templateParams: ![[TEMPLATE_TYPE:[0-9]+]], identifier: "_ZTSN3foo1SIcEE")
+// CHECK: ![[ELEMENT_TYPE]] = !{![[ELEMENT_TYPE:[0-9]+]]}
+// CHECK: ![[ELEMENT_TYPE]] = !DIDerivedType(tag: DW_TAG_member, name: "x",{{.*}} baseType: ![[BASE_TYPE:[0-9]+]], size: 8)
+// CHECK: ![[BASE_TYPE]] = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
+// CHECK: ![[TEMPLATE_TYPE]] = !{![[TEMPLATE_TYPE:[0-9]+]]}
+// CHECK: ![[TEMPLATE_TYPE]] = !DITemplateTypeParameter(name: "T", type: ![[BASE_TYPE]])
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -13780,7 +13780,7 @@
       }
 
       if (Context.getTargetInfo().allowDebugInfoForExternalRef() &&
-          !Var->isInvalidDecl() && !getLangOpts().CPlusPlus)
+          !Var->isInvalidDecl())
         ExternalDeclarations.push_back(Var);
 
       return;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153898.537844.patch
Type: text/x-patch
Size: 1798 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230706/8ae7fc23/attachment.bin>


More information about the cfe-commits mailing list