[clang] [clang][DebugInfo] Emit global variable definitions for static data members with constant initializers (PR #70639)
Michael Buch via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 30 11:45:01 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())
----------------
Michael137 wrote:
Because this one has a corresponding `llvm::GlobalVariable` which doesn't go down the code-path I added. We emit a `DW_AT_location` only for this. Should we be emitting both a location and constant in this case?
https://github.com/llvm/llvm-project/pull/70639
More information about the cfe-commits
mailing list