Mesa (master): st/mesa: define ST_NEW_ flags as uint64_t values, not enums

Brian Paul brianp at kemper.freedesktop.org
Tue Aug 9 13:51:37 UTC 2016


Module: Mesa
Branch: master
Commit: 60dc36a680ff0f768647d928395e19e4fdffa68d
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=60dc36a680ff0f768647d928395e19e4fdffa68d

Author: Brian Paul <brianp at vmware.com>
Date:   Mon Aug  8 16:37:00 2016 -0600

st/mesa: define ST_NEW_ flags as uint64_t values, not enums

MSVC doesn't support 64-bit enum values, at least not with C code.
The compiler was warning:

c:\users\brian\projects\mesa\src\mesa\state_tracker\st_atom_list.h(43) : warning
 C4309: 'initializing' : truncation of constant value
c:\users\brian\projects\mesa\src\mesa\state_tracker\st_atom_list.h(44) : warning
 C4309: 'initializing' : truncation of constant value
...

And at runtime we crashed since the high 32-bits of the 'dirty' bitmask
was always 0xffffffff and the 32+u_bit_scan() index went out of bounds of
the atoms[] array.

Reviewed-by: Marek Olšák <marek.olsak at amd.com>
Reviewed-by: Nicolai Hähnle <nicolai.haehnle at amd.com>

---

 src/mesa/state_tracker/st_atom.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/mesa/state_tracker/st_atom.h b/src/mesa/state_tracker/st_atom.h
index febd7ce..971ea35 100644
--- a/src/mesa/state_tracker/st_atom.h
+++ b/src/mesa/state_tracker/st_atom.h
@@ -68,12 +68,12 @@ enum {
 #undef ST_STATE
 };
 
-/* Define ST_NEW_xxx */
-enum {
-#define ST_STATE(FLAG, st_update) FLAG = 1llu << FLAG##_INDEX,
+/* Define ST_NEW_xxx values as static const uint64_t values.
+ * We can't use an enum type because MSVC doesn't allow 64-bit enum values.
+ */
+#define ST_STATE(FLAG, st_update) static const uint64_t FLAG = 1llu << FLAG##_INDEX;
 #include "st_atom_list.h"
 #undef ST_STATE
-};
 
 /* Add extern struct declarations. */
 #define ST_STATE(FLAG, st_update) extern const struct st_tracked_state st_update;




More information about the mesa-commit mailing list