[PATCH] D133574: [C2x] reject type definitions in offsetof
Aaron Ballman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 23 08:38:31 PDT 2022
aaron.ballman added inline comments.
================
Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:1650
+def err_type_defined_in_offsetof : Error<
+ "%0 cannot be defined in '__builtin_offsetof'">;
----------------
inclyc wrote:
> aaron.ballman wrote:
> > inclyc wrote:
> > > aaron.ballman wrote:
> > > > We might want this change, we might not -- can you test the diagnostic behavior when using `#include <stddef.h>`? Does it print `__builtin_offsetof` in the following example?
> > > > ```
> > > > #include <stddef.h>
> > > >
> > > > int main() {
> > > > return offsetof(struct S { int a; }, a);
> > > > }
> > > > ```
> > > > when executed with `clang -fsyntax-only -ffreestanding -std=c2x test.c`
> > > >
> > > > If it prints the builtin name, I think we'll want to look at the builtin token to see if it was expanded from a macro named `offsetof` to improve the diagnostic quality.
> > > ```
> > > local/offsetofcc.c:4:26: error: 'struct S' cannot be defined in '__builtin_offsetof'
> > > return offsetof(struct S { int a; }, a);
> > > ^
> > > 1 error generated.
> > > ```
> > > > If it prints the builtin name, I think we'll want to look at the builtin token to see if it was expanded from a macro named offsetof to improve the diagnostic quality.
> > >
> > > OK
> > We have similar code for this here:
> >
> > https://github.com/llvm/llvm-project/blob/main/clang/lib/Sema/SemaChecking.cpp#L13438
> > We have similar code for this here:
>
> Wow! Thank you so much for this. I'm searching for how to do this in a LOT of doxygen generated pages (
No problem! I realized "this could be tricky, surely we've done this before" and went looking. :-D
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