From patchwork Sat May 10 11:31:01 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 347658 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id A4FD414009C for ; Sat, 10 May 2014 21:31:17 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=MUqT7+c2vWt5DrgCLV9xk5vjIA4FlBOdolOA2cPfRfFvcW+Hbu i59zPoWAOkgFz6ej1CQoZOWDbU1bY5oZwkfhW8q8RXZvDYnzGEgmwvLDWd57tkxn kcl9/O9niKATEfhprPdq+E4rSNKTWqNlA3WyRIFdcW222chIHH89ccuVY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; s= default; bh=bpg+cnu05I9JELfnXjPqvZ/c5V8=; b=C1USVCAQNz7Ru6rEpyt6 6IpEi8S4kUPToTpVF2GeBQYSQiLEA8cSo4ewsXKlUVDPcIpHj2phweIP/Gj6shbK bfpcrC3Vf37qVay6IcTrQmUB9UvAmho4pCm+WgroKiHah/3eBPWR8EgI3ynfHXaL FZILZJU3wYmxGlGB5qVP8lw= Received: (qmail 14078 invoked by alias); 10 May 2014 11:31:10 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 14067 invoked by uid 89); 10 May 2014 11:31:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.1 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 10 May 2014 11:31:08 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s4ABV59v020735 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sat, 10 May 2014 07:31:05 -0400 Received: from redhat.com (ovpn-116-30.ams2.redhat.com [10.36.116.30]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s4ABV1cP014819 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO); Sat, 10 May 2014 07:31:03 -0400 Date: Sat, 10 May 2014 13:31:01 +0200 From: Marek Polacek To: GCC Patches Cc: "Joseph S. Myers" Subject: [C PATCH] Add location to pedwarn_init Message-ID: <20140510113100.GC23554@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) As the subject says. Along with some whitespace fixes. Regtested/bootstrapped on x86_64-linux, ok for trunk? 2014-05-10 Marek Polacek * 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. Marek diff --git gcc/c/c-parser.c gcc/c/c-parser.c index 432bf96..6e8554d 100644 --- gcc/c/c-parser.c +++ gcc/c/c-parser.c @@ -1777,9 +1777,9 @@ c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, } 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, - init.original_type, asm_name); + init.original_type, asm_name); } } else @@ -7599,7 +7599,7 @@ c_parser_postfix_expression_after_paren_type (c_parser *parser, } init = c_parser_braced_init (parser, type, false); finish_init (); - maybe_warn_string_init (type, init); + maybe_warn_string_init (type_loc, type, init); if (type != error_mark_node && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type)) diff --git gcc/c/c-tree.h gcc/c/c-tree.h index ae932fa..e7dcb35 100644 --- gcc/c/c-tree.h +++ gcc/c/c-tree.h @@ -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 build_c_cast (location_t, 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 finish_init (void); extern void really_start_incremental_init (tree); diff --git gcc/c/c-typeck.c gcc/c/c-typeck.c index 6798801..4b1fe66 100644 --- gcc/c/c-typeck.c +++ gcc/c/c-typeck.c @@ -5596,13 +5596,13 @@ warning_init (location_t loc, int opt, const char *gmsgid) object of type TYPE. */ 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 && TREE_CODE (type) == ARRAY_TYPE && TREE_CODE (expr.value) == STRING_CST && expr.original_code != STRING_CST) - pedwarn_init (input_location, OPT_Wpedantic, + pedwarn_init (loc, OPT_Wpedantic, "array initialized from parenthesized string constant"); } @@ -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 strings are complete sentences, visible to gettext and checked at compile time. */ -#define WARN_FOR_ASSIGNMENT(LOCATION, OPT, AR, AS, IN, RE) \ +#define WARN_FOR_ASSIGNMENT(LOCATION, OPT, AR, AS, IN, RE) \ do { \ switch (errtype) \ { \ case ic_argpass: \ if (pedwarn (LOCATION, OPT, AR, parmnum, rname)) \ inform ((fundecl && !DECL_IS_BUILTIN (fundecl)) \ - ? DECL_SOURCE_LOCATION (fundecl) : LOCATION, \ + ? DECL_SOURCE_LOCATION (fundecl) : LOCATION, \ "expected %qT but argument is of type %qT", \ type, rhstype); \ break; \ @@ -5675,7 +5675,7 @@ convert_for_assignment (location_t location, location_t expr_loc, tree type, pedwarn_init (LOCATION, OPT, IN); \ break; \ case ic_return: \ - pedwarn (LOCATION, OPT, RE); \ + pedwarn (LOCATION, OPT, RE); \ break; \ default: \ gcc_unreachable (); \ @@ -6541,7 +6541,7 @@ digest_init (location_t init_loc, tree type, tree init, tree origtype, expr.value = inside_init; expr.original_code = (strict_string ? STRING_CST : ERROR_MARK); 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))) pedwarn_init (init_loc, OPT_Wpedantic, @@ -7430,7 +7430,7 @@ pop_init_level (location_t loc, int implicit, if (constructor_depth > 2) error_init (loc, "initialization of flexible array member in a nested context"); else - pedwarn_init (input_location, OPT_Wpedantic, + pedwarn_init (loc, OPT_Wpedantic, "initialization of a flexible array member"); /* 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) void 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)) return; @@ -7668,7 +7668,7 @@ set_init_index (location_t loc, tree first, tree last, { first = c_fully_fold (first, false, NULL); if (TREE_CODE (first) == INTEGER_CST) - pedwarn_init (input_location, OPT_Wpedantic, + pedwarn_init (loc, OPT_Wpedantic, "array index in initializer is not " "an integer constant expression"); } @@ -7677,7 +7677,7 @@ set_init_index (location_t loc, tree first, tree last, { last = c_fully_fold (last, false, NULL); if (TREE_CODE (last) == INTEGER_CST) - pedwarn_init (input_location, OPT_Wpedantic, + pedwarn_init (loc, OPT_Wpedantic, "array index in initializer is not " "an integer constant expression"); } @@ -8745,7 +8745,7 @@ process_init_element (location_t loc, struct c_expr value, bool implicit, if (constructor_fields == 0) { - pedwarn_init (input_location, 0, + pedwarn_init (loc, 0, "excess elements in union initializer"); break; } @@ -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) || integer_all_onesp (constructor_max_index))) { - pedwarn_init (input_location, 0, + pedwarn_init (loc, 0, "excess elements in array initializer"); break; } @@ -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. */ if (tree_int_cst_lt (constructor_max_index, constructor_index)) { - pedwarn_init (input_location, 0, + pedwarn_init (loc, 0, "excess elements in vector initializer"); break; } @@ -8901,7 +8901,7 @@ process_init_element (location_t loc, struct c_expr value, bool implicit, else if (constructor_type != error_mark_node && constructor_fields == 0) { - pedwarn_init (input_location, 0, + pedwarn_init (loc, 0, "excess elements in scalar initializer"); break; } @@ -9413,7 +9413,7 @@ do_case (location_t loc, tree low_value, tree high_value) { low_value = c_fully_fold (low_value, false, NULL); if (TREE_CODE (low_value) == INTEGER_CST) - pedwarn (input_location, OPT_Wpedantic, + pedwarn (loc, OPT_Wpedantic, "case label is not an integer constant expression"); } diff --git gcc/testsuite/gcc.dg/init-string-1.c gcc/testsuite/gcc.dg/init-string-1.c index ace3b34..a33f741 100644 --- gcc/testsuite/gcc.dg/init-string-1.c +++ gcc/testsuite/gcc.dg/init-string-1.c @@ -30,7 +30,7 @@ struct s j = { 1, (L"j") }; /* { 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 = { (("k")), /* { dg-bogus "warning" "warning in place of error" } */ /* { dg-error "parenthesized|near init" "paren array" { target *-*-* } 35 } */ @@ -48,7 +48,7 @@ struct s m = { .c = L"m", .a = ("m") }; /* { 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" }; diff --git gcc/testsuite/gcc.dg/pedwarn-init.c gcc/testsuite/gcc.dg/pedwarn-init.c index e69de29..1261115 100644 --- gcc/testsuite/gcc.dg/pedwarn-init.c +++ gcc/testsuite/gcc.dg/pedwarn-init.c @@ -0,0 +1,19 @@ +/* { 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" } */