[Mesa-dev] [PATCH v2 2/5] compiler/list: avoid downcasting sentinel nodes (v2)
Nicolai Hähnle
nhaehnle at gmail.com
Fri May 13 04:50:50 UTC 2016
From: Nicolai Hähnle <nicolai.haehnle at amd.com>
This avoids undefined behaviour that crashes gcc's ubsan.
v2: don't add a new macro (Ian Romanick)
---
src/compiler/glsl/opt_dead_code_local.cpp | 8 +++++---
src/compiler/glsl/opt_tree_grafting.cpp | 9 +++++----
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 d38fd2b..a35026e 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 a40e5f7..b9db41b 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)
--
2.7.4
More information about the mesa-dev
mailing list