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

Clayton Knittel via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 15 19:59:30 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
----------------
ClaytonKnittel wrote:

Right, here's my refined understanding:

`canUseCtorHoming` is called on complete types by `CGDebugInfo::completeRequiredType` and `CGDebugInfo::CreateType`. I verified this by adding an `assert(RD->isComplete());` to `canUseCtorHoming` (happy to remove this if you think it's unnecessary to keep around). Types may only be complete if all their field member / base class types are also complete.

What matters for this code is that `isStandardLayoutUnionMember` has been calculated on the `RecordDecl` before it is called here. This bit is initialized by `CXXRecordDecl::completeDefinition`, which, as you would expect, sets the complete definition bit in the `TagDecl`.

This complete bit is also set in a few other places, so as a sanity check I temporarily added an `isComplete` bit to `CXXRecordDecl` and only set it at the end of `CXXRecordDecl::completeDefinition`. With the assertion updated to check this temporary `isComplete`, `check-clang` still passes.

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


More information about the cfe-commits mailing list