diff options
author | Neil Roberts <[email protected]> | 2020-04-02 16:25:18 +0200 |
---|---|---|
committer | Neil Roberts <[email protected]> | 2020-04-03 09:10:17 +0200 |
commit | 63b4fcba33848029e7dd1476d9f82070308a7239 (patch) | |
tree | f88c21d08a09cedbcc5a0f679f0be9460126f588 | |
parent | ff1a3a00cb37d84ab9a563f0aa241714876f56b4 (diff) |
glsl/lower_precision: Use vector.back() instead of vector.end()[-1]
The use of vector.end()[-1] seems to generate warnings in Coverity about
not allowing a negative argument to a parameter. The intention with the
code snippet is just to access the last element of the vector. The
vector.back() call acheives the same thing, is clearer and will
hopefully fix the Coverity warning.
I’m not exactly sure why Coverity thinks the array index can’t be
negative. cplusplus.com says that vector::end() returns a random access
iterator and that the type of the array index operator argument to that
should be the difference type for the container. It then also says that
difference_type for a vector is "a signed integral type".
Reviewed-by: Eric Anholt <[email protected]>
-rw-r--r-- | src/compiler/glsl/lower_precision.cpp | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/src/compiler/glsl/lower_precision.cpp b/src/compiler/glsl/lower_precision.cpp index 4e4ef8ef2e5..332cd50cc7a 100644 --- a/src/compiler/glsl/lower_precision.cpp +++ b/src/compiler/glsl/lower_precision.cpp @@ -200,7 +200,7 @@ find_lowerable_rvalues_visitor::add_lowerable_children(const stack_entry &entry) void find_lowerable_rvalues_visitor::pop_stack_entry() { - const stack_entry &entry = stack.end()[-1]; + const stack_entry &entry = stack.back(); if (stack.size() >= 2) { /* Combine this state into the parent state, unless the parent operation @@ -315,7 +315,7 @@ find_lowerable_rvalues_visitor::visit(ir_constant *ir) stack_enter(ir, this); if (!can_lower_type(ir->type)) - stack.end()[-1].state = CANT_LOWER; + stack.back().state = CANT_LOWER; stack_leave(ir, this); @@ -327,8 +327,8 @@ find_lowerable_rvalues_visitor::visit(ir_dereference_variable *ir) { stack_enter(ir, this); - if (stack.end()[-1].state == UNKNOWN) - stack.end()[-1].state = handle_precision(ir->type, ir->precision()); + if (stack.back().state == UNKNOWN) + stack.back().state = handle_precision(ir->type, ir->precision()); stack_leave(ir, this); @@ -340,8 +340,8 @@ find_lowerable_rvalues_visitor::visit_enter(ir_dereference_record *ir) { ir_hierarchical_visitor::visit_enter(ir); - if (stack.end()[-1].state == UNKNOWN) - stack.end()[-1].state = handle_precision(ir->type, ir->precision()); + if (stack.back().state == UNKNOWN) + stack.back().state = handle_precision(ir->type, ir->precision()); return visit_continue; } @@ -351,8 +351,8 @@ find_lowerable_rvalues_visitor::visit_enter(ir_dereference_array *ir) { ir_hierarchical_visitor::visit_enter(ir); - if (stack.end()[-1].state == UNKNOWN) - stack.end()[-1].state = handle_precision(ir->type, ir->precision()); + if (stack.back().state == UNKNOWN) + stack.back().state = handle_precision(ir->type, ir->precision()); return visit_continue; } @@ -362,12 +362,12 @@ find_lowerable_rvalues_visitor::visit_enter(ir_texture *ir) { ir_hierarchical_visitor::visit_enter(ir); - if (stack.end()[-1].state == UNKNOWN) { + if (stack.back().state == UNKNOWN) { /* The precision of the sample value depends on the precision of the * sampler. */ - stack.end()[-1].state = handle_precision(ir->type, - ir->sampler->precision()); + stack.back().state = handle_precision(ir->type, + ir->sampler->precision()); } return visit_continue; @@ -379,7 +379,7 @@ find_lowerable_rvalues_visitor::visit_enter(ir_expression *ir) ir_hierarchical_visitor::visit_enter(ir); if (!can_lower_type(ir->type)) - stack.end()[-1].state = CANT_LOWER; + stack.back().state = CANT_LOWER; /* Don't lower precision for derivative calculations */ if (ir->operation == ir_unop_dFdx || @@ -388,7 +388,7 @@ find_lowerable_rvalues_visitor::visit_enter(ir_expression *ir) ir->operation == ir_unop_dFdy || ir->operation == ir_unop_dFdy_coarse || ir->operation == ir_unop_dFdy_fine) { - stack.end()[-1].state = CANT_LOWER; + stack.back().state = CANT_LOWER; } return visit_continue; |