kees wrote:

> `InitListChecker::CheckStructUnionTypes` never calls 
> `StructuredList->setInitializedFieldInUnion`

Ah-ha, thank you for the pointer. I think I've figured this out: initialization 
was avoiding flexible arrays because we don't yet support non-zero 
initialization (as described in commit 
5955a0f9375a8c0b134eeb4a8de5155dcce7c94f). However, we _do_ want to allow zero 
initialization. This fixes the Assert and the sketchy `undef`s in the codegen 
output. Now we get zero inits:

```diff
-    // If we've hit the flexible array member at the end, we're done.
-    if (Field->getType()->isIncompleteArrayType())
+    // If we've hit a flexible array member, only allow zero initialization.
+    // Other values are not yet supported. See commit 5955a0f9375a.
+    if (Field->getType()->isIncompleteArrayType() && !IsZeroInitializer(Init))
```

> I think things can be simplified a bit further

Ah yes! That's much nicer. Since we're processing the Union, we can just return 
completely instead of continuing the loop. Thanks!


https://github.com/llvm/llvm-project/pull/84428
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to