Commit 634b5df5 by Jakub Jelinek Committed by Jakub Jelinek

re PR c/32041 (offsetof buglet)

	PR c/32041
	* c-parser.c (c_parser_postfix_expression): Allow `->' in
	offsetof member-designator, handle it as `[0].'.

	* parser.c (cp_parser_builtin_offsetof): Allow `->' in
	offsetof member-designator, handle it as `[0].'.

	* gcc.dg/pr32041.c: New test.
	* g++.dg/parse/offsetof9.C: New test.

From-SVN: r143305
parent 89b7d5e1
2009-01-12 Jakub Jelinek <jakub@redhat.com>
PR c/32041
* c-parser.c (c_parser_postfix_expression): Allow `->' in
offsetof member-designator, handle it as `[0].'.
2009-01-12 John David Anglin <dave.anglin@nrc-cnrc.gc.ca> 2009-01-12 John David Anglin <dave.anglin@nrc-cnrc.gc.ca>
* pa.c (pa_asm_output_mi_thunk): Use pc-relative branch to thunk * pa.c (pa_asm_output_mi_thunk): Use pc-relative branch to thunk
......
...@@ -5273,10 +5273,21 @@ c_parser_postfix_expression (c_parser *parser) ...@@ -5273,10 +5273,21 @@ c_parser_postfix_expression (c_parser *parser)
c_parser_consume_token (parser); c_parser_consume_token (parser);
while (c_parser_next_token_is (parser, CPP_DOT) while (c_parser_next_token_is (parser, CPP_DOT)
|| c_parser_next_token_is (parser, || c_parser_next_token_is (parser,
CPP_OPEN_SQUARE)) CPP_OPEN_SQUARE)
|| c_parser_next_token_is (parser,
CPP_DEREF))
{ {
if (c_parser_next_token_is (parser, CPP_DOT)) if (c_parser_next_token_is (parser, CPP_DEREF))
{
loc = c_parser_peek_token (parser)->location;
offsetof_ref = build_array_ref (offsetof_ref,
integer_zero_node,
loc);
goto do_dot;
}
else if (c_parser_next_token_is (parser, CPP_DOT))
{ {
do_dot:
c_parser_consume_token (parser); c_parser_consume_token (parser);
if (c_parser_next_token_is_not (parser, if (c_parser_next_token_is_not (parser,
CPP_NAME)) CPP_NAME))
......
2009-01-12 Jakub Jelinek <jakub@redhat.com> 2009-01-12 Jakub Jelinek <jakub@redhat.com>
PR c/32041
* parser.c (cp_parser_builtin_offsetof): Allow `->' in
offsetof member-designator, handle it as `[0].'.
PR c++/38794 PR c++/38794
* decl.c (start_function): If grokdeclarator hasn't returned * decl.c (start_function): If grokdeclarator hasn't returned
FUNCTION_DECL nor error_mark_node, issue diagnostics. FUNCTION_DECL nor error_mark_node, issue diagnostics.
......
/* C++ Parser. /* C++ Parser.
Copyright (C) 2000, 2001, 2002, 2003, 2004, Copyright (C) 2000, 2001, 2002, 2003, 2004,
2005, 2007, 2008 Free Software Foundation, Inc. 2005, 2007, 2008, 2009 Free Software Foundation, Inc.
Written by Mark Mitchell <mark@codesourcery.com>. Written by Mark Mitchell <mark@codesourcery.com>.
This file is part of GCC. This file is part of GCC.
...@@ -6627,7 +6627,8 @@ cp_parser_constant_expression (cp_parser* parser, ...@@ -6627,7 +6627,8 @@ cp_parser_constant_expression (cp_parser* parser,
offsetof-member-designator: offsetof-member-designator:
id-expression id-expression
| offsetof-member-designator "." id-expression | offsetof-member-designator "." id-expression
| offsetof-member-designator "[" expression "]" */ | offsetof-member-designator "[" expression "]"
| offsetof-member-designator "->" id-expression */
static tree static tree
cp_parser_builtin_offsetof (cp_parser *parser) cp_parser_builtin_offsetof (cp_parser *parser)
...@@ -6670,11 +6671,16 @@ cp_parser_builtin_offsetof (cp_parser *parser) ...@@ -6670,11 +6671,16 @@ cp_parser_builtin_offsetof (cp_parser *parser)
expr = cp_parser_postfix_open_square_expression (parser, expr, true); expr = cp_parser_postfix_open_square_expression (parser, expr, true);
break; break;
case CPP_DEREF:
/* offsetof-member-designator "->" identifier */
expr = grok_array_decl (expr, integer_zero_node);
/* FALLTHRU */
case CPP_DOT: case CPP_DOT:
/* offsetof-member-designator "." identifier */ /* offsetof-member-designator "." identifier */
cp_lexer_consume_token (parser->lexer); cp_lexer_consume_token (parser->lexer);
expr = cp_parser_postfix_dot_deref_expression (parser, CPP_DOT, expr, expr = cp_parser_postfix_dot_deref_expression (parser, CPP_DOT,
true, &dummy, expr, true, &dummy,
token->location); token->location);
break; break;
......
2009-01-12 Jakub Jelinek <jakub@redhat.com>
PR c/32041
* gcc.dg/pr32041.c: New test.
* g++.dg/parse/offsetof9.C: New test.
2009-01-12 Daniel Jacobowitz <dan@codesourcery.com> 2009-01-12 Daniel Jacobowitz <dan@codesourcery.com>
Nathan Froyd <froydnj@codesourcery.com> Nathan Froyd <froydnj@codesourcery.com>
......
/* PR c/32041 */
/* { dg-do run } */
struct S
{
int c;
struct { float f; } sa[2];
};
char a[__builtin_offsetof (S, sa->f)
== __builtin_offsetof (S, sa[0].f) ? 1 : -1];
template <int N>
struct T
{
int c[N];
struct { float f; } sa[N];
static int foo () { return __builtin_offsetof (T, sa->f); }
static int bar () { return __builtin_offsetof (T, sa[0].f); }
};
char b[__builtin_offsetof (T<5>, sa->f)
== __builtin_offsetof (T<5>, sa[0].f) ? 1 : -1];
int
main ()
{
if (T<1>::foo () != T<1>::bar ())
__builtin_abort ();
if (T<7>::foo () != T<7>::bar ())
__builtin_abort ();
}
/* PR c/32041 */
/* { dg-do compile } */
struct S
{
int c;
struct { float f; } sa[2];
};
char a[__builtin_offsetof (struct S, sa->f)
== __builtin_offsetof (struct S, sa[0].f) ? 1 : -1];
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment