[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:41:09 PDT 2026
================
@@ -27,12 +27,23 @@ struct E {
constexpr E(){};
} TestE;
-// Declared but not defined constexpr constructor should not emit full debug info..
-// CHECK-DAG: !DICompositeType(tag: DW_TAG_structure_type, name: "DeclaredConstexpr"{{.*}}flags: DIFlagFwdDecl
+// A constexpr constructor that is only declared here may still be defined
+// elsewhere and called, so it cannot be relied on to home the type.
+// CHECK-DAG: !DICompositeType(tag: DW_TAG_structure_type, name: "DeclaredConstexpr"{{.*}}DIFlagTypePassByValue
struct DeclaredConstexpr {
constexpr DeclaredConstexpr();
} TestDeclaredConstexpr;
+// A declared-only constexpr constructor that is never odr-used need not be
+// defined anywhere in the program, so nothing would ever emit the definition
+// of the type - but the type is still required to be complete here.
+// CHECK-DAG: !DICompositeType(tag: DW_TAG_structure_type, name: "ConstexprDeclaredOnly"{{.*}}DIFlagTypePassByValue
+struct ConstexprDeclaredOnly {
+ unsigned long v;
+ constexpr ConstexprDeclaredOnly(unsigned long t);
----------------
avikivity wrote:
Aha, so it does _not_ call the constructor. Extract from abseil container_memory.h:
```c++
// If kMutableKeys is true, key can be accessed through all slots while value
// and mutable_value must be accessed only via INITIALIZED slots. Slots are
// created and destroyed via mutable_value so that the key can be moved later.
//
// Accessing one of the union fields while the other is active is safe as
// long as they are layout-compatible, which is guaranteed by the definition of
// kMutableKeys. For C++11, the relevant section of the standard is
// https://timsong-cpp.github.io/cppwp/n3337/class.mem#19 (9.2.19)
template <class K, class V>
union map_slot_type {
map_slot_type() {}
~map_slot_type() = delete;
using value_type = std::pair<const K, V>;
using mutable_value_type =
std::pair<absl::remove_const_t<K>, absl::remove_const_t<V>>;
value_type value;
mutable_value_type mutable_value;
absl::remove_const_t<K> key;
};
```
Abseil constructs mutable_value and then accesses value, so value_type does not get debug information emitted.
https://github.com/llvm/llvm-project/pull/221566
More information about the cfe-commits
mailing list