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

Martin Storsjö via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 18 00:48:00 PST 2023


mstorsjo added a subscriber: aeubanks.
mstorsjo added a comment.

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.)


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