[clang] Revert "[DebugInfo] Ignore undefined constexpr constructors in constructor homing." (PR #221566)

Clayton Knittel via cfe-commits cfe-commits at lists.llvm.org
Sun Sep 6 10:52:34 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);
----------------
ClaytonKnittel wrote:

Hmm, so right this is essentially the `reinterpret_cast` to a type that was never constructed loophole that breaks constructor homing as a whole.

Constructor homing relies on the assumption that any type which we care about having debug info must be constructed.

https://github.com/llvm/llvm-project/pull/221566


More information about the cfe-commits mailing list