[clang] [clang][bytecode] Fix reading union template parameter object (PR #179899)

Yanzuo Liu via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 5 05:33:32 PST 2026


================
@@ -5069,14 +5069,30 @@ bool Compiler<Emitter>::visitAPValueInitializer(const APValue &Val,
   }
   if (Val.isUnion()) {
     const FieldDecl *UnionField = Val.getUnionField();
-    const Record *R = this->getRecord(UnionField->getParent());
+    if (!UnionField)
+      // no active fields
+      return true;
+    const Record *R = this->getRecord(T);
     assert(R);
     const APValue &F = Val.getUnionValue();
     const Record::Field *RF = R->getField(UnionField);
-    PrimType T = classifyPrim(RF->Decl->getType());
-    if (!this->visitAPValue(F, T, E))
+    QualType FieldType = RF->Decl->getType();
+
+    if (OptPrimType PT = classify(FieldType)) {
+      if (!this->visitAPValue(F, *PT, E))
+        return false;
+      if (RF->isBitField())
+        return this->emitInitBitFieldActivate(*PT, RF, E);
----------------
zwuis wrote:

Bit-fields can exist in unions. There is no rule rejecting them.

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


More information about the cfe-commits mailing list