aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2009-06-27 20:38:33 +0000
committerEli Friedman <eli.friedman@gmail.com>2009-06-27 20:38:33 +0000
commit309fe0d8e696f61eaa4b1de9fb1cc49c4b5cda7f (patch)
tree4bd44f9ddfe627d2cb8cee2fa48a202892dc86c0
parent4c9b68f70ed4a55dc597b35c36f0e72e5d33ee81 (diff)
Fix the parser error hanlding for __builtin_offsetof to actually print
out an error for a malformed __builtin_offsetof. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@74388 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Parse/ParseExpr.cpp13
-rw-r--r--test/Parser/offsetof.c7
2 files changed, 14 insertions, 6 deletions
diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp
index 13b32acd5b..ee2f209fff 100644
--- a/lib/Parse/ParseExpr.cpp
+++ b/lib/Parse/ParseExpr.cpp
@@ -1172,17 +1172,18 @@ Parser::OwningExprResult Parser::ParseBuiltinPrimaryExpression() {
Comps.back().LocEnd =
MatchRHSPunctuation(tok::r_square, Comps.back().LocStart);
- } else if (Tok.is(tok::r_paren)) {
- if (Ty.isInvalid())
+ } else {
+ if (Tok.isNot(tok::r_paren)) {
+ MatchRHSPunctuation(tok::r_paren, LParenLoc);
+ Res = ExprError();
+ } else if (Ty.isInvalid()) {
Res = ExprError();
- else
+ } else {
Res = Actions.ActOnBuiltinOffsetOf(CurScope, StartLoc, TypeLoc,
Ty.get(), &Comps[0],
Comps.size(), ConsumeParen());
+ }
break;
- } else {
- // Error occurred.
- return ExprError();
}
}
break;
diff --git a/test/Parser/offsetof.c b/test/Parser/offsetof.c
new file mode 100644
index 0000000000..6c4e3feaa6
--- /dev/null
+++ b/test/Parser/offsetof.c
@@ -0,0 +1,7 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+
+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 '('}}