From 12d2dc5e67905a22e0bf6d8b4a49b1ce246284a8 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Mon, 18 Mar 2013 08:10:33 +0100 Subject: [PATCH] re PR c/56566 (bogus "is narrower than values of its type" warning) PR c/56566 * tree.c (tree_int_cst_min_precision): For integer_zerop (value) return 1 even for !unsignedp. * c-c++-common/pr56566.c: New test. From-SVN: r196767 --- gcc/ChangeLog | 6 ++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/c-c++-common/pr56566.c | 14 ++++++++++++++ gcc/tree.c | 12 +++++------- 4 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/pr56566.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index df6116d3684..c91609e89c2 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2013-03-18 Jakub Jelinek + + PR c/56566 + * tree.c (tree_int_cst_min_precision): For integer_zerop (value) + return 1 even for !unsignedp. + 2013-03-17 Uros Bizjak * config/i386/i386.md (isa): Add x64 and nox64. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 0f4a5c4a6df..8f14a53cdb4 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2013-03-18 Jakub Jelinek + + PR c/56566 + * c-c++-common/pr56566.c: New test. + 2013-03-17 Jason Merrill * g++.dg/template/abstract-dr337.C: XFAIL. diff --git a/gcc/testsuite/c-c++-common/pr56566.c b/gcc/testsuite/c-c++-common/pr56566.c new file mode 100644 index 00000000000..e753d933a4f --- /dev/null +++ b/gcc/testsuite/c-c++-common/pr56566.c @@ -0,0 +1,14 @@ +/* PR c/56566 */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +struct S1 { enum E1 { N1 = -1, Z1 = 0 } e : 1; }; +struct S2 { enum E2 { N2 = -1 } e : 1; }; +struct S3 { enum E3 { Z3 = 0 } e : 1; }; +struct S4 { enum E4 { N4 = -2, Z4 = 1 } e : 2; }; +struct S5 { enum E5 { N5 = -3, Z5 = 1 } e : 3; }; +struct S6 { enum E6 { N6 = -2, Z6 = 1 } e : 1; }; // { dg-warning "too small|narrower" } +struct S7 { enum E7 { N7 = -3, Z7 = 1 } e : 2; }; // { dg-warning "too small|narrower" } +struct S8 { enum E8 { Z8 = 1 } e : 1; }; +struct S9 { enum E9 { Z9 = 2 } e : 2; }; +struct S0 { enum E0 { Z0 = 2 } e : 1; }; // { dg-warning "too small|narrower" } diff --git a/gcc/tree.c b/gcc/tree.c index 98ad5d8784b..31f8037deb8 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -6648,8 +6648,6 @@ tree_int_cst_sgn (const_tree t) unsigned int tree_int_cst_min_precision (tree value, bool unsignedp) { - int log; - /* If the value is negative, compute its negative minus 1. The latter adjustment is because the absolute value of the largest negative value is one larger than the largest positive value. This is equivalent to @@ -6659,14 +6657,14 @@ tree_int_cst_min_precision (tree value, bool unsignedp) value = fold_build1 (BIT_NOT_EXPR, TREE_TYPE (value), value); /* Return the number of bits needed, taking into account the fact - that we need one more bit for a signed than unsigned type. */ + that we need one more bit for a signed than unsigned type. + If value is 0 or -1, the minimum precision is 1 no matter + whether unsignedp is true or false. */ if (integer_zerop (value)) - log = 0; + return 1; else - log = tree_floor_log2 (value); - - return log + 1 + !unsignedp; + return tree_floor_log2 (value) + 1 + !unsignedp; } /* Compare two constructor-element-type constants. Return 1 if the lists