forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reland "[clang][DebugInfo] Emit global variable definitions for stati…
…c data members with constant initializers" (llvm#71780) This patch relands llvm#70639 It was reverted because under certain conditions we triggered an assertion in `DIBuilder`. Specifically, in the original patch we called `EmitGlobalVariable` at the end of `CGDebugInfo::finalize`, after all the temporary `DIType`s have been uniqued. With limited debug-info such temporary nodes would be created more frequently, leaving us with non-uniqued nodes by the time we got to `DIBuilder::finalize`; this violated its pre-condition and caused assertions to trigger. To fix this, the latest iteration of the patch moves `EmitGlobalVariable` to the beginning of `CGDebugInfo::finalize`. Now, when we create a temporary `DIType` node as a result of emitting a variable definition, it will get uniqued in time. A test-case was added for this scenario. We also now don't emit a linkage name for non-locationed constants since LLDB doesn't make use of it anyway. Original commit message: """ When an LLDB user asks for the value of a static data member, LLDB starts by searching the Names accelerator table for the corresponding variable definition DIE. For static data members with out-of-class definitions that works fine, because those get represented as global variables with a location and making them eligible to be added to the Names table. However, in-class definitions won’t get indexed because we usually don't emit global variables for them. So in DWARF we end up with a single `DW_TAG_member` that usually holds the constant initializer. But we don't get a corresponding CU-level `DW_TAG_variable` like we do for out-of-class definitions. To make it more convenient for debuggers to get to the value of inline static data members, this patch makes sure we emit definitions for static variables with constant initializers the same way we do for other static variables. This also aligns Clang closer to GCC, which produces CU-level definitions for inline statics and also emits these into `.debug_pubnames`. The implementation keeps track of newly created static data members. Then in `CGDebugInfo::finalize`, we emit a global `DW_TAG_variable` with a `DW_AT_const_value` for any of those declarations that didn't end up with a definition in the `DeclCache`. The newly emitted `DW_TAG_variable` will look as follows: ``` 0x0000007b: DW_TAG_structure_type DW_AT_calling_convention (DW_CC_pass_by_value) DW_AT_name ("Foo") ... 0x0000008d: DW_TAG_member DW_AT_name ("i") DW_AT_type (0x00000062 "const int") DW_AT_external (true) DW_AT_declaration (true) DW_AT_const_value (4) Newly added vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv 0x0000009a: DW_TAG_variable DW_AT_specification (0x0000008d "i") DW_AT_const_value (4) DW_AT_linkage_name ("_ZN2t2IiE1iIfEE") ``` This patch also drops the `DW_AT_const_value` off of the declaration since we now always have it on the definition. This ensures that the `DWARFParallelLinker` can type-merge class with static members where we couldn't attach the constant on the declaration in some CUs. """ Dependent changes: * llvm#71800
- Loading branch information
1 parent
3182b7d
commit 2d4cee3
Showing
7 changed files
with
219 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
clang/test/CodeGenCXX/debug-info-static-inline-member.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// RUN: %clangxx -target arm64-apple-macosx11.0.0 -g -debug-info-kind=standalone %s -emit-llvm -S -o - | FileCheck --check-prefixes=CHECK %s | ||
// RUN: %clangxx -target arm64-apple-macosx11.0.0 -g -debug-info-kind=limited %s -emit-llvm -S -o - | FileCheck --check-prefixes=CHECK %s | ||
|
||
enum class Enum : int { | ||
VAL = -1 | ||
}; | ||
|
||
struct Empty {}; | ||
struct Fwd; | ||
|
||
constexpr auto func() { return 25; } | ||
|
||
struct Foo { | ||
static constexpr int cexpr_int_with_addr = 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_struct_with_addr{}; | ||
static inline Enum inline_enum = Enum::VAL; | ||
|
||
template<typename T, unsigned V> | ||
static constexpr auto cexpr_template = V; | ||
|
||
static const auto empty_templated = cexpr_template<Fwd, 1>; | ||
}; | ||
|
||
int main() { | ||
Foo f; | ||
//Bar b; | ||
|
||
// Force global variable definitions to be emitted. | ||
(void)&Foo::cexpr_int_with_addr; | ||
(void)&Foo::cexpr_struct_with_addr; | ||
|
||
return Foo::cexpr_int_with_addr + Foo::cexpr_float | ||
+ (int)Foo::cexpr_enum + Foo::cexpr_template<short, 5> | ||
+ Foo::empty_templated; | ||
} | ||
|
||
// CHECK: @{{.*}}cexpr_int_with_addr{{.*}} = | ||
// CHECK-SAME: !dbg ![[INT_GLOBAL:[0-9]+]] | ||
|
||
// CHECK: @{{.*}}cexpr_struct_with_addr{{.*}} = | ||
// CHECK-SAME !dbg ![[EMPTY_GLOBAL:[0-9]+]] | ||
|
||
// CHECK: !DIGlobalVariableExpression(var: ![[INT_VAR:[0-9]+]], expr: !DIExpression()) | ||
// CHECK: ![[INT_VAR]] = distinct !DIGlobalVariable(name: "cexpr_int_with_addr", linkageName: | ||
// CHECK-SAME: isLocal: false, isDefinition: true, declaration: ![[INT_DECL:[0-9]+]]) | ||
|
||
// CHECK: ![[INT_DECL]] = !DIDerivedType(tag: DW_TAG_member, name: "cexpr_int_with_addr", | ||
// CHECK-SAME: flags: DIFlagStaticMember | ||
// CHECK-NOT: extraData: | ||
|
||
// CHECK: ![[INT_DECL2:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "cexpr_int2", | ||
// CHECK-SAME: flags: DIFlagStaticMember | ||
// CHECK-NOT: extraData: | ||
|
||
// CHECK: ![[FLOAT_DECL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "cexpr_float", | ||
// CHECK-SAME: flags: DIFlagStaticMember | ||
// CHECK-NOT: extraData: | ||
|
||
// CHECK: ![[ENUM_DECL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "cexpr_enum", | ||
// CHECK-SAME: flags: DIFlagStaticMember | ||
// CHECK-NOT: extraData: | ||
|
||
// CHECK: ![[EMPTY_DECL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "cexpr_struct_with_addr", | ||
// CHECK-SAME: flags: DIFlagStaticMember | ||
// CHECK-NOT: extraData: | ||
|
||
// CHECK: ![[IENUM_DECL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "inline_enum", | ||
// CHECK-SAME: flags: DIFlagStaticMember | ||
// CHECK-NOT: extraData: | ||
|
||
// CHECK: ![[EMPTY_TEMPLATED_DECL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "empty_templated", | ||
// CHECK-SAME: flags: DIFlagStaticMember | ||
// CHECK-NOT: extraData: | ||
|
||
// CHECK: ![[TEMPLATE_DECL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "cexpr_template", | ||
// CHECK-SAME: flags: DIFlagStaticMember | ||
// CHECK-NOT: extraData: | ||
|
||
// CHECK: !DIGlobalVariableExpression(var: ![[EMPTY_VAR:[0-9]+]], expr: !DIExpression()) | ||
// CHECK: ![[EMPTY_VAR]] = distinct !DIGlobalVariable(name: "cexpr_struct_with_addr", linkageName: | ||
// CHECK-SAME: isLocal: false, isDefinition: true, declaration: ![[EMPTY_DECL]]) | ||
|
||
// CHECK: !DIGlobalVariableExpression(var: ![[INT_VAR2:[0-9]+]], expr: !DIExpression(DW_OP_constu, 26, DW_OP_stack_value)) | ||
// CHECK: ![[INT_VAR2]] = distinct !DIGlobalVariable(name: "cexpr_int2" | ||
// CHECK-NOT: linkageName: | ||
// CHECK-SAME: isLocal: true, isDefinition: true, declaration: ![[INT_DECL2]]) | ||
|
||
// CHECK: !DIGlobalVariableExpression(var: ![[FLOAT_VAR:[0-9]+]], expr: !DIExpression(DW_OP_constu, {{.*}}, DW_OP_stack_value)) | ||
// CHECK: ![[FLOAT_VAR]] = distinct !DIGlobalVariable(name: "cexpr_float" | ||
// CHECK-NOT: linkageName: | ||
// CHECK-SAME: isLocal: true, isDefinition: true, declaration: ![[FLOAT_DECL]]) | ||
|
||
// CHECK: !DIGlobalVariableExpression(var: ![[ENUM_VAR:[0-9]+]], expr: !DIExpression(DW_OP_constu, {{.*}}, DW_OP_stack_value)) | ||
// CHECK: ![[ENUM_VAR]] = distinct !DIGlobalVariable(name: "cexpr_enum" | ||
// CHECK-NOT: linkageName: | ||
// CHECK-SAME: isLocal: true, isDefinition: true, declaration: ![[ENUM_DECL]]) | ||
|
||
// CHECK: !DIGlobalVariableExpression(var: ![[IENUM_VAR:[0-9]+]], expr: !DIExpression(DW_OP_constu, {{.*}}, DW_OP_stack_value)) | ||
// CHECK: ![[IENUM_VAR]] = distinct !DIGlobalVariable(name: "inline_enum" | ||
// CHECK-NOT: linkageName: | ||
// CHECK-SAME: isLocal: true, isDefinition: true, declaration: ![[IENUM_DECL]]) | ||
|
||
// CHECK: !DIGlobalVariableExpression(var: ![[EMPTY_TEMPLATED_VAR:[0-9]+]], expr: !DIExpression(DW_OP_constu, 1, DW_OP_stack_value)) | ||
// CHECK: ![[EMPTY_TEMPLATED_VAR]] = distinct !DIGlobalVariable(name: "empty_templated" | ||
// CHECK-NOT: linkageName: | ||
// CHECK-SAME: isLocal: true, isDefinition: true, declaration: ![[EMPTY_TEMPLATED_DECL]]) | ||
|
||
// CHECK: !DIGlobalVariableExpression(var: ![[TEMPLATE_VAR:[0-9]+]], expr: !DIExpression(DW_OP_constu, 5, DW_OP_stack_value)) | ||
// CHECK: ![[TEMPLATE_VAR]] = distinct !DIGlobalVariable(name: "cexpr_template" | ||
// CHECK-NOT: linkageName: | ||
// CHECK-SAME: isLocal: true, isDefinition: true, declaration: ![[TEMPLATE_DECL]], templateParams: ![[TEMPLATE_PARMS_2:[0-9]+]]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters