[Mesa-dev] [PATCH 03/10] i965: Silence loop counter overflow warning

Ian Romanick idr at freedesktop.org
Thu Mar 10 18:25:12 UTC 2016


From: Ian Romanick <ian.d.romanick at intel.com>

I don't understand why the old code was bad, but the new code is fine.

brw_state_dump.c: In function ‘brw_debug_batch’:
brw_state_dump.c:677:4: warning: cannot optimize loop, the loop counter may overflow [-Wunsafe-loop-optimizations]
    for (i = 0; i < size / 4; i += 4) {
    ^
brw_state_dump.c:693:4: warning: cannot optimize loop, the loop counter may overflow [-Wunsafe-loop-optimizations]
    for (i = 0; i < size / 4; i += 4) {
    ^

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
 src/mesa/drivers/dri/i965/brw_state_dump.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_state_dump.c b/src/mesa/drivers/dri/i965/brw_state_dump.c
index 943b2a9..ba09537 100644
--- a/src/mesa/drivers/dri/i965/brw_state_dump.c
+++ b/src/mesa/drivers/dri/i965/brw_state_dump.c
@@ -674,7 +674,9 @@ dump_vs_constants(struct brw_context *brw, uint32_t offset, uint32_t size)
    uint32_t *as_uint = brw->batch.bo->virtual + offset;
    float *as_float = brw->batch.bo->virtual + offset;
 
-   for (unsigned i = 0; i < size / 4; i += 4) {
+   for (unsigned j = 0; j < size / 16; j++) {
+      const unsigned i = j * 4;
+
       batch_out(brw, name, offset, i, "%3d: (% f % f % f % f) (0x%08x 0x%08x 0x%08x 0x%08x)\n",
 		i / 4,
 		as_float[i], as_float[i + 1], as_float[i + 2], as_float[i + 3],
@@ -689,7 +691,9 @@ dump_wm_constants(struct brw_context *brw, uint32_t offset, uint32_t size)
    uint32_t *as_uint = brw->batch.bo->virtual + offset;
    float *as_float = brw->batch.bo->virtual + offset;
 
-   for (unsigned i = 0; i < size / 4; i += 4) {
+   for (unsigned j = 0; j < size / 16; j++) {
+      const unsigned i = j * 4;
+
       batch_out(brw, name, offset, i, "%3d: (% f % f % f % f) (0x%08x 0x%08x 0x%08x 0x%08x)\n",
 		i / 4,
 		as_float[i], as_float[i + 1], as_float[i + 2], as_float[i + 3],
-- 
2.5.0



More information about the mesa-dev mailing list