diff options
author | jakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4> | 2017-10-17 14:47:15 +0000 |
---|---|---|
committer | jakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4> | 2017-10-17 14:47:15 +0000 |
commit | 94006c86adb9fa636de27c498ddcdccd4d202ccd (patch) | |
tree | 22125f468d889554891eb45ef85977d3e14da9a2 | |
parent | 12515af2d8c762cdb00e8864cf0a4ef74b571e83 (diff) | |
download | gcc-94006c86adb9fa636de27c498ddcdccd4d202ccd.tar.gz |
PR tree-optimization/82549
* fold-const.c (optimize_bit_field_compare, fold_truth_andor_1):
Formatting fixes. Instead of calling make_bit_field_ref with negative
bitpos return 0.
* gcc.c-torture/compile/pr82549.c: New test.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-7-branch@253816 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/fold-const.c | 52 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 27 | ||||
-rw-r--r-- | gcc/testsuite/gcc.c-torture/compile/pr82549.c | 9 |
4 files changed, 64 insertions, 31 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d7d3034b38f..3f2e1291de3 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2017-10-17 Jakub Jelinek <jakub@redhat.com> + + PR tree-optimization/82549 + * fold-const.c (optimize_bit_field_compare, fold_truth_andor_1): + Formatting fixes. Instead of calling make_bit_field_ref with negative + bitpos return 0. + 2017-10-13 Jakub Jelinek <jakub@redhat.com> PR target/82274 diff --git a/gcc/fold-const.c b/gcc/fold-const.c index a634fc90cae..aa6490a18f3 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -4040,21 +4040,20 @@ optimize_bit_field_compare (location_t loc, enum tree_code code, size_int (nbitsize - lbitsize - lbitpos)); if (! const_p) - /* If not comparing with constant, just rework the comparison - and return. */ - return fold_build2_loc (loc, code, compare_type, - fold_build2_loc (loc, BIT_AND_EXPR, unsigned_type, - make_bit_field_ref (loc, linner, lhs, - unsigned_type, - nbitsize, nbitpos, - 1, lreversep), - mask), - fold_build2_loc (loc, BIT_AND_EXPR, unsigned_type, - make_bit_field_ref (loc, rinner, rhs, - unsigned_type, - nbitsize, nbitpos, - 1, rreversep), - mask)); + { + if (nbitpos < 0) + return 0; + + /* If not comparing with constant, just rework the comparison + and return. */ + tree t1 = make_bit_field_ref (loc, linner, lhs, unsigned_type, + nbitsize, nbitpos, 1, lreversep); + t1 = fold_build2_loc (loc, BIT_AND_EXPR, unsigned_type, t1, mask); + tree t2 = make_bit_field_ref (loc, rinner, rhs, unsigned_type, + nbitsize, nbitpos, 1, rreversep); + t2 = fold_build2_loc (loc, BIT_AND_EXPR, unsigned_type, t2, mask); + return fold_build2_loc (loc, code, compare_type, t1, t2); + } /* Otherwise, we are handling the constant case. See if the constant is too big for the field. Warn and return a tree for 0 (false) if so. We do @@ -4085,6 +4084,9 @@ optimize_bit_field_compare (location_t loc, enum tree_code code, } } + if (nbitpos < 0) + return 0; + /* Single-bit compares should always be against zero. */ if (lbitsize == 1 && ! integer_zerop (rhs)) { @@ -5858,7 +5860,10 @@ fold_truth_andor_1 (location_t loc, enum tree_code code, tree truth_type, results. */ ll_mask = const_binop (BIT_IOR_EXPR, ll_mask, rl_mask); lr_mask = const_binop (BIT_IOR_EXPR, lr_mask, rr_mask); - if (lnbitsize == rnbitsize && xll_bitpos == xlr_bitpos) + if (lnbitsize == rnbitsize + && xll_bitpos == xlr_bitpos + && lnbitpos >= 0 + && rnbitpos >= 0) { lhs = make_bit_field_ref (loc, ll_inner, ll_arg, lntype, lnbitsize, lnbitpos, @@ -5882,10 +5887,14 @@ fold_truth_andor_1 (location_t loc, enum tree_code code, tree truth_type, Note that we still must mask the lhs/rhs expressions. Furthermore, the mask must be shifted to account for the shift done by make_bit_field_ref. */ - if ((ll_bitsize + ll_bitpos == rl_bitpos - && lr_bitsize + lr_bitpos == rr_bitpos) - || (ll_bitpos == rl_bitpos + rl_bitsize - && lr_bitpos == rr_bitpos + rr_bitsize)) + if (((ll_bitsize + ll_bitpos == rl_bitpos + && lr_bitsize + lr_bitpos == rr_bitpos) + || (ll_bitpos == rl_bitpos + rl_bitsize + && lr_bitpos == rr_bitpos + rr_bitsize)) + && ll_bitpos >= 0 + && rl_bitpos >= 0 + && lr_bitpos >= 0 + && rr_bitpos >= 0) { tree type; @@ -5954,6 +5963,9 @@ fold_truth_andor_1 (location_t loc, enum tree_code code, tree truth_type, } } + if (lnbitpos < 0) + return 0; + /* Construct the expression we will return. First get the component reference we will make. Unless the mask is all ones the width of that field, perform the mask operation. Then compare with the diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e0b75bfd1e9..7ceb78458d4 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,26 +1,31 @@ +2017-10-17 Jakub Jelinek <jakub@redhat.com> + + PR tree-optimization/82549 + * gcc.c-torture/compile/pr82549.c: New test. + 2017-10-16 Paul Thomas <pault@gcc.gnu.org> PR fortran/78512 - * gfortran.dg/associate_9.f03 : Remove XFAIL. - * gfortran.dg/associate_26.f90 : New test. + * gfortran.dg/associate_9.f03: Remove XFAIL. + * gfortran.dg/associate_26.f90: New test. PR fortran/80120 - * gfortran.dg/associate_27.f90 : New test. + * gfortran.dg/associate_27.f90: New test. PR fortran/81903 - * gfortran.dg/associate_28.f90 : New test. + * gfortran.dg/associate_28.f90: New test. PR fortran/82121 - * gfortran.dg/associate_29.f90 : New test. + * gfortran.dg/associate_29.f90: New test. PR fortran/67543 - * gfortran.dg/associate_30.f90 : New test. + * gfortran.dg/associate_30.f90: New test. 2017-10-16 Paul Thomas <pault@gcc.gnu.org> Backport from trunk PR fortran/81048 - * gfortran.dg/derived_init_4.f90 : New test. + * gfortran.dg/derived_init_4.f90: New test. 2017-10-13 Jakub Jelinek <jakub@redhat.com> @@ -2762,7 +2767,7 @@ PR fortran/80156 PR fortran/79382 - * gfortran.dg/dtio_23.f90 : Remove the dg-error and add the + * gfortran.dg/dtio_23.f90: Remove the dg-error and add the testcase for PR80156. Add a main programme that tests that the typebound generic is accessible. @@ -3098,13 +3103,13 @@ 2017-03-18 Paul Thomas <pault@gcc.gnu.org> PR fortran/79676 - * gfortran.dg/submodule_28.f08 : New test. + * gfortran.dg/submodule_28.f08: New test. 2017-03-18 Paul Thomas <pault@gcc.gnu.org> PR fortran/71838 - * gfortran.dg/submodule_26.f08 : New test. - * gfortran.dg/submodule_27.f08 : New test. + * gfortran.dg/submodule_26.f08: New test. + * gfortran.dg/submodule_27.f08: New test. 2017-03-17 Pat Haugen <pthaugen@us.ibm.com> diff --git a/gcc/testsuite/gcc.c-torture/compile/pr82549.c b/gcc/testsuite/gcc.c-torture/compile/pr82549.c new file mode 100644 index 00000000000..11525cde032 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr82549.c @@ -0,0 +1,9 @@ +/* PR tree-optimization/82549 */ + +int a, b[1]; + +int +main () +{ + return !a || b[-2] || b[-2]; +} |