[clang] Always emit complete debug info for types which appear as a member of a standard-layout union. (PR #221615)

Avi Kivity via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 8 05:47:49 PDT 2026


================
@@ -3244,6 +3244,17 @@ static bool canUseCtorHoming(const CXXRecordDecl *RD) {
       RD->hasConstexprNonCopyMoveConstructor())
     return false;
 
+  // Skip this optimization if this type is standard-layout and is a member of
+  // some standard-layout union in this translation unit. Per the C++ spec, "it
+  // is permitted to inspect the common initial part of any of" the "common
+  // initial sequence" of distinct types in a standard-layout union. This
+  // exception to strict aliasing enables producing a reference to a type
+  // without ever having constructed that type.
+  //
+  // See: https://timsong-cpp.github.io/cppwp/n3337/class.mem#19
+  if (RD->isStandardLayoutUnionMember())
+    return false;
+
----------------
avikivity wrote:

Does this follow typedefs? Does it work for nested structs? (e.g. A is a member of a union, A contains A1, we must skip the optimization for A1 even though it is not directly a member of a union)

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


More information about the cfe-commits mailing list