[Mesa-dev] [PATCH 5/5] glsl/linker: Safely generate mask of possible locations
Ian Romanick
idr at freedesktop.org
Sat Jan 6 05:40:34 UTC 2018
From: Ian Romanick <ian.d.romanick at intel.com>
If MaxAttribs were ever raised to 32, undefined behavior would occur.
We had already gone to the effort (albeit incorrectly) handle this in
one case, so fix them all.
CID: 1369628
Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
src/compiler/glsl/linker.cpp | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp
index 010f591..04c8692 100644
--- a/src/compiler/glsl/linker.cpp
+++ b/src/compiler/glsl/linker.cpp
@@ -2564,6 +2564,8 @@ find_available_slots(unsigned used_mask, unsigned needed_count)
}
+#define SAFE_MASK_FROM_INDEX(i) (((i) >= 32) ? ~0 : ((1 << (i)) - 1))
+
/**
* Assign locations for either VS inputs or FS outputs
*
@@ -2594,8 +2596,7 @@ assign_attribute_or_color_locations(void *mem_ctx,
/* Mark invalid locations as being used.
*/
- unsigned used_locations = (max_index >= 32)
- ? 0 : ~((1 << max_index) - 1);
+ unsigned used_locations = ~SAFE_MASK_FROM_INDEX(max_index);
unsigned double_storage_locations = 0;
assert((target_index == MESA_SHADER_VERTEX)
@@ -2948,7 +2949,7 @@ assign_attribute_or_color_locations(void *mem_ctx,
if (target_index == MESA_SHADER_VERTEX) {
unsigned total_attribs_size =
- _mesa_bitcount(used_locations & ((1 << max_index) - 1)) +
+ _mesa_bitcount(used_locations & SAFE_MASK_FROM_INDEX(max_index)) +
_mesa_bitcount(double_storage_locations);
if (total_attribs_size > max_index) {
linker_error(prog,
@@ -3012,7 +3013,7 @@ assign_attribute_or_color_locations(void *mem_ctx,
*/
if (target_index == MESA_SHADER_VERTEX) {
unsigned total_attribs_size =
- _mesa_bitcount(used_locations & ((1 << max_index) - 1)) +
+ _mesa_bitcount(used_locations & SAFE_MASK_FROM_INDEX(max_index)) +
_mesa_bitcount(double_storage_locations);
if (total_attribs_size > max_index) {
linker_error(prog,
--
2.9.5
More information about the mesa-dev
mailing list