From 97b40c39208e384fd3ead463b85cddda9e55a375 Mon Sep 17 00:00:00 2001 From: Martin Sebor Date: Thu, 30 Jan 2020 08:46:23 -0700 Subject: [PATCH] PR middle-end/92323 - bogus -Warray-bounds after unrolling despite __builtin_unreachable gcc/testsuite/ChangeLog: * gcc.dg/Warray-bounds-57.c: New test. --- gcc/testsuite/ChangeLog | 5 +++ gcc/testsuite/gcc.dg/Warray-bounds-57.c | 53 +++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/Warray-bounds-57.c diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a97bf325013..0247d2cd083 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2020-01-30 Martin Sebor + + PR middle-end/92323 + * gcc.dg/Warray-bounds-57.c: New test. + 2020-01-30 David Malcolm PR analyzer/93450 diff --git a/gcc/testsuite/gcc.dg/Warray-bounds-57.c b/gcc/testsuite/gcc.dg/Warray-bounds-57.c new file mode 100644 index 00000000000..97e9ce47bc8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/Warray-bounds-57.c @@ -0,0 +1,53 @@ +/* PR middle-end/92323 - bogus -Warray-bounds after unrolling despite + __builtin_unreachable + { dg-do compile } + { dg-options "-O2 -Wall" } */ + +struct S { int a[5]; } s; + +void sink (void*); + +#pragma GCC optimize "2" + +void f_O2 (unsigned n, struct S *p) +{ + for (unsigned i = 1; i < n - 1; ++i) + s.a[i - 1] = p->a[i]; // { dg-bogus "\\\[-Warray-bounds" } + + if (n < 4 || n > 5) + __builtin_unreachable (); +} + +void g_O2 (unsigned n, struct S *p) +{ + if (n < 4 || n > 5) + __builtin_unreachable (); + + for (unsigned i = 1; i < n - 1; ++i) + s.a[i - 1] = p->a[i]; +} + + +// Also exercise -O3 with loop unrolling for good measure. + +#pragma GCC optimize "3" + +struct T { int a[6]; } t; + +void f_O3 (unsigned n, struct T *p) +{ + for (unsigned i = 1; i < n - 1; ++i) + t.a[i - 1] = p->a[i]; // { dg-bogus "\\\[-Warray-bounds" } + + if (n < 5 || n > 6) + __builtin_unreachable (); +} + +void g_O3 (unsigned n, struct T *p) +{ + if (n < 5 || n > 6) + __builtin_unreachable (); + + for (unsigned i = 1; i < n - 1; ++i) + s.a[i - 1] = p->a[i]; +} -- 2.30.2