[PATCH] D133574: [C2x] reject type definitions in offsetof

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 18 05:52:37 PST 2023


aaron.ballman added a comment.

In D133574#4061428 <https://reviews.llvm.org/D133574#4061428>, @mstorsjo wrote:

> For clarity in the review - the relanded commit ended up reverted by @aeubanks in 39da55e8f548a11f7dadefa73ea73d809a5f1729 <https://reviews.llvm.org/rG39da55e8f548a11f7dadefa73ea73d809a5f1729>. The relanded commit triggers failed asserts like this:
>
>   $ echo 'void c() { __builtin_offsetof(struct {int b;}, b); }' | bin/clang -cc1 -emit-llvm -o /dev/null - -x c
>   clang: ../../clang/lib/AST/RecordLayoutBuilder.cpp:3286: const clang::ASTRecordLayout& clang::ASTContext::getASTRecordLayout(const clang::RecordDecl*) const: Assertion `!D->isInvalidDecl() && "Cannot get layout of invalid decl!"' failed.
>
> I also ran into a second issue with the reapplied version of the commit:
>
>   $ echo 'int i = __builtin_offsetof(struct {int b;}, b);' | bin/clang -cc1 -emit-llvm -o /dev/null - -x c
>   <stdin>:1:9: error: initializer element is not a compile-time constant
>   int i = __builtin_offsetof(struct {int b;}, b);
>           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>   1 error generated.
>
> (This used to compile successfully before.)

Sorry for the trouble, there was a declaration being marked as invalid despite us *warning* on it rather than erroring on it. I've corrected it and re-landed in e7300e75b51a7e7d4e81975b4be7a6c65f9a8286 <https://reviews.llvm.org/rGe7300e75b51a7e7d4e81975b4be7a6c65f9a8286> with additional test coverage for both of the scenarios discovered. Thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133574/new/

https://reviews.llvm.org/D133574



More information about the cfe-commits mailing list