From: Alexandre Oliva Date: Fri, 6 Jan 2017 03:34:37 +0000 (+0000) Subject: [bootstrap-O3,fortran] silence warning in simplify_transformation_to_array X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e1d070a4f7128f98c1d5aa504ec44f41d0ac1a5a;p=gcc.git [bootstrap-O3,fortran] silence warning in simplify_transformation_to_array simplify_transformation_to_array had the nested loop unrolled 7 times, which is reasonable given that it iterates over arrays of size GFC_MAX_DIMENSIONS == 7. The problem is that the last iteration increments the index, tests that it's less than result->rank, and then accesses the arrays with the incremented index. We did not optimize out that part in the 7th iteration, so VRP flagged the unreachable code as accessing arrays past the end. It couldn't possibly know that we'd never reach that part, since the test was on result->rank, and it's not obvious (for the compiler) that result->rank <= GFC_MAX_DIMENSIONS. Even an assert to that effect before the enclosing loop didn't avoid the warning turned to error, though; I suppose there might be some aliasing at play, because moving the assert into the loop does. An assert on the index itself would also work, even more efficiently, but we're just silencing the warning instead. for gcc/fortran/ChangeLog * simplify.c (simplify_transformation_to_array): Silence array bounds warning. Fix whitespace. From-SVN: r244122 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 95c5279e48c..d1892de8bb1 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,8 @@ +2017-01-06 Alexandre Oliva + + * simplify.c (simplify_transformation_to_array): Silence + array bounds warning. Fix whitespace. + 2017-01-04 Alexandre Oliva * module.c (load_omp_udrs): Initialize name. diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c index a5a50de5cab..c5e7b671691 100644 --- a/gcc/fortran/simplify.c +++ b/gcc/fortran/simplify.c @@ -610,9 +610,18 @@ simplify_transformation_to_array (gfc_expr *result, gfc_expr *array, gfc_expr *d n++; if (n < result->rank) { - count [n]++; +#pragma GCC diagnostic push + /* If the nested loop is unrolled GFC_MAX_DIMENSIONS + times, we'd warn for the last iteration, because the + array index will have already been incremented to the + array sizes, and we can't tell that this must make + the test against result->rank false, because ranks + must not exceed GFC_MAX_DIMENSIONS. */ +#pragma GCC diagnostic ignored "-Warray-bounds" + count[n]++; base += sstride[n]; dest += dstride[n]; +#pragma GCC diagnostic pop } else done = true;