efriedma added inline comments.
================ Comment at: clang/lib/CodeGen/CodeGenModule.cpp:4639 + getDataLayout().getTypeAllocSize(Init->getType())); + assert(VarSize == CstSize && "Emitted constant has unexpected size"); +#endif ---------------- ahatanak wrote: > efriedma wrote: > > ahatanak wrote: > > > This assertion fails when the following code is compiled: > > > > > > > > > ``` > > > typedef unsigned char uint8_t; > > > typedef uint8_t uint8_a16 __attribute__((aligned(16))); > > > > > > void foo1() { > > > static const uint8_a16 array1[] = { 1 }; > > > } > > > ``` > > `sizeof(uint8_a16[1])` is 16, but we currently emit a one-byte global. So > > it seems like there's an underlying bug exposed by the assertion. > > > > gcc thinks this is nonsense, and just prints an error. > It seems to me that we should disallow arrays that have an element whose > alignment is larger than its size, just as gcc does. > > But I see arrays like that declared in a couple of clang's regression tests > (e.g., `Sema/attr-aligned.c`). I'm not sure whether there was a reason for > not rejecting it or it was just an oversight. I'd guess oversight; it's originally a gcc extension, and using it to insert padding into arrays doesn't really make sense. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D123649/new/ https://reviews.llvm.org/D123649 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits