Commit d033409e by Marek Polacek Committed by Marek Polacek

c-parser.c (c_parser_declaration_or_fndef): Pass init_loc to maybe_warn_string_init.

	* c-parser.c (c_parser_declaration_or_fndef): Pass init_loc to
	maybe_warn_string_init.
	(c_parser_postfix_expression_after_paren_type): Pass type_loc to
	maybe_warn_string_init.
	* c-tree.h (maybe_warn_string_init): Update declaration.
	* c-typeck.c (maybe_warn_string_init): Add location parameter.
	Call pedwarn_init with loc instead of with input_location.
	(digest_init): Pass init_loc to maybe_warn_string_init.
	(pop_init_level): Call pedwarn_init with loc instead of with
	input_location.
	(set_init_index): Likewise.
	(process_init_element): Likewise.

	* gcc.dg/pedwarn-init.c: New test.
	* gcc.dg/init-string-1.c: Adjust dg-error.

From-SVN: r210300
parent 00599202
2014-05-10 Marek Polacek <polacek@redhat.com>
* c-parser.c (c_parser_declaration_or_fndef): Pass init_loc to
maybe_warn_string_init.
(c_parser_postfix_expression_after_paren_type): Pass type_loc to
maybe_warn_string_init.
* c-tree.h (maybe_warn_string_init): Update declaration.
* c-typeck.c (maybe_warn_string_init): Add location parameter.
Call pedwarn_init with loc instead of with input_location.
(digest_init): Pass init_loc to maybe_warn_string_init.
(pop_init_level): Call pedwarn_init with loc instead of with
input_location.
(set_init_index): Likewise.
(process_init_element): Likewise.
2014-05-09 Marek Polacek <polacek@redhat.com> 2014-05-09 Marek Polacek <polacek@redhat.com>
PR c/61096 PR c/61096
......
...@@ -1777,9 +1777,9 @@ c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, ...@@ -1777,9 +1777,9 @@ c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok,
} }
if (d != error_mark_node) if (d != error_mark_node)
{ {
maybe_warn_string_init (TREE_TYPE (d), init); maybe_warn_string_init (init_loc, TREE_TYPE (d), init);
finish_decl (d, init_loc, init.value, finish_decl (d, init_loc, init.value,
init.original_type, asm_name); init.original_type, asm_name);
} }
} }
else else
...@@ -7599,7 +7599,7 @@ c_parser_postfix_expression_after_paren_type (c_parser *parser, ...@@ -7599,7 +7599,7 @@ c_parser_postfix_expression_after_paren_type (c_parser *parser,
} }
init = c_parser_braced_init (parser, type, false); init = c_parser_braced_init (parser, type, false);
finish_init (); finish_init ();
maybe_warn_string_init (type, init); maybe_warn_string_init (type_loc, type, init);
if (type != error_mark_node if (type != error_mark_node
&& !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type)) && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type))
......
...@@ -602,7 +602,7 @@ extern tree build_compound_expr (location_t, tree, tree); ...@@ -602,7 +602,7 @@ extern tree build_compound_expr (location_t, tree, tree);
extern tree c_cast_expr (location_t, struct c_type_name *, tree); extern tree c_cast_expr (location_t, struct c_type_name *, tree);
extern tree build_c_cast (location_t, tree, tree); extern tree build_c_cast (location_t, tree, tree);
extern void store_init_value (location_t, tree, tree, tree); extern void store_init_value (location_t, tree, tree, tree);
extern void maybe_warn_string_init (tree, struct c_expr); extern void maybe_warn_string_init (location_t, tree, struct c_expr);
extern void start_init (tree, tree, int); extern void start_init (tree, tree, int);
extern void finish_init (void); extern void finish_init (void);
extern void really_start_incremental_init (tree); extern void really_start_incremental_init (tree);
......
...@@ -5596,13 +5596,13 @@ warning_init (location_t loc, int opt, const char *gmsgid) ...@@ -5596,13 +5596,13 @@ warning_init (location_t loc, int opt, const char *gmsgid)
object of type TYPE. */ object of type TYPE. */
void void
maybe_warn_string_init (tree type, struct c_expr expr) maybe_warn_string_init (location_t loc, tree type, struct c_expr expr)
{ {
if (pedantic if (pedantic
&& TREE_CODE (type) == ARRAY_TYPE && TREE_CODE (type) == ARRAY_TYPE
&& TREE_CODE (expr.value) == STRING_CST && TREE_CODE (expr.value) == STRING_CST
&& expr.original_code != STRING_CST) && expr.original_code != STRING_CST)
pedwarn_init (input_location, OPT_Wpedantic, pedwarn_init (loc, OPT_Wpedantic,
"array initialized from parenthesized string constant"); "array initialized from parenthesized string constant");
} }
...@@ -5657,14 +5657,14 @@ convert_for_assignment (location_t location, location_t expr_loc, tree type, ...@@ -5657,14 +5657,14 @@ convert_for_assignment (location_t location, location_t expr_loc, tree type,
/* This macro is used to emit diagnostics to ensure that all format /* This macro is used to emit diagnostics to ensure that all format
strings are complete sentences, visible to gettext and checked at strings are complete sentences, visible to gettext and checked at
compile time. */ compile time. */
#define WARN_FOR_ASSIGNMENT(LOCATION, OPT, AR, AS, IN, RE) \ #define WARN_FOR_ASSIGNMENT(LOCATION, OPT, AR, AS, IN, RE) \
do { \ do { \
switch (errtype) \ switch (errtype) \
{ \ { \
case ic_argpass: \ case ic_argpass: \
if (pedwarn (LOCATION, OPT, AR, parmnum, rname)) \ if (pedwarn (LOCATION, OPT, AR, parmnum, rname)) \
inform ((fundecl && !DECL_IS_BUILTIN (fundecl)) \ inform ((fundecl && !DECL_IS_BUILTIN (fundecl)) \
? DECL_SOURCE_LOCATION (fundecl) : LOCATION, \ ? DECL_SOURCE_LOCATION (fundecl) : LOCATION, \
"expected %qT but argument is of type %qT", \ "expected %qT but argument is of type %qT", \
type, rhstype); \ type, rhstype); \
break; \ break; \
...@@ -5675,7 +5675,7 @@ convert_for_assignment (location_t location, location_t expr_loc, tree type, ...@@ -5675,7 +5675,7 @@ convert_for_assignment (location_t location, location_t expr_loc, tree type,
pedwarn_init (LOCATION, OPT, IN); \ pedwarn_init (LOCATION, OPT, IN); \
break; \ break; \
case ic_return: \ case ic_return: \
pedwarn (LOCATION, OPT, RE); \ pedwarn (LOCATION, OPT, RE); \
break; \ break; \
default: \ default: \
gcc_unreachable (); \ gcc_unreachable (); \
...@@ -6541,7 +6541,7 @@ digest_init (location_t init_loc, tree type, tree init, tree origtype, ...@@ -6541,7 +6541,7 @@ digest_init (location_t init_loc, tree type, tree init, tree origtype,
expr.value = inside_init; expr.value = inside_init;
expr.original_code = (strict_string ? STRING_CST : ERROR_MARK); expr.original_code = (strict_string ? STRING_CST : ERROR_MARK);
expr.original_type = NULL; expr.original_type = NULL;
maybe_warn_string_init (type, expr); maybe_warn_string_init (init_loc, type, expr);
if (TYPE_DOMAIN (type) && !TYPE_MAX_VALUE (TYPE_DOMAIN (type))) if (TYPE_DOMAIN (type) && !TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
pedwarn_init (init_loc, OPT_Wpedantic, pedwarn_init (init_loc, OPT_Wpedantic,
...@@ -7430,7 +7430,7 @@ pop_init_level (location_t loc, int implicit, ...@@ -7430,7 +7430,7 @@ pop_init_level (location_t loc, int implicit,
if (constructor_depth > 2) if (constructor_depth > 2)
error_init (loc, "initialization of flexible array member in a nested context"); error_init (loc, "initialization of flexible array member in a nested context");
else else
pedwarn_init (input_location, OPT_Wpedantic, pedwarn_init (loc, OPT_Wpedantic,
"initialization of a flexible array member"); "initialization of a flexible array member");
/* We have already issued an error message for the existence /* We have already issued an error message for the existence
...@@ -7650,7 +7650,7 @@ push_range_stack (tree range_end, struct obstack * braced_init_obstack) ...@@ -7650,7 +7650,7 @@ push_range_stack (tree range_end, struct obstack * braced_init_obstack)
void void
set_init_index (location_t loc, tree first, tree last, set_init_index (location_t loc, tree first, tree last,
struct obstack * braced_init_obstack) struct obstack *braced_init_obstack)
{ {
if (set_designator (loc, 1, braced_init_obstack)) if (set_designator (loc, 1, braced_init_obstack))
return; return;
...@@ -7668,7 +7668,7 @@ set_init_index (location_t loc, tree first, tree last, ...@@ -7668,7 +7668,7 @@ set_init_index (location_t loc, tree first, tree last,
{ {
first = c_fully_fold (first, false, NULL); first = c_fully_fold (first, false, NULL);
if (TREE_CODE (first) == INTEGER_CST) if (TREE_CODE (first) == INTEGER_CST)
pedwarn_init (input_location, OPT_Wpedantic, pedwarn_init (loc, OPT_Wpedantic,
"array index in initializer is not " "array index in initializer is not "
"an integer constant expression"); "an integer constant expression");
} }
...@@ -7677,7 +7677,7 @@ set_init_index (location_t loc, tree first, tree last, ...@@ -7677,7 +7677,7 @@ set_init_index (location_t loc, tree first, tree last,
{ {
last = c_fully_fold (last, false, NULL); last = c_fully_fold (last, false, NULL);
if (TREE_CODE (last) == INTEGER_CST) if (TREE_CODE (last) == INTEGER_CST)
pedwarn_init (input_location, OPT_Wpedantic, pedwarn_init (loc, OPT_Wpedantic,
"array index in initializer is not " "array index in initializer is not "
"an integer constant expression"); "an integer constant expression");
} }
...@@ -8745,7 +8745,7 @@ process_init_element (location_t loc, struct c_expr value, bool implicit, ...@@ -8745,7 +8745,7 @@ process_init_element (location_t loc, struct c_expr value, bool implicit,
if (constructor_fields == 0) if (constructor_fields == 0)
{ {
pedwarn_init (input_location, 0, pedwarn_init (loc, 0,
"excess elements in union initializer"); "excess elements in union initializer");
break; break;
} }
...@@ -8835,7 +8835,7 @@ process_init_element (location_t loc, struct c_expr value, bool implicit, ...@@ -8835,7 +8835,7 @@ process_init_element (location_t loc, struct c_expr value, bool implicit,
&& (tree_int_cst_lt (constructor_max_index, constructor_index) && (tree_int_cst_lt (constructor_max_index, constructor_index)
|| integer_all_onesp (constructor_max_index))) || integer_all_onesp (constructor_max_index)))
{ {
pedwarn_init (input_location, 0, pedwarn_init (loc, 0,
"excess elements in array initializer"); "excess elements in array initializer");
break; break;
} }
...@@ -8869,7 +8869,7 @@ process_init_element (location_t loc, struct c_expr value, bool implicit, ...@@ -8869,7 +8869,7 @@ process_init_element (location_t loc, struct c_expr value, bool implicit,
always have a fixed size derived from their type. */ always have a fixed size derived from their type. */
if (tree_int_cst_lt (constructor_max_index, constructor_index)) if (tree_int_cst_lt (constructor_max_index, constructor_index))
{ {
pedwarn_init (input_location, 0, pedwarn_init (loc, 0,
"excess elements in vector initializer"); "excess elements in vector initializer");
break; break;
} }
...@@ -8901,7 +8901,7 @@ process_init_element (location_t loc, struct c_expr value, bool implicit, ...@@ -8901,7 +8901,7 @@ process_init_element (location_t loc, struct c_expr value, bool implicit,
else if (constructor_type != error_mark_node else if (constructor_type != error_mark_node
&& constructor_fields == 0) && constructor_fields == 0)
{ {
pedwarn_init (input_location, 0, pedwarn_init (loc, 0,
"excess elements in scalar initializer"); "excess elements in scalar initializer");
break; break;
} }
...@@ -9413,7 +9413,7 @@ do_case (location_t loc, tree low_value, tree high_value) ...@@ -9413,7 +9413,7 @@ do_case (location_t loc, tree low_value, tree high_value)
{ {
low_value = c_fully_fold (low_value, false, NULL); low_value = c_fully_fold (low_value, false, NULL);
if (TREE_CODE (low_value) == INTEGER_CST) if (TREE_CODE (low_value) == INTEGER_CST)
pedwarn (input_location, OPT_Wpedantic, pedwarn (loc, OPT_Wpedantic,
"case label is not an integer constant expression"); "case label is not an integer constant expression");
} }
......
2014-05-10 Marek Polacek <polacek@redhat.com>
* gcc.dg/pedwarn-init.c: New test.
* gcc.dg/init-string-1.c: Adjust dg-error.
2014-05-10 Hans-Peter Nilsson <hp@bitrange.com> 2014-05-10 Hans-Peter Nilsson <hp@bitrange.com>
* lib/target-supports.exp * lib/target-supports.exp
......
...@@ -30,7 +30,7 @@ struct s j = { ...@@ -30,7 +30,7 @@ struct s j = {
1, 1,
(L"j") (L"j")
}; /* { dg-bogus "warning" "warning in place of error" } */ }; /* { dg-bogus "warning" "warning in place of error" } */
/* { dg-error "parenthesized|near init" "paren array" { target *-*-* } 32 } */ /* { dg-error "parenthesized|near init" "paren array" { target *-*-* } 31 } */
struct s k = { struct s k = {
(("k")), /* { dg-bogus "warning" "warning in place of error" } */ (("k")), /* { dg-bogus "warning" "warning in place of error" } */
/* { dg-error "parenthesized|near init" "paren array" { target *-*-* } 35 } */ /* { dg-error "parenthesized|near init" "paren array" { target *-*-* } 35 } */
...@@ -48,7 +48,7 @@ struct s m = { ...@@ -48,7 +48,7 @@ struct s m = {
.c = L"m", .c = L"m",
.a = ("m") .a = ("m")
}; /* { dg-bogus "warning" "warning in place of error" } */ }; /* { dg-bogus "warning" "warning in place of error" } */
/* { dg-error "parenthesized|near init" "paren array" { target *-*-* } 50 } */ /* { dg-error "parenthesized|near init" "paren array" { target *-*-* } 49 } */
char *n = (char []){ "n" }; char *n = (char []){ "n" };
......
/* { dg-do compile } */
/* { dg-options "-std=gnu99 -Wpedantic" } */
/* { dg-prune-output ".*near initialization for.*" } */
typedef unsigned vec __attribute__ ((vector_size (2 * sizeof (int))));
union u { int a; double d; };
struct S { int i; char fam[]; };
int i;
vec v = { 1, 2, 3 }; /* { dg-warning "17:excess elements in vector initializer" } */
int a1 = { 1, 2 }; /* { dg-warning "15:excess elements in scalar initializer" } */
int a2[2] = { 1, 2, 3 }; /* { dg-warning "21:excess elements in array initializer" } */
int a3[] = { [1 ? 1 : i] = 0 }; /* { dg-warning "15:array index in initializer is not an integer constant expression" } */
int a4[] = { [1 ... 1 ? 2 : i] = 0 }; /* { dg-warning "15:array index in initializer is not an integer constant expression" } */
char a5[] = ("lol"); /* { dg-warning "13:array initialized from parenthesized string constant" } */
char a6[] = { ("foo") }; /* { dg-warning "13:array initialized from parenthesized string constant" } */
char *a7 = (char []) { ("bar") }; /* { dg-warning "12:array initialized from parenthesized string constant" } */
union u u = { 1, 1.0 }; /* { dg-warning "18:excess elements in union initializer" } */
struct S s = { 1, 2 }; /* { dg-warning "14:initialization of a flexible array member" } */
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