diff options
author | Marek Polacek <polacek@redhat.com> | 2014-01-23 21:01:08 +0000 |
---|---|---|
committer | Marek Polacek <mpolacek@gcc.gnu.org> | 2014-01-23 21:01:08 +0000 |
commit | 393e8e8b0ca526d8909ace6303785dd522b1c8ce (patch) | |
tree | 98eae88584be77108a2375e808287ccd88b48a78 | |
parent | 6e23f2967868d307d367385411a5e61e6de2c02b (diff) | |
download | gcc-393e8e8b0ca526d8909ace6303785dd522b1c8ce.zip gcc-393e8e8b0ca526d8909ace6303785dd522b1c8ce.tar.gz gcc-393e8e8b0ca526d8909ace6303785dd522b1c8ce.tar.bz2 |
re PR c/59846 (Imprecise column number for -Wtype-limits)
PR c/59846
c-family/
* c-common.c (shorten_compare): Add location_t parameter.
* c-common.h (shorten_binary_op): Adjust declaration.
cp/
* typeck.c (cp_build_binary_op): Pass location to shorten_compare.
c/
* c-typeck.c (parser_build_binary_op): Use location instead of
input_location.
(build_binary_op): Pass location to shorten_compare.
testsuite/
* gcc.dg/pr59846.c: New test.
From-SVN: r207008
-rw-r--r-- | gcc/c-family/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/c-family/c-common.c | 7 | ||||
-rw-r--r-- | gcc/c-family/c-common.h | 3 | ||||
-rw-r--r-- | gcc/c/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/c/c-typeck.c | 9 | ||||
-rw-r--r-- | gcc/cp/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/cp/typeck.c | 3 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr59846.c | 39 |
9 files changed, 75 insertions, 9 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index cba9f4e..34c1660 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,5 +1,11 @@ 2014-01-23 Marek Polacek <polacek@redhat.com> + PR c/59846 + * c-common.c (shorten_compare): Add location_t parameter. + * c-common.h (shorten_binary_op): Adjust declaration. + +2014-01-23 Marek Polacek <polacek@redhat.com> + PR c/58346 * c-common.c (pointer_to_zero_sized_aggr_p): New function. * c-common.h: Declare it. diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 0912801..86cec72 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -3974,13 +3974,15 @@ expr_original_type (tree expr) of build_binary_op: OP0_PTR is &OP0, OP1_PTR is &OP1, RESTYPE_PTR is &RESULT_TYPE and RESCODE_PTR is &RESULTCODE. + LOC is the location of the comparison. + If this function returns nonzero, it means that the comparison has a constant value. What this function returns is an expression for that value. */ tree -shorten_compare (tree *op0_ptr, tree *op1_ptr, tree *restype_ptr, - enum tree_code *rescode_ptr) +shorten_compare (location_t loc, tree *op0_ptr, tree *op1_ptr, + tree *restype_ptr, enum tree_code *rescode_ptr) { tree type; tree op0 = *op0_ptr; @@ -3989,7 +3991,6 @@ shorten_compare (tree *op0_ptr, tree *op1_ptr, tree *restype_ptr, int real1, real2; tree primop0, primop1; enum tree_code code = *rescode_ptr; - location_t loc = EXPR_LOC_OR_LOC (op0, input_location); /* Throw away any conversions to wider types already present in the operands. */ diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index dab0b8c..d7077fd 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -800,7 +800,8 @@ extern tree shorten_binary_op (tree result_type, tree op0, tree op1, bool bitwis /* Subroutine of build_binary_op, used for comparison operations. See if the operands have both been converted from subword integer types and, if so, perhaps change them both back to their original type. */ -extern tree shorten_compare (tree *, tree *, tree *, enum tree_code *); +extern tree shorten_compare (location_t, tree *, tree *, tree *, + enum tree_code *); extern tree pointer_int_sum (location_t, enum tree_code, tree, tree, bool = true); diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 4088912..834c420 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,5 +1,12 @@ 2014-01-23 Marek Polacek <polacek@redhat.com> + PR c/59846 + * c-typeck.c (parser_build_binary_op): Use location instead of + input_location. + (build_binary_op): Pass location to shorten_compare. + +2014-01-23 Marek Polacek <polacek@redhat.com> + PR c/58346 * c-typeck.c (pointer_diff): Give an error on arithmetic on pointer to an empty aggregate. diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index 77f3bdd..f71bea4 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -3388,11 +3388,11 @@ parser_build_binary_op (location_t location, enum tree_code code, /* Check for cases such as x+y<<z which users are likely to misinterpret. */ if (warn_parentheses) - warn_about_parentheses (input_location, code, - code1, arg1.value, code2, arg2.value); + warn_about_parentheses (location, code, code1, arg1.value, code2, + arg2.value); if (warn_logical_op) - warn_logical_operator (input_location, code, TREE_TYPE (result.value), + warn_logical_operator (location, code, TREE_TYPE (result.value), code1, arg1.value, code2, arg2.value); /* Warn about comparisons against string literals, with the exception @@ -10891,7 +10891,8 @@ build_binary_op (location_t location, enum tree_code code, tree xop0 = op0, xop1 = op1, xresult_type = result_type; enum tree_code xresultcode = resultcode; tree val - = shorten_compare (&xop0, &xop1, &xresult_type, &xresultcode); + = shorten_compare (location, &xop0, &xop1, &xresult_type, + &xresultcode); if (val != 0) { diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index aee3fcf..e663170 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,10 @@ 2014-01-23 Marek Polacek <polacek@redhat.com> + PR c/59846 + * typeck.c (cp_build_binary_op): Pass location to shorten_compare. + +2014-01-23 Marek Polacek <polacek@redhat.com> + PR c/58346 * typeck.c (pointer_diff): Give an error on arithmetic on pointer to an empty aggregate. diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 9cd6a95..f40f309 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -4838,7 +4838,8 @@ cp_build_binary_op (location_t location, tree xop0 = op0, xop1 = op1, xresult_type = result_type; enum tree_code xresultcode = resultcode; tree val - = shorten_compare (&xop0, &xop1, &xresult_type, &xresultcode); + = shorten_compare (location, &xop0, &xop1, &xresult_type, + &xresultcode); if (val != 0) return cp_convert (boolean_type_node, val, complain); op0 = xop0, op1 = xop1; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f3d8d3a..47352e1 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,10 @@ 2014-01-23 Marek Polacek <polacek@redhat.com> + PR c/59846 + * gcc.dg/pr59846.c: New test. + +2014-01-23 Marek Polacek <polacek@redhat.com> + PR c/58346 * c-c++-common/pr58346-1.c: New test. * c-c++-common/pr58346-2.c: New test. diff --git a/gcc/testsuite/gcc.dg/pr59846.c b/gcc/testsuite/gcc.dg/pr59846.c new file mode 100644 index 0000000..e002fba --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr59846.c @@ -0,0 +1,39 @@ +/* PR c/59846 */ +/* { dg-do compile } */ +/* { dg-options "-Wlogical-op -Wtype-limits" } */ + +_Bool +fn1 (unsigned int p) +{ + return 0UL > p; /* { dg-warning "14:comparison is always false due to limited range of data type" } */ +} + +_Bool +fn2 (unsigned int p) +{ + return 0UL <= p; /* { dg-warning "14:comparison is always true due to limited range of data type" } */ +} + +_Bool +fn3 (unsigned int p) +{ + return p >= 0U; /* { dg-warning "12:comparison of unsigned expression >= 0 is always true" } */ +} + +_Bool +fn4 (unsigned int p) +{ + return p < 0U; /* { dg-warning "12:comparison of unsigned expression < 0 is always false" } */ +} + +_Bool +fn5 (_Bool p) +{ + return p || !p; /* { dg-warning "12:logical" } */ +} + +_Bool +fn6 (_Bool p) +{ + return p && !p; /* { dg-warning "12:logical" } */ +} |