[PATCH] D72434: Support offset of member designator with the arrow for __builtin_offsetof
Jim Lin via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 8 22:04:03 PST 2020
Jim created this revision.
Jim added a reviewer: eli.friedman.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Push array index 0 into offsets to support offset of member designator x->b.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D72434
Files:
clang/lib/Parse/ParseExpr.cpp
clang/test/Parser/offsetof.c
Index: clang/test/Parser/offsetof.c
===================================================================
--- clang/test/Parser/offsetof.c
+++ clang/test/Parser/offsetof.c
@@ -3,5 +3,3 @@
struct a { struct { int b; } x[2]; };
int a = __builtin_offsetof(struct a, x; // expected-error{{expected ')'}} expected-note{{to match this '('}}
-// FIXME: This actually shouldn't give an error
-int b = __builtin_offsetof(struct a, x->b); // expected-error{{expected ')'}} expected-note{{to match this '('}}
Index: clang/lib/Parse/ParseExpr.cpp
===================================================================
--- clang/lib/Parse/ParseExpr.cpp
+++ clang/lib/Parse/ParseExpr.cpp
@@ -2165,7 +2165,6 @@
Comps.back().U.IdentInfo = Tok.getIdentifierInfo();
Comps.back().LocStart = Comps.back().LocEnd = ConsumeToken();
- // FIXME: This loop leaks the index expressions on error.
while (1) {
if (Tok.is(tok::period)) {
// offsetof-member-designator: offsetof-member-designator '.' identifier
@@ -2200,6 +2199,28 @@
ST.consumeClose();
Comps.back().LocEnd = ST.getCloseLocation();
+ } else if (Tok.is(tok::arrow)) {
+ // offsetof-member-designator: offsetof-member-design '->' identifier
+ // Push array index 0 into offsets.
+ Comps.push_back(Sema::OffsetOfComponent());
+ Comps.back().isBrackets = true;
+ SourceLocation SavedLoc = ConsumeToken();
+ Comps.back().LocStart = Comps.back().LocEnd = SavedLoc;
+ Res = Actions.ActOnIntegerConstant(SourceLocation(), 0);
+ Comps.back().U.E = Res.get();
+
+ Comps.push_back(Sema::OffsetOfComponent());
+ Comps.back().isBrackets = false;
+ Comps.back().LocStart = SavedLoc;
+
+ if (Tok.isNot(tok::identifier)) {
+ Diag(Tok, diag::err_expected) << tok::identifier;
+ SkipUntil(tok::r_paren, StopAtSemi);
+ return ExprError();
+ }
+ Comps.back().U.IdentInfo = Tok.getIdentifierInfo();
+ Comps.back().LocEnd = ConsumeToken();
+
} else {
if (Tok.isNot(tok::r_paren)) {
PT.consumeClose();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72434.236960.patch
Type: text/x-patch
Size: 2135 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200109/324d87d6/attachment.bin>
More information about the cfe-commits
mailing list