[clang] [clang][DebugInfo] Revert to attaching DW_AT_const_value on static member declarations (PR #73626)
Michael137 wrote: > Looks like LLDB linux buildbot isn't happy, checking... Fix in https://github.com/llvm/llvm-project/pull/73707 https://github.com/llvm/llvm-project/pull/73626 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][DebugInfo] Revert to attaching DW_AT_const_value on static member declarations (PR #73626)
Michael137 wrote: Looks like LLDB linux buildbot isn't happy, checking... https://github.com/llvm/llvm-project/pull/73626 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][DebugInfo] Revert to attaching DW_AT_const_value on static member declarations (PR #73626)
https://github.com/Michael137 closed https://github.com/llvm/llvm-project/pull/73626 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][DebugInfo] Revert to attaching DW_AT_const_value on static member declarations (PR #73626)
Michael137 wrote: > > I do wonder how feasible it would be for the downstream tests to be > > adjusted to look at the `DW_AT_location`.. > > As I mentioned on the other thread, the point is not to have to read the > value from the process-under-debug. This is not efficient in a > remote-debugging scenario. Ah that's fair, missed your comment on the other thread https://github.com/llvm/llvm-project/pull/73626 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][DebugInfo] Revert to attaching DW_AT_const_value on static member declarations (PR #73626)
pogo59 wrote: > I do wonder how feasible it would be for the downstream tests to be adjusted > to look at the `DW_AT_location`.. As I mentioned on the other thread, the point is not to have to read the value from the process-under-debug. This is not efficient in a remote-debugging scenario. https://github.com/llvm/llvm-project/pull/73626 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][DebugInfo] Revert to attaching DW_AT_const_value on static member declarations (PR #73626)
Michael137 wrote: I do wonder how feasible it would be for the downstream tests to be adjusted to look at the `DW_AT_location`.. https://github.com/llvm/llvm-project/pull/73626 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][DebugInfo] Revert to attaching DW_AT_const_value on static member declarations (PR #73626)
https://github.com/jryans approved this pull request. Thanks, seems like a fine temporary measure to me! https://github.com/llvm/llvm-project/pull/73626 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][DebugInfo] Revert to attaching DW_AT_const_value on static member declarations (PR #73626)
https://github.com/Michael137 edited https://github.com/llvm/llvm-project/pull/73626 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][DebugInfo] Revert to attaching DW_AT_const_value on static member declarations (PR #73626)
llvmbot wrote: @llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-codegen @llvm/pr-subscribers-debuginfo Author: Michael Buch (Michael137) Changes In #71780 we started emitting definitions for all static data-members with constant initialisers, even if they were constants (i.e., didn't have a location). We also dropped the DW_AT_const_value from the declaration to help resolve inconsistencies during type merging in the DWARFParallelLinker. However, for static data members that do have locations, we wouldn't emit a DW_AT_const_value on it, assuming that the consumer knows how to read the value using the location. This broke some consumers that really wanted to find a DW_AT_const_value. Ultimately we want to attach a DW_AT_const_value to definitions that have a location too. But to fix consumers broken by said change, this patch adds the constant back onto the declaration. --- Full diff: https://github.com/llvm/llvm-project/pull/73626.diff 3 Files Affected: - (modified) clang/lib/CodeGen/CGDebugInfo.cpp (+15-3) - (modified) clang/test/CodeGenCXX/debug-info-static-inline-member.cpp (+7-7) - (modified) clang/test/CodeGenCXX/debug-info-static-member.cpp (+4-4) ``diff diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 0b52d99ad07f164..5d9d5d1792450c3 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -1678,14 +1678,26 @@ CGDebugInfo::CreateRecordStaticField(const VarDecl *Var, llvm::DIType *RecordTy, unsigned LineNumber = getLineNumber(Var->getLocation()); StringRef VName = Var->getName(); + // FIXME: to avoid complications with type merging we should + // emit the constant on the definition instead of the declaration. + llvm::Constant *C = nullptr; + if (Var->getInit()) { +const APValue *Value = Var->evaluateValue(); +if (Value) { + if (Value->isInt()) +C = llvm::ConstantInt::get(CGM.getLLVMContext(), Value->getInt()); + if (Value->isFloat()) +C = llvm::ConstantFP::get(CGM.getLLVMContext(), Value->getFloat()); +} + } + llvm::DINode::DIFlags Flags = getAccessFlag(Var->getAccess(), RD); auto Tag = CGM.getCodeGenOpts().DwarfVersion >= 5 ? llvm::dwarf::DW_TAG_variable : llvm::dwarf::DW_TAG_member; auto Align = getDeclAlignIfRequired(Var, CGM.getContext()); - llvm::DIDerivedType *GV = - DBuilder.createStaticMemberType(RecordTy, VName, VUnit, LineNumber, VTy, - Flags, /* Val */ nullptr, Tag, Align); + llvm::DIDerivedType *GV = DBuilder.createStaticMemberType( + RecordTy, VName, VUnit, LineNumber, VTy, Flags, C, Tag, Align); StaticDataMemberCache[Var->getCanonicalDecl()].reset(GV); StaticDataMemberDefinitionsToEmit.push_back(Var->getCanonicalDecl()); return GV; diff --git a/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp b/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp index f2d4d9408a8297a..d3b6a363c5bd8f2 100644 --- a/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp +++ b/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp @@ -49,19 +49,19 @@ int main() { // CHECK: ![[INT_DECL]] = !DIDerivedType(tag: DW_TAG_member, name: "cexpr_int_with_addr", // CHECK-SAME: flags: DIFlagStaticMember -// CHECK-NOT: extraData: +// CHECK-SAME: extraData: i32 25 // CHECK: ![[INT_DECL2:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "cexpr_int2", // CHECK-SAME: flags: DIFlagStaticMember -// CHECK-NOT: extraData: +// CHECK-SAME: extraData: i32 26 // CHECK: ![[FLOAT_DECL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "cexpr_float", // CHECK-SAME: flags: DIFlagStaticMember -// CHECK-NOT: extraData: +// CHECK-SAME: extraData: float // CHECK: ![[ENUM_DECL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "cexpr_enum", // CHECK-SAME: flags: DIFlagStaticMember -// CHECK-NOT: extraData: +// CHECK-SAME: extraData: i32 -1 // CHECK: ![[EMPTY_DECL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "cexpr_struct_with_addr", // CHECK-SAME: flags: DIFlagStaticMember @@ -69,15 +69,15 @@ int main() { // CHECK: ![[IENUM_DECL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "inline_enum", // CHECK-SAME: flags: DIFlagStaticMember -// CHECK-NOT: extraData: +// CHECK-SAME: extraData: i32 -1 // CHECK: ![[EMPTY_TEMPLATED_DECL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "empty_templated", // CHECK-SAME:flags: DIFlagStaticMember -// CHECK-NOT:
[clang] [clang][DebugInfo] Revert to attaching DW_AT_const_value on static member declarations (PR #73626)
Michael137 wrote: FYI @petrhosek https://github.com/llvm/llvm-project/pull/73626 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][DebugInfo] Revert to attaching DW_AT_const_value on static member declarations (PR #73626)
https://github.com/Michael137 created https://github.com/llvm/llvm-project/pull/73626 In #71780 we started emitting definitions for all static data-members with constant initialisers, even if they were constants (i.e., didn't have a location). We also dropped the DW_AT_const_value from the declaration to help resolve inconsistencies during type merging in the DWARFParallelLinker. However, for static data members that do have locations, we wouldn't emit a DW_AT_const_value on it, assuming that the consumer knows how to read the value using the location. This broke some consumers that really wanted to find a DW_AT_const_value. Ultimately we want to attach a DW_AT_const_value to definitions that have a location too. But to fix consumers broken by said change, this patch adds the constant back onto the declaration. >From aabd30057e5ccfc16b22e535f1cab15b73308e1e Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Tue, 28 Nov 2023 08:40:57 + Subject: [PATCH 1/2] [clang][DebugInfo] Revert to attaching DW_AT_const_value on static member declarations In #71780 we started emitting definitions for all static data-members with constant initialisers, even if they were constants (i.e., didn't have a location). We also dropped the DW_AT_const_value from the declaration to help resolve inconsistencies during type merging in the DWARFParallelLinker. However, for static data members that do have locations, we wouldn't emit a DW_AT_const_value on it, assuming that the consumer knows how to read the value using the location. This broke some consumers that really wanted to find a DW_AT_const_value. Ultimately we want to attach a DW_AT_const_value to definitions that have a location too. But to fix consumers broken by said change, this patch adds the constant back onto the declaration. --- clang/lib/CodeGen/CGDebugInfo.cpp | 18 +++--- .../debug-info-static-inline-member.cpp| 10 +- .../CodeGenCXX/debug-info-static-member.cpp| 8 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 0b52d99ad07f164..5d9d5d1792450c3 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -1678,14 +1678,26 @@ CGDebugInfo::CreateRecordStaticField(const VarDecl *Var, llvm::DIType *RecordTy, unsigned LineNumber = getLineNumber(Var->getLocation()); StringRef VName = Var->getName(); + // FIXME: to avoid complications with type merging we should + // emit the constant on the definition instead of the declaration. + llvm::Constant *C = nullptr; + if (Var->getInit()) { +const APValue *Value = Var->evaluateValue(); +if (Value) { + if (Value->isInt()) +C = llvm::ConstantInt::get(CGM.getLLVMContext(), Value->getInt()); + if (Value->isFloat()) +C = llvm::ConstantFP::get(CGM.getLLVMContext(), Value->getFloat()); +} + } + llvm::DINode::DIFlags Flags = getAccessFlag(Var->getAccess(), RD); auto Tag = CGM.getCodeGenOpts().DwarfVersion >= 5 ? llvm::dwarf::DW_TAG_variable : llvm::dwarf::DW_TAG_member; auto Align = getDeclAlignIfRequired(Var, CGM.getContext()); - llvm::DIDerivedType *GV = - DBuilder.createStaticMemberType(RecordTy, VName, VUnit, LineNumber, VTy, - Flags, /* Val */ nullptr, Tag, Align); + llvm::DIDerivedType *GV = DBuilder.createStaticMemberType( + RecordTy, VName, VUnit, LineNumber, VTy, Flags, C, Tag, Align); StaticDataMemberCache[Var->getCanonicalDecl()].reset(GV); StaticDataMemberDefinitionsToEmit.push_back(Var->getCanonicalDecl()); return GV; diff --git a/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp b/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp index f2d4d9408a8297a..857ac8999ff471a 100644 --- a/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp +++ b/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp @@ -49,11 +49,11 @@ int main() { // CHECK: ![[INT_DECL]] = !DIDerivedType(tag: DW_TAG_member, name: "cexpr_int_with_addr", // CHECK-SAME: flags: DIFlagStaticMember -// CHECK-NOT: extraData: +// CHECK-SAME: extraData: i32 25 // CHECK: ![[INT_DECL2:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "cexpr_int2", // CHECK-SAME: flags: DIFlagStaticMember -// CHECK-NOT: extraData: +// CHECK-SAME: extraData: 26 // CHECK: ![[FLOAT_DECL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "cexpr_float", // CHECK-SAME: flags: DIFlagStaticMember @@ -61,7 +61,7 @@ int main() { // CHECK: ![[ENUM_DECL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "cexpr_enum", // CHECK-SAME: flags: DIFlagStaticMember -// CHECK-NOT: extraData: +//