r600/sb: cleanup if_conversion iterator to be legal C++
authorDave Airlie <airlied@redhat.com>
Fri, 29 Jun 2018 02:47:26 +0000 (03:47 +0100)
committerDave Airlie <airlied@redhat.com>
Wed, 4 Jul 2018 06:42:22 +0000 (07:42 +0100)
The current code causes:
/usr/include/c++/8/debug/safe_iterator.h:207:
Error: attempt to copy from a singular iterator.

This is due to the iterators getting invalidated, fix the
reverse iterator to use the return value from erase, and
cast it properly.

(used Mathias suggestion)
Cc: <mesa-stable@lists.freedesktop.org>
Reviewed-by: Mathias Fröhlich <mathias.froehlich@web.de>
src/gallium/drivers/r600/sb/sb_if_conversion.cpp

index 3f6431b80f5dc0dd25e92cd37cbbbcc3d7fe091f..017153434fcaaf6e500f29f9f4f81eaaa3e64aac 100644 (file)
@@ -42,16 +42,13 @@ int if_conversion::run() {
        regions_vec &rv = sh.get_regions();
 
        unsigned converted = 0;
-
-       for (regions_vec::reverse_iterator N, I = rv.rbegin(), E = rv.rend();
-                       I != E; I = N) {
-               N = I; ++N;
-
+       for (regions_vec::reverse_iterator I = rv.rbegin(); I != rv.rend(); ) {
                region_node *r = *I;
                if (run_on(r)) {
-                       rv.erase(I.base() - 1);
+                       I = regions_vec::reverse_iterator(rv.erase((++I).base()));
                        ++converted;
-               }
+               } else
+                       ++I;
        }
        return 0;
 }