[clang] Revert "[DebugInfo] Ignore undefined constexpr constructors in constructor homing." (PR #221566)
Avi Kivity via cfe-commits
cfe-commits at lists.llvm.org
Sun Sep 6 10:51:35 PDT 2026
avikivity wrote:
A self-contained, linkable reproducer, in the shape of `absl::container_internal::map_slot_type<K, V>`: the constructor definitions are present (as libstdc++'s `std::pair` constructors are), but are never instantiated for `mypair<const K, V>`, because construction goes through `mutable_value` and only reads go through `value`.
```c++
template <class A, class B>
struct mypair {
A first;
B second;
constexpr mypair() : first(), second() {}
constexpr mypair(const A& a, const B& b) : first(a), second(b) {}
};
template <class K, class V>
union map_slot_type {
map_slot_type() {}
~map_slot_type() {}
using value_type = mypair<const K, V>; // read, never constructed
using mutable_value_type = mypair<K, V>; // constructed
value_type value;
mutable_value_type mutable_value;
K key;
};
map_slot_type<unsigned long, void*> slot;
int marker;
int main() {
// Construction goes through the mutable pair, as absl's map_slot_policy does.
slot.mutable_value = mypair<unsigned long, void*>(42, &marker);
// Reads go through the const-key pair, whose type is now unavailable.
return (slot.value.first == 42 && slot.value.second == &marker) ? 0 : 1;
}
```
```
$ clang++ -O2 -g ctor-homing-linkable.cc -o prog && ./prog; echo $?
0
$ llvm-dwarfdump --debug-info prog | grep -A4 'DW_AT_name.*"mypair<const'
$ gdb -q -batch -ex 'set language c++' -ex 'ptype mypair<const unsigned long, void*>' prog
```
clang 22.1.8:
```
DW_AT_name ("mypair<const unsigned long, void *>")
DW_AT_byte_size (0x10)
type = struct mypair<unsigned long const, void*> [with A = const unsigned long, B = void *] {
const A first;
B second;
mypair(void);
mypair(const A &, void * const&);
}
```
clang 24.0.0git (03de3d1299bf, i.e. with 6ba0802b406e):
```
DW_AT_name ("mypair<const unsigned long, void *>")
DW_AT_declaration (true)
No symbol "mypair<const unsigned long, void*>" in current context.
```
Both link and run, exit status 0.
Dropping `constexpr` from both constructors, everything else unchanged:
```
clang 22.1.8 exit=0 const-key pair: DW_AT_declaration
clang 24.0.0git exit=0 const-key pair: DW_AT_declaration
```
https://github.com/llvm/llvm-project/pull/221566
More information about the cfe-commits
mailing list