llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.1k stars 12.01k forks source link

Missing constant values in debug info for late-instantiated constexpr static members of class templates #102676

Open dwblaikie opened 3 months ago

dwblaikie commented 3 months ago
template<typename T>
struct t1 {
  static constexpr bool m = sizeof(T) > 1;
};
t1<int> v1;
int i = t1<int>::m;
int j = t1<char>::m;
t1<char> v2;

Produces DWARF like this:

0x00000035:     DW_TAG_variable
                  DW_AT_name    ("m")
0x00000078:     DW_TAG_variable
                  DW_AT_name    ("m")
                  DW_AT_const_value     (0)

The constant is only attached if the constexpr member is instantiated before the type is created in the DWARF.

We have solutions for type information that address these kinds of ordering problems (if we emit a declaration for a type, but later on that type is defined, we can emit that definition instead of the declaration we initially created) - it'd probably be good to do something similar for static constexpr members to reduce this kind of ordering dependence.

(huh, GCC doesn't produce any debug info for "m" in either case above... ( https://godbolt.org/z/z6sxPv6nf ) - I guess it only produces debug info if the variable has a real definition/storage is created for it... huh)

llvmbot commented 3 months ago

@llvm/issue-subscribers-debuginfo

Author: David Blaikie (dwblaikie)

``` template<typename T> struct t1 { static constexpr bool m = sizeof(T) > 1; }; t1<int> v1; int i = t1<int>::m; int j = t1<char>::m; t1<char> v2; ``` Produces DWARF like this: ``` 0x00000035: DW_TAG_variable DW_AT_name ("m") 0x00000078: DW_TAG_variable DW_AT_name ("m") DW_AT_const_value (0) ``` The constant is only attached if the constexpr member is instantiated before the type is created in the DWARF. We have solutions for type information that address these kinds of ordering problems (if we emit a declaration for a type, but later on that type is defined, we can emit that definition instead of the declaration we initially created) - it'd probably be good to do something similar for static constexpr members to reduce this kind of ordering dependence. (huh, GCC doesn't produce any debug info for "m" in either case above... ( https://godbolt.org/z/z6sxPv6nf ) - I guess it only produces debug info if the variable has a real definition/storage is created for it... huh)
llvmbot commented 3 months ago

@llvm/issue-subscribers-clang-codegen

Author: David Blaikie (dwblaikie)

``` template<typename T> struct t1 { static constexpr bool m = sizeof(T) > 1; }; t1<int> v1; int i = t1<int>::m; int j = t1<char>::m; t1<char> v2; ``` Produces DWARF like this: ``` 0x00000035: DW_TAG_variable DW_AT_name ("m") 0x00000078: DW_TAG_variable DW_AT_name ("m") DW_AT_const_value (0) ``` The constant is only attached if the constexpr member is instantiated before the type is created in the DWARF. We have solutions for type information that address these kinds of ordering problems (if we emit a declaration for a type, but later on that type is defined, we can emit that definition instead of the declaration we initially created) - it'd probably be good to do something similar for static constexpr members to reduce this kind of ordering dependence. (huh, GCC doesn't produce any debug info for "m" in either case above... ( https://godbolt.org/z/z6sxPv6nf ) - I guess it only produces debug info if the variable has a real definition/storage is created for it... huh)