-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clang][DebugInfo] Emit global variable definitions for static data members with constant initializers #70639
Changes from all commits
81bd540
59e1072
ec47e17
970cc99
ed9d3bb
89dc41d
51e0997
b5d9dd2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// 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_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> | ||
static constexpr T cexpr_template{}; | ||
}; | ||
|
||
int main() { | ||
Foo f; | ||
|
||
// 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>; | ||
} | ||
|
||
// 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()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why doesn't this have a value/expression? (but INT_VAR2 does) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because this one has a corresponding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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 |
||
// 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: ![[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", 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", 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", 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", linkageName: | ||
// CHECK-SAME: isLocal: true, isDefinition: true, declaration: ![[IENUM_DECL]]) | ||
|
||
// CHECK: !DIGlobalVariableExpression(var: ![[TEMPLATE_VAR:[0-9]+]], expr: !DIExpression(DW_OP_constu, 0, DW_OP_stack_value)) | ||
// CHECK: ![[TEMPLATE_VAR]] = distinct !DIGlobalVariable(name: "cexpr_template", linkageName: | ||
// CHECK-SAME: isLocal: true, isDefinition: true, declaration: ![[TEMPLATE_DECL]], templateParams: ![[TEMPLATE_PARMS:[0-9]+]]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This parameter on
createStaticMemberType
is technically not needed anymore. So could think about removing it in a follow-up