[PATCH] D133574: [C2x] reject type definitions in offsetof
YingChi Long via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Sep 24 10:10:31 PDT 2022
inclyc updated this revision to Diff 462680.
inclyc added a comment.
Address comments.
Clang will now consider __builtin_offsetof #defined from "offsetof" to improve
diagnostic message.
For example:
#define offsetof(t, d) __builtin_offsetof(t, d)
int main() {
return offsetof(struct S { int a; }, a);
}
local/offsetof.c:4:26: error: 'S' cannot be defined in 'offsetof'
return offsetof(struct S { int a; }, a);
^
1 error generated.
Emm, the "expected-error" of struct B within a macro seems have to be annotated
at the same line as"struct A".
int macro(void) {
return offsetof(struct A // expected-error{{'A' cannot be defined in 'offsetof'}}
// expected-error at -1{{'B' cannot be defined in 'offsetof'}} <---- Have to write this here, but I believe the line number is correct
{
int a;
struct B // FIXME: verifier seems to think the error is emitted by the macro
// In fact the location of the error is "B" on the line above
{
int c;
int d;
} x;
}, a);
}
clang/test/C/C2x/n2350.c:11:36: error: 'A' cannot be defined in '__builtin_offsetof'
return __builtin_offsetof(struct A // expected-error{{'A' cannot be defined in '__builtin_offsetof'}}
^
clang/test/C/C2x/n2350.c:14:12: error: 'B' cannot be defined in '__builtin_offsetof'
struct B // expected-error{{'B' cannot be defined in '__builtin_offsetof'}}
^
clang/test/C/C2x/n2350.c:26:26: error: 'A' cannot be defined in 'offsetof'
return offsetof(struct A // expected-error{{'A' cannot be defined in 'offsetof'}}
^
clang/test/C/C2x/n2350.c:30:12: error: 'B' cannot be defined in 'offsetof' <-- note that this line number is "30" (not "26")
struct B // FIXME: verifier seems to think the error is emitted by the macro
^
4 errors generated.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D133574/new/
https://reviews.llvm.org/D133574
Files:
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Parse/Parser.h
clang/include/clang/Parse/RAIIObjectsForParser.h
clang/include/clang/Sema/Sema.h
clang/lib/Parse/ParseDecl.cpp
clang/lib/Parse/ParseDeclCXX.cpp
clang/lib/Parse/ParseExpr.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/test/C/C2x/n2350.c
clang/test/Parser/declarators.c
clang/test/SemaCXX/offsetof.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133574.462680.patch
Type: text/x-patch
Size: 12500 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220924/85641e4c/attachment-0001.bin>
More information about the cfe-commits
mailing list