[clang] a9f5119 - [DebugInfo] Enable debug info emission for extern variables in C++

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


Author: Yuze Chi
Date: 2023-07-06T12:59:05-07:00
New Revision: a9f5119a78aaa1fc63347a89aee50922bbb8c99c

URL: https://github.com/llvm/llvm-project/commit/a9f5119a78aaa1fc63347a89aee50922bbb8c99c
DIFF: https://github.com/llvm/llvm-project/commit/a9f5119a78aaa1fc63347a89aee50922bbb8c99c.diff

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

Debug info emission for extern variables in C++ was previously disabled
when the functionality was added in https://reviews.llvm.org/D71818 and
originally in https://reviews.llvm.org/D70696, because there was no use
case. We are enabling it now, as we start to deploy BPF programs
compiled from C++, leveraging C++ features like templates to reduce code
complexity. This patch is required so that we can still use kconfig in
such BPF programs compiled from C++.

Reviewed By: rnk, dblaikie, MaskRay, yonghong-song

Differential Revision: https://reviews.llvm.org/D153898

Added: 
    clang/test/CodeGen/debug-info-extern-basic.cpp

Modified: 
    clang/lib/Sema/SemaDecl.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 9e54b6c3ed0b32..e3cbcd6795ea66 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -13780,7 +13780,7 @@ void Sema::ActOnUninitializedDecl(Decl *RealDecl) {
       }
 
       if (Context.getTargetInfo().allowDebugInfoForExternalRef() &&
-          !Var->isInvalidDecl() && !getLangOpts().CPlusPlus)
+          !Var->isInvalidDecl())
         ExternalDeclarations.push_back(Var);
 
       return;

diff  --git a/clang/test/CodeGen/debug-info-extern-basic.cpp b/clang/test/CodeGen/debug-info-extern-basic.cpp
new file mode 100644
index 00000000000000..1756690d166613
--- /dev/null
+++ b/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]])


        


More information about the cfe-commits mailing list