diff options
author | Martin Sebor <msebor@redhat.com> | 2019-08-30 17:42:57 +0000 |
---|---|---|
committer | Martin Sebor <msebor@gcc.gnu.org> | 2019-08-30 11:42:57 -0600 |
commit | 5d69df7e9292522d00100b79f84a982359ed8142 (patch) | |
tree | a657da3d6c4925872955670e1b22d00b7f31c902 | |
parent | 7259a9d577b05735ccbb8bf808d14a702bf6d8c2 (diff) | |
download | gcc-5d69df7e9292522d00100b79f84a982359ed8142.zip gcc-5d69df7e9292522d00100b79f84a982359ed8142.tar.gz gcc-5d69df7e9292522d00100b79f84a982359ed8142.tar.bz2 |
PR middle-end/91584 - Bogus warning from -Warray-bounds during string assignment
gcc/ChangeLog:
PR middle-end/91584
* tree-vrp.c (vrp_prop::check_mem_ref): Normalize type domain bounds
before using them to validate MEM_REF offset.
gcc/testsuite/ChangeLog:
* gfortran.dg/char_array_constructor_4.f90: New test.
From-SVN: r275210
-rw-r--r-- | gcc/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gfortran.dg/char_array_constructor_4.f90 | 13 | ||||
-rw-r--r-- | gcc/tree-vrp.c | 23 |
4 files changed, 31 insertions, 16 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e9226d8..45dd3a2 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2019-08-30 Martin Sebor <msebor@redhat.com> + + PR middle-end/91584 + * tree-vrp.c (vrp_prop::check_mem_ref): Normalize type domain bounds + before using them to validate MEM_REF offset. + 2019-08-30 Marek Polacek <polacek@redhat.com> * doc/invoke.texi (-Wvolatile): Use @code for volatile. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 715c417..420ddd4 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-08-30 Martin Sebor <msebor@redhat.com> + + PR middle-end/91584 + * gfortran.dg/char_array_constructor_4.f90: New test. + 2019-08-30 Eric Botcazou <ebotcazou@adacore.com> * gnat.dg/pack24.adb: New test. diff --git a/gcc/testsuite/gfortran.dg/char_array_constructor_4.f90 b/gcc/testsuite/gfortran.dg/char_array_constructor_4.f90 new file mode 100644 index 0000000..e7c68f9 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/char_array_constructor_4.f90 @@ -0,0 +1,13 @@ +! PR 30319 - Bogus warning from -Warray-bounds during string assignment +! { dg-do compile } +! { dg-options "-O2 -Warray-bounds" } + +program test_bounds + + character(256) :: foo + + foo = '1234' ! { dg-bogus "\\\[-Warray-bounds" } + + print *, foo + +end program test_bounds diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index c95b5ad..bc06480 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -4703,31 +4703,23 @@ vrp_prop::check_mem_ref (location_t location, tree ref, || RECORD_OR_UNION_TYPE_P (reftype)) return false; + arrbounds[0] = 0; + offset_int eltsize; if (TREE_CODE (reftype) == ARRAY_TYPE) { eltsize = wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (reftype))); - if (tree dom = TYPE_DOMAIN (reftype)) { tree bnds[] = { TYPE_MIN_VALUE (dom), TYPE_MAX_VALUE (dom) }; - if (array_at_struct_end_p (arg) - || !bnds[0] || !bnds[1]) - { - arrbounds[0] = 0; - arrbounds[1] = wi::lrshift (maxobjsize, wi::floor_log2 (eltsize)); - } + if (array_at_struct_end_p (arg) || !bnds[0] || !bnds[1]) + arrbounds[1] = wi::lrshift (maxobjsize, wi::floor_log2 (eltsize)); else - { - arrbounds[0] = wi::to_offset (bnds[0]) * eltsize; - arrbounds[1] = (wi::to_offset (bnds[1]) + 1) * eltsize; - } + arrbounds[1] = (wi::to_offset (bnds[1]) - wi::to_offset (bnds[0]) + + 1) * eltsize; } else - { - arrbounds[0] = 0; - arrbounds[1] = wi::lrshift (maxobjsize, wi::floor_log2 (eltsize)); - } + arrbounds[1] = wi::lrshift (maxobjsize, wi::floor_log2 (eltsize)); if (TREE_CODE (ref) == MEM_REF) { @@ -4742,7 +4734,6 @@ vrp_prop::check_mem_ref (location_t location, tree ref, else { eltsize = 1; - arrbounds[0] = 0; arrbounds[1] = wi::to_offset (TYPE_SIZE_UNIT (reftype)); } |