From 92b638845d0564991c3ae8d739bc67e8d52b597d Mon Sep 17 00:00:00 2001 From: mpolacek Date: Mon, 5 Jan 2015 12:03:57 +0000 Subject: [PATCH] PR c/64423 c-family/ * c-common.c (warn_array_subscript_with_type_char): Add location_t parameter. Use it. * c-common.h (warn_array_subscript_with_type_char): Update declaration. c/ * c-typeck.c (build_array_ref): Pass loc down to warn_array_subscript_with_type_char. cp/ * typeck.c (cp_build_array_ref): Pass loc down to warn_array_subscript_with_type_char. testsuite/ * gcc.dg/pr64423.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@219186 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/c-family/ChangeLog | 8 ++++++++ gcc/c-family/c-common.c | 5 +++-- gcc/c-family/c-common.h | 2 +- gcc/c/ChangeLog | 6 ++++++ gcc/c/c-typeck.c | 2 +- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/typeck.c | 4 ++-- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/pr64423.c | 13 +++++++++++++ 9 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr64423.c diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 47aa690dae7..960c7d1de2a 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,11 @@ +2015-01-05 Marek Polacek + + PR c/64423 + * c-common.c (warn_array_subscript_with_type_char): Add location_t + parameter. Use it. + * c-common.h (warn_array_subscript_with_type_char): Update + declaration. + 2014-12-20 Edward Smith-Rowland <3dw4rd@verizon.net> * c-cppbuiltin.c (__cpp_sized_deallocation): Uncomment and move macro. diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 1066c6b96a7..af7a07e18b0 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -11238,11 +11238,12 @@ check_missing_format_attribute (tree ltype, tree rtype) warning only for non-constant value of type char. */ void -warn_array_subscript_with_type_char (tree index) +warn_array_subscript_with_type_char (location_t loc, tree index) { if (TYPE_MAIN_VARIANT (TREE_TYPE (index)) == char_type_node && TREE_CODE (index) != INTEGER_CST) - warning (OPT_Wchar_subscripts, "array subscript has type %"); + warning_at (loc, OPT_Wchar_subscripts, + "array subscript has type %"); } /* Implement -Wparentheses for the unexpected C precedence rules, to diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index c7eebcfc2ba..d1f09a63a8b 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -1014,7 +1014,7 @@ extern tree builtin_type_for_size (int, bool); extern void c_common_mark_addressable_vec (tree); -extern void warn_array_subscript_with_type_char (tree); +extern void warn_array_subscript_with_type_char (location_t, tree); extern void warn_about_parentheses (location_t, enum tree_code, enum tree_code, tree, diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 1661747d604..7a0eda0dcef 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,9 @@ +2015-01-05 Marek Polacek + + PR c/64423 + * c-typeck.c (build_array_ref): Pass loc down to + warn_array_subscript_with_type_char. + 2014-12-20 Martin Uecker * c-typeck.c: New behavious for pointers to arrays with qualifiers diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index abd452aed39..37beb6407ac 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -2501,7 +2501,7 @@ build_array_ref (location_t loc, tree array, tree index) /* ??? Existing practice has been to warn only when the char index is syntactically the index, not for char[array]. */ if (!swapped) - warn_array_subscript_with_type_char (index); + warn_array_subscript_with_type_char (loc, index); /* Apply default promotions *after* noticing character types. */ index = default_conversion (index); diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index a6ce50bc685..de34ef92cf6 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2015-01-05 Marek Polacek + + PR c/64423 + * typeck.c (cp_build_array_ref): Pass loc down to + warn_array_subscript_with_type_char. + 2014-12-31 Iain Sandoe * parser.c (cp_parser_primary_expression): If parsing an diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 9368b49b012..fc85ec34821 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -3081,7 +3081,7 @@ cp_build_array_ref (location_t loc, tree array, tree idx, { tree rval, type; - warn_array_subscript_with_type_char (idx); + warn_array_subscript_with_type_char (loc, idx); if (!INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (idx))) { @@ -3191,7 +3191,7 @@ cp_build_array_ref (location_t loc, tree array, tree idx, return error_mark_node; } - warn_array_subscript_with_type_char (idx); + warn_array_subscript_with_type_char (loc, idx); ret = cp_build_indirect_ref (cp_build_binary_op (input_location, PLUS_EXPR, ar, ind, diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 1690e7b0224..7293521c535 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-01-05 Marek Polacek + + PR c/64423 + * gcc.dg/pr64423.c: New test. + 2015-01-05 Hans-Peter Nilsson * gcc.dg/debug/debug-1.c: Pass -fno-if-conversion for diff --git a/gcc/testsuite/gcc.dg/pr64423.c b/gcc/testsuite/gcc.dg/pr64423.c new file mode 100644 index 00000000000..c228acb05a3 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr64423.c @@ -0,0 +1,13 @@ +/* PR c/64423 */ +/* { dg-do compile } */ +/* { dg-options "-Wchar-subscripts" } */ + +int a[100]; + +int +f (char c) +{ + return a[c] /* { dg-warning "11:array subscript has type .char." } */ + + a[c] /* { dg-warning "14:array subscript has type .char." } */ + + a[c]; /* { dg-warning "16:array subscript has type .char." } */ +} -- 2.11.4.GIT