aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/pr53265.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2013-03-14 10:13:36 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2013-03-14 10:13:36 +0100
commitfbd28bc3b2c3394db09577ff2f5a594d50c75b2c (patch)
tree20df72f941802d316ad1e5b63a60b221cc29586a /gcc/testsuite/gcc.dg/pr53265.c
parentdf2dfaea4e76a6159e733073aff5aa5e6837289a (diff)
downloadgcc-fbd28bc3b2c3394db09577ff2f5a594d50c75b2c.zip
gcc-fbd28bc3b2c3394db09577ff2f5a594d50c75b2c.tar.gz
gcc-fbd28bc3b2c3394db09577ff2f5a594d50c75b2c.tar.bz2
re PR tree-optimization/53265 (Warn when undefined behavior implies smaller iteration count)
PR tree-optimization/53265 * common.opt (Waggressive-loop-optimizations): New option. * tree-ssa-loop-niter.c: Include tree-pass.h. (do_warn_aggressive_loop_optimizations): New function. (record_estimate): Call it. Don't add !is_exit bounds to loop->bounds if number_of_latch_executions returned constant. (estimate_numbers_of_iterations_loop): Call number_of_latch_executions early. If number_of_latch_executions returned constant, set nb_iterations_upper_bound back to it. * cfgloop.h (struct loop): Add warned_aggressive_loop_optimizations field. * Makefile.in (tree-ssa-loop-niter.o): Depend on $(TREE_PASS_H). * doc/invoke.texi (-Wno-aggressive-loop-optimizations): Document. * gcc.dg/pr53265.c: New test. * gcc.dg/torture/pr49518.c: Add -Wno-aggressive-loop-optimizations to dg-options. * g++.dg/opt/longbranch2.C (EBCOTLut): Double sizes of a2 and a3 arrays. * gcc.dg/tree-ssa/cunroll-10.c (main): Rename to foo. Add argument n, use it as high bound instead of 4. * unwind-dw2.c (execute_cfa_program): Avoid -Waggressive-array-optimizations warnings for DW_CFA_GNU_window_save on targets with DWARF_FRAME_REGISTERS < 32. * testsuite/libmudflap.c/fail37-frag.c: Add optimization barrier. From-SVN: r196650
Diffstat (limited to 'gcc/testsuite/gcc.dg/pr53265.c')
-rw-r--r--gcc/testsuite/gcc.dg/pr53265.c156
1 files changed, 156 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/pr53265.c b/gcc/testsuite/gcc.dg/pr53265.c
new file mode 100644
index 0000000..c60a736
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr53265.c
@@ -0,0 +1,156 @@
+/* PR tree-optimization/53265 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -Wall" } */
+
+void bar (void *);
+int baz (int);
+
+void
+fn1 (void)
+{
+ unsigned int a[128];
+ int i;
+
+ for (i = 0; i < 128; ++i) /* { dg-message "note: containing loop" } */
+ a[i] = i * 0x02000001; /* { dg-warning "invokes undefined behavior" } */
+ bar (a);
+}
+
+void
+fn2 (void)
+{
+ unsigned long long a[128];
+ int i;
+
+ for (i = 0; i < 128; i++) /* { dg-message "note: containing loop" } */
+ a[i] = (i + 1LL) * 0x0123456789ABCDEFLL; /* { dg-warning "invokes undefined behavior" } */
+ bar (a);
+}
+
+void
+fn3 (void)
+{
+ unsigned char a[16], b[16], c[16];
+ int i;
+
+ bar (b);
+ for (i = 0; i < (int) (sizeof (a) / sizeof (a[0])); i++) /* { dg-message "note: containing loop" } */
+ {
+ c[i + 8] = b[i]; /* { dg-warning "invokes undefined behavior" } */
+ a[i + 8] = b[i + 8];
+ }
+ bar (a);
+ bar (c);
+}
+
+void
+fn4 (void)
+{
+ unsigned int *a[32], *o, i;
+
+ bar (a);
+ for (i = 0; i <= sizeof (a) / sizeof (a[0]); i++) /* { dg-message "note: containing loop" "" { xfail *-*-* } } */
+ {
+ o = a[i]; /* { dg-warning "invokes undefined behavior" "" { xfail *-*-* } } */
+ bar (o);
+ }
+}
+
+void
+fn5 (void)
+{
+ unsigned short a[23940];
+ unsigned int b[1140];
+ int j;
+
+ bar (b);
+ for (j = 0; j < 1140; j++) /* { dg-message "note: containing loop" } */
+ a[23940 + j - 950] = b[j]; /* { dg-warning "invokes undefined behavior" } */
+ bar (a);
+}
+
+void
+fn6 (void)
+{
+ double a[4][3], b[12];
+ int i;
+ bar (b);
+ for (i = 0; i < 12; i++) /* { dg-message "note: containing loop" } */
+ a[0][i] = b[i] / 10000.0; /* { dg-warning "invokes undefined behavior" } */
+ bar (a);
+}
+
+void
+fn7 (void)
+{
+ int a[16], b, c;
+ bar (a);
+ for (b = a[c = 0]; c < 16; b = a[++c]) /* { dg-warning "invokes undefined behavior" "" { xfail *-*-* } } */
+ baz (b);
+}
+
+/* { dg-message "note: containing loop" "" { xfail *-*-* } 88 } */
+
+const void *va, *vb, *vc, *vd, *ve;
+const void *vf[4];
+void
+fn8 (void)
+{
+ unsigned long i;
+ vf[0] = va; vf[1] = vb; vf[2] = vc; vf[3] = vd;
+ for (i = 0; i < (sizeof (vf) / sizeof (vf[0])); i++)
+ if (!vf[i])
+ vf[i] = ve;
+}
+
+int wa, wb[53][5], wc[53][5];
+
+void
+fn9 (void)
+{
+ int i, j, k;
+ for (i = 0; i < 53; i++)
+ for (j = 16 / (((wa & 1) != 0) ? 8 : 4); j > 0; j--)
+ {
+ int d = 1;
+ if (wb[i][j] == 0 || wc[i][1] != 0)
+ continue;
+ for (k = 0; k < j; k++)
+ if (wc[i + k][1])
+ {
+ d = 0;
+ break;
+ }
+ if (!d)
+ continue;
+ wc[i][j] = baz (0);
+ }
+}
+
+int xa[18];
+
+void
+fn10 (void)
+{
+ int i;
+ for (i = 16; i < 32; i++) /* { dg-message "note: containing loop" } */
+ xa[i] = 26; /* { dg-warning "invokes undefined behavior" } */
+}
+
+__attribute__((noinline)) static void
+fn11 (int x)
+{
+ int i = 1;
+ if (x > 1)
+ do
+ baz (i);
+ while (++i != x); /* { dg-bogus "invokes undefined behavior" } */
+}
+
+void
+fn12 (void)
+{
+ fn11 (1);
+ fn11 (1);
+ fn11 (1);
+}