diff options
author | Martin Sebor <msebor@redhat.com> | 2019-08-28 16:43:56 +0000 |
---|---|---|
committer | Martin Sebor <msebor@gcc.gnu.org> | 2019-08-28 10:43:56 -0600 |
commit | 464969eb9b47eb2f24403c74c16769a58dbaa638 (patch) | |
tree | 821481a2cfc3a3c99c5d25b19c08cd56afef8e58 /gcc/testsuite/gcc.dg/Wstringop-overflow-15.c | |
parent | e2eee239811d4335f28ccdf7c2d9c490fcf6612d (diff) | |
download | gcc-464969eb9b47eb2f24403c74c16769a58dbaa638.zip gcc-464969eb9b47eb2f24403c74c16769a58dbaa638.tar.gz gcc-464969eb9b47eb2f24403c74c16769a58dbaa638.tar.bz2 |
PR tree-optimization/91457 - inconsistent warning for writing past the end of an array member
gcc/ChangeLog:
PR tree-optimization/91457
* builtins.c (component_size): New function.
(compute_objsize): Add argument. Handle ARRAY_REF and COMPONENT_REF.
* builtins.h (compute_objsize): Add argument.
* tree-ssa-strlen.c (handle_store): Handle no-warning bit.
* tree-vrp.c (vrp_prop::check_array_ref): Return warning result.
(vrp_prop::check_mem_ref): Same.
(vrp_prop::search_for_addr_array): Set no-warning bit.
(check_array_bounds): Same.
gcc/testsuite/ChangeLog:
PR tree-optimization/91457
* c-c++-common/Wstringop-overflow-2.c: New test.
* g++.dg/warn/Warray-bounds-8.C: New test.
* g++.dg/warn/Wstringop-overflow-3.C: New test.
* gcc.dg/Wstringop-overflow-15.c: New test.
From-SVN: r274997
Diffstat (limited to 'gcc/testsuite/gcc.dg/Wstringop-overflow-15.c')
-rw-r--r-- | gcc/testsuite/gcc.dg/Wstringop-overflow-15.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/Wstringop-overflow-15.c b/gcc/testsuite/gcc.dg/Wstringop-overflow-15.c new file mode 100644 index 0000000..12f8f9d --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wstringop-overflow-15.c @@ -0,0 +1,62 @@ +/* PR middle-end/91458 - inconsistent warning for writing past the end + of an array member + Verify that the -Wstringop-overflow detection doesn't cause an ICE + for either kind of VLAs (member and non-member). + Diagnosing the accesses is the subject of pr82608. + { dg-do compile } + { dg-options "-O2 -Wall -Wno-array-bounds" } */ + +void sink (void*); + +void vla_unbounded (int n) +{ + char a[n]; + + a[0] = 0; + a[1] = 1; + a[n] = n; // { dg-warning "\\\[-Wstringop-overflow" "pr82608" { xfail *-*-* } } + + sink (&a); +} + +void vla_bounded (int n) +{ + if (n > 32) + n = 32; + + char a[n]; + + a[0] = 0; + a[1] = 1; + a[n] = n; // { dg-warning "\\\[-Wstringop-overflow" "pr82608" { xfail *-*-* } } + a[69] = n; // { dg-warning "\\\[-Wstringop-overflow" "pr82608" { xfail *-*-* } } + + sink (&a); +} + + +void member_vla_unbounded (int n) +{ + struct S { char i, a[n]; } s; + + s.a[0] = 0; + s.a[1] = 1; + s.a[n] = n; // { dg-warning "\\\[-Wstringop-overflow" "pr82608" { xfail *-*-* } } + + sink (&s); +} + +void member_vla_bounded (int n) +{ + if (n > 32) + n = 32; + + struct S { char i, a[n]; } s; + + s.a[0] = 0; + s.a[1] = 1; + s.a[n] = n; // { dg-warning "\\\[-Wstringop-overflow" "pr82608" { xfail *-*-* } } + s.a[69] = n; // { dg-warning "\\\[-Wstringop-overflow" "pr82608" { xfail *-*-* } } + + sink (&s); +} |