summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolai Hähnle <nicolai.haehnle@amd.com>2016-04-29 23:34:26 -0500
committerNicolai Hähnle <nicolai.haehnle@amd.com>2016-06-15 10:39:48 +0200
commit07fa473350e1933187427f09fc66238c522a042c (patch)
treeee673d4de5a098b3ed8a94b209e75e7d1d19c04c
parent8a56b09a226da100a5f092ca141461936778d4d3 (diff)
compiler/list: avoid downcasting sentinel nodes (v2)
This avoids undefined behaviour that crashes gcc's ubsan. v2: don't add a new macro (Ian Romanick)
-rw-r--r--src/compiler/glsl/opt_dead_code_local.cpp8
-rw-r--r--src/compiler/glsl/opt_tree_grafting.cpp9
2 files changed, 10 insertions, 7 deletions
diff --git a/src/compiler/glsl/opt_dead_code_local.cpp b/src/compiler/glsl/opt_dead_code_local.cpp
index d38fd2bf63..a35026e4c9 100644
--- a/src/compiler/glsl/opt_dead_code_local.cpp
+++ b/src/compiler/glsl/opt_dead_code_local.cpp
@@ -291,7 +291,8 @@ dead_code_local_basic_block(ir_instruction *first,
ir_instruction *last,
void *data)
{
- ir_instruction *ir, *ir_next;
+ ir_instruction *ir;
+ exec_node *ir_next;
/* List of avaialble_copy */
exec_list assignments;
bool *out_progress = (bool *)data;
@@ -299,8 +300,8 @@ dead_code_local_basic_block(ir_instruction *first,
void *ctx = ralloc_context(NULL);
/* Safe looping, since process_assignment */
- for (ir = first, ir_next = (ir_instruction *)first->next;;
- ir = ir_next, ir_next = (ir_instruction *)ir->next) {
+ for (ir = first, ir_next = first->next;;
+ ir = (ir_instruction *) ir_next, ir_next = ir->next) {
ir_assignment *ir_assign = ir->as_assignment();
if (debug) {
@@ -315,6 +316,7 @@ dead_code_local_basic_block(ir_instruction *first,
ir->accept(&kill);
}
+ /* break before we might perform an incorrect cast of a sentinel node */
if (ir == last)
break;
}
diff --git a/src/compiler/glsl/opt_tree_grafting.cpp b/src/compiler/glsl/opt_tree_grafting.cpp
index a40e5f7160..b9db41befa 100644
--- a/src/compiler/glsl/opt_tree_grafting.cpp
+++ b/src/compiler/glsl/opt_tree_grafting.cpp
@@ -347,11 +347,12 @@ tree_grafting_basic_block(ir_instruction *bb_first,
void *data)
{
struct tree_grafting_info *info = (struct tree_grafting_info *)data;
- ir_instruction *ir, *next;
+ exec_node *node, *next;
- for (ir = bb_first, next = (ir_instruction *)ir->next;
- ir != bb_last->next;
- ir = next, next = (ir_instruction *)ir->next) {
+ for (node = bb_first, next = node->next;
+ node != bb_last->next;
+ node = next, next = node->next) {
+ ir_instruction * const ir = (ir_instruction *) node;
ir_assignment *assign = ir->as_assignment();
if (!assign)