[clang] [lldb] [clang][DebugInfo] Emit global variable definitions for static data members with constant initializers (PR #70639)
David Blaikie via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 31 13:56:36 PDT 2023
================
@@ -0,0 +1,87 @@
+// RUN: %clangxx -target arm64-apple-macosx11.0.0 -g %s -emit-llvm -S -o - | FileCheck --check-prefixes=CHECK %s
+
+enum class Enum : int {
+ VAL = -1
+};
+
+struct Empty {};
+
+constexpr auto func() { return 25; }
+
+struct Foo {
+ static constexpr int cexpr_int = func();
+ static constexpr int cexpr_int2 = func() + 1;
+ static constexpr float cexpr_float = 2.0 + 1.0;
+ static constexpr Enum cexpr_enum = Enum::VAL;
+ static constexpr Empty cexpr_empty{};
+ static inline Enum inline_enum = Enum::VAL;
+
+ template<typename T>
+ static constexpr T cexpr_template{};
+};
+
+int main() {
+ Foo f;
+
+ // Force global variable definitions to be emitted.
+ (void)&Foo::cexpr_int;
+ (void)&Foo::cexpr_empty;
+
+ return Foo::cexpr_int + Foo::cexpr_float
+ + (int)Foo::cexpr_enum + Foo::cexpr_template<short>;
+}
+
+// CHECK: @{{.*}}cexpr_int{{.*}} =
+// CHECK-SAME: !dbg ![[INT_GLOBAL:[0-9]+]]
+
+// CHECK: @{{.*}}cexpr_empty{{.*}} =
+// CHECK-SAME !dbg ![[EMPTY_GLOBAL:[0-9]+]]
+
+// CHECK: !DIGlobalVariableExpression(var: ![[INT_VAR:[0-9]+]], expr: !DIExpression())
----------------
dwblaikie wrote:
Ah, that was the intent (the line 27 taking address-of)? Maybe give the variable a more descriptive name to make it clear this is testing the case where the variable has a definition emitted to the IR
https://github.com/llvm/llvm-project/pull/70639
More information about the cfe-commits
mailing list