Commit ea58ef42 by Marek Polacek Committed by Marek Polacek

re PR c/61096 (error_init lacks a location)

	PR c/61096
	* c-parser.c (c_parser_braced_init): Pass brace_loc to push_init_level.
	(c_parser_initelt): Pass location to set_init_label.  Pass array index
	location to set_init_index.
	* c-tree.h (push_init_level): Update declaration.
	(pop_init_level): Likewise.
	(set_init_index): Likewise.
	(set_init_label): Likewise.
	* c-typeck.c (error_init): Add location parameter.  Call error_at
	instead of error.
	(digest_init): Pass init_loc to error_init.
	(really_start_incremental_init):
	(push_init_level): Add location parameter.  Pass loc to pop_init_level
	and error_init.
	(pop_init_level): Likewise.
	(set_designator): Add location parameter.  Pass loc to pop_init_level,
	push_init_level, and error_init.
	(set_init_index): Add location parameter.  Pass loc to error_init and
	set_designator.
	(set_init_label): Likewise.
	(output_init_element): Pass loc to error_init.
	(process_init_element): Pass loc to error_init, pop_init_level,
	pedwarn_init, and push_init_level.

	* gcc.dg/pr61096-1.c: New test.
	* gcc.dg/pr61096-2.c: New test.

From-SVN: r210280
parent 4f61140c
2014-05-09 Marek Polacek <polacek@redhat.com>
PR c/61096
* c-parser.c (c_parser_braced_init): Pass brace_loc to push_init_level.
(c_parser_initelt): Pass location to set_init_label. Pass array index
location to set_init_index.
* c-tree.h (push_init_level): Update declaration.
(pop_init_level): Likewise.
(set_init_index): Likewise.
(set_init_label): Likewise.
* c-typeck.c (error_init): Add location parameter. Call error_at
instead of error.
(digest_init): Pass init_loc to error_init.
(really_start_incremental_init):
(push_init_level): Add location parameter. Pass loc to pop_init_level
and error_init.
(pop_init_level): Likewise.
(set_designator): Add location parameter. Pass loc to pop_init_level,
push_init_level, and error_init.
(set_init_index): Add location parameter. Pass loc to error_init and
set_designator.
(set_init_label): Likewise.
(output_init_element): Pass loc to error_init.
(process_init_element): Pass loc to error_init, pop_init_level,
pedwarn_init, and push_init_level.
2014-05-09 Marek Polacek <polacek@redhat.com>
PR c/50459
* c-parser.c (c_parser_attributes): Parse the arguments as an
expression-list if the attribute takes identifier.
......
......@@ -4143,7 +4143,7 @@ c_parser_braced_init (c_parser *parser, tree type, bool nested_p)
gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
c_parser_consume_token (parser);
if (nested_p)
push_init_level (0, &braced_init_obstack);
push_init_level (brace_loc, 0, &braced_init_obstack);
else
really_start_incremental_init (type);
if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
......@@ -4173,12 +4173,12 @@ c_parser_braced_init (c_parser *parser, tree type, bool nested_p)
ret.original_code = ERROR_MARK;
ret.original_type = NULL;
c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>");
pop_init_level (0, &braced_init_obstack);
pop_init_level (brace_loc, 0, &braced_init_obstack);
obstack_free (&braced_init_obstack, NULL);
return ret;
}
c_parser_consume_token (parser);
ret = pop_init_level (0, &braced_init_obstack);
ret = pop_init_level (brace_loc, 0, &braced_init_obstack);
obstack_free (&braced_init_obstack, NULL);
return ret;
}
......@@ -4195,7 +4195,8 @@ c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack)
&& c_parser_peek_2nd_token (parser)->type == CPP_COLON)
{
/* Old-style structure member designator. */
set_init_label (c_parser_peek_token (parser)->value,
set_init_label (c_parser_peek_token (parser)->location,
c_parser_peek_token (parser)->value,
braced_init_obstack);
/* Use the colon as the error location. */
pedwarn (c_parser_peek_2nd_token (parser)->location, OPT_Wpedantic,
......@@ -4224,7 +4225,7 @@ c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack)
c_parser_consume_token (parser);
if (c_parser_next_token_is (parser, CPP_NAME))
{
set_init_label (c_parser_peek_token (parser)->value,
set_init_label (des_loc, c_parser_peek_token (parser)->value,
braced_init_obstack);
c_parser_consume_token (parser);
}
......@@ -4245,6 +4246,7 @@ c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack)
{
tree first, second;
location_t ellipsis_loc = UNKNOWN_LOCATION; /* Quiet warning. */
location_t array_index_loc = UNKNOWN_LOCATION;
/* ??? Following the old parser, [ objc-receiver
objc-message-args ] is accepted as an initializer,
being distinguished from a designator by what follows
......@@ -4322,6 +4324,7 @@ c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack)
return;
}
c_parser_consume_token (parser);
array_index_loc = c_parser_peek_token (parser)->location;
first = c_parser_expr_no_commas (parser, NULL).value;
mark_exp_read (first);
array_desig_after_first:
......@@ -4337,7 +4340,8 @@ c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack)
if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
{
c_parser_consume_token (parser);
set_init_index (first, second, braced_init_obstack);
set_init_index (array_index_loc, first, second,
braced_init_obstack);
if (second)
pedwarn (ellipsis_loc, OPT_Wpedantic,
"ISO C forbids specifying range of elements to initialize");
......
......@@ -606,10 +606,10 @@ extern void maybe_warn_string_init (tree, struct c_expr);
extern void start_init (tree, tree, int);
extern void finish_init (void);
extern void really_start_incremental_init (tree);
extern void push_init_level (int, struct obstack *);
extern struct c_expr pop_init_level (int, struct obstack *);
extern void set_init_index (tree, tree, struct obstack *);
extern void set_init_label (tree, struct obstack *);
extern void push_init_level (location_t, int, struct obstack *);
extern struct c_expr pop_init_level (location_t, int, struct obstack *);
extern void set_init_index (location_t, tree, tree, struct obstack *);
extern void set_init_label (location_t, tree, struct obstack *);
extern void process_init_element (location_t, struct c_expr, bool,
struct obstack *);
extern tree build_compound_literal (location_t, tree, tree, bool);
......
2014-05-09 Marek Polacek <polacek@redhat.com>
PR c/61096
* gcc.dg/pr61096-1.c: New test.
* gcc.dg/pr61096-2.c: New test.
2014-05-09 Florian Weimer <fweimer@redhat.com>
* gcc.dg/fstack-protector-strong.c: Add coverage for return slots.
......
/* PR c/61077 */
/* { dg-do compile } */
/* { dg-options "-std=gnu99 -fshort-enums -fshort-wchar -Wpedantic" } */
/* { dg-prune-output ".*near initialization for.*" } */
typedef enum { A } schar;
extern int e;
struct S
{
int a[3];
};
struct f
{
int w;
int x[];
};
struct g
{
struct f f; /* { dg-warning "invalid use of structure with flexible array member" } */
};
char w1[] = L"foo"; /* { dg-error "13:char-array initialized from wide string" } */
__WCHAR_TYPE__ w2[] = "foo"; /* { dg-error "23:wide character array initialized from non-wide string" } */
__WCHAR_TYPE__ w3[] = U"foo"; /* { dg-error "23:wide character array initialized from incompatible wide string" } */
schar a1[] = "foo"; /* { dg-error "14:array of inappropriate type initialized from string constant" } */
int a2[] = (int[]) { 1 }; /* { dg-error "12:array initialized from non-constant array expression" } */
int a3 = e; /* { dg-error "10:initializer element is not constant" } */
int a4 = (e, 1); /* { dg-error "10:initializer element is not constant" } */
int a5 = a1[0]; /* { dg-error "10:initializer element is not constant" } */
int a6 = &a3 - &a4; /* { dg-error "10:initializer element is not" } */
int a7[] = a7; /* { dg-error "12:invalid initializer" } */
struct S s = { { 1 }, { 3 } }; /* { dg-error "23:extra brace group at end of initializer" } */
/* { dg-warning "23:excess elements in struct initializer" "" { target *-*-* } 34 } */
struct g g1 = { {0, { 1 } } }; /* { dg-error "21:initialization of flexible array member in a nested context" } */
struct g g2 = { .f[0] = 1 }; /* { dg-error "20:array index in non-array initializer" } */
__extension__ int a8 = { }; /* { dg-error "24:empty scalar initializer" } */
int a9[10] = {[1.2] = 2 }; /* { dg-error "16:array index in initializer not of integer type" } */
int a10[10] = {[e] = 2 }; /* { dg-error "17:nonconstant array index in initializer" } */
__extension__ int a11[10] = {[1 ... e] = 1 }; /* { dg-error "31:nonconstant array index in initializer" } */
int a12 = {[1] = 2 }; /* { dg-error "13:array index in non-array initializer" } */
int a13[2] = {[-1] = 4 }; /* { dg-error "16:array index in initializer exceeds array bounds" } */
int a14[2] = {[64] = 4 }; /* { dg-error "16:array index in initializer exceeds array bounds" } */
__extension__ int a15[10] = {[2 ... 1] = 4 }; /* { dg-error "31:empty index range in initializer" } */
__extension__ int a16[10] = {[2 ... 100] = 4 }; /* { dg-error "31:array index range in initializer exceeds array bounds" } */
int a17[] = { .B = 1 }; /* { dg-error "15:field name not in record or union initializer" } */
int a18[] = { e }; /* { dg-error "15:initializer element is not constant" } */
char a19[1] = { "x", "x" }; /* { dg-error "22:excess elements in char array initializer" } */
void
bar (void)
{
struct f f = { 2, "c" }; /* { dg-error "21:non-static initialization of a flexible array member" } */
}
struct
{
char *v;
} sx[] = { .v = 0 }; /* { dg-error "12:field name not in record or union initializer" } */
/* PR c/61077 */
/* { dg-do compile } */
struct s { char c[1]; };
extern struct s foo (void);
void
bar (void)
{
char *t = (foo ()).c; /* { dg-error "13:invalid use of non-lvalue array" } */
}
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