summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEdward O'Callaghan <[email protected]>2016-12-06 11:28:56 +1100
committerEdward O'Callaghan <[email protected]>2016-12-21 15:00:21 +1100
commit8801734da701d95608e39d829e0a31a191ee68f2 (patch)
tree1ca2b2df98ab04d6fd29db8b5f102300f17ea26a /src
parente827d9175675aaa6cfc0b981e2a80685fb7b3a74 (diff)
svga: Fix a strict-aliasing violation in shader dumper
As per the C spec, it is illegal to alias pointers to different types. This results in undefined behaviour after optimization passes, resulting in very subtle bugs that happen only on a full moon.. Use a memcpy() as a well defined coercion between the isomorphic bit-field interpretations of memory. V.2: Use C99 compat STATIC_ASSERT() over C11 static_assert(). Signed-off-by: Edward O'Callaghan <[email protected]> Reviewed-by: Charmaine Lee <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/gallium/drivers/svga/svgadump/svga_shader_dump.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/gallium/drivers/svga/svgadump/svga_shader_dump.c b/src/gallium/drivers/svga/svgadump/svga_shader_dump.c
index 4ee1bf2c353..46126a5460d 100644
--- a/src/gallium/drivers/svga/svgadump/svga_shader_dump.c
+++ b/src/gallium/drivers/svga/svgadump/svga_shader_dump.c
@@ -30,6 +30,9 @@
* @author Michal Krol <[email protected]>
*/
+#include <assert.h>
+#include <string.h>
+
#include "svga_shader.h"
#include "svga_shader_dump.h"
#include "svga_shader_op.h"
@@ -413,6 +416,11 @@ dump_dstreg(struct sh_dstreg dstreg,
static void dump_srcreg( struct sh_srcreg srcreg, struct sh_srcreg *indreg, const struct dump_info *di )
{
+ struct sh_reg srcreg_sh = {0};
+ /* bit-fields carefully aligned, ensure they stay that way. */
+ STATIC_ASSERT(sizeof(struct sh_reg) == sizeof(struct sh_srcreg));
+ memcpy(&srcreg_sh, &srcreg, sizeof(srcreg_sh));
+
switch (srcreg.modifier) {
case SVGA3DSRCMOD_NEG:
case SVGA3DSRCMOD_BIASNEG:
@@ -427,7 +435,7 @@ static void dump_srcreg( struct sh_srcreg srcreg, struct sh_srcreg *indreg, cons
case SVGA3DSRCMOD_NOT:
_debug_printf( "!" );
}
- dump_reg( *(struct sh_reg *) &srcreg, indreg, di );
+ dump_reg(srcreg_sh, indreg, di );
switch (srcreg.modifier) {
case SVGA3DSRCMOD_NONE:
case SVGA3DSRCMOD_NEG: