[Mesa-dev] [PATCH] nir: Replace assert(0) with unreachable().

Connor Abbott cwabbott0 at gmail.com
Wed Jan 21 20:23:15 PST 2015


Reviewed-by: Connor Abbott <cwabbott0 at gmail.com>

On Wed, Jan 21, 2015 at 11:23 PM, Matt Turner <mattst88 at gmail.com> wrote:
> Fixes a couple of warnings in the process.
> ---
>  src/glsl/nir/glsl_to_nir.cpp           | 57 ++++++++++++----------------------
>  src/glsl/nir/nir.h                     |  3 +-
>  src/glsl/nir/nir_lower_system_values.c |  3 +-
>  src/glsl/nir/nir_to_ssa.c              |  2 +-
>  4 files changed, 22 insertions(+), 43 deletions(-)
>
> diff --git a/src/glsl/nir/glsl_to_nir.cpp b/src/glsl/nir/glsl_to_nir.cpp
> index 6ac830e..1457c1c 100644
> --- a/src/glsl/nir/glsl_to_nir.cpp
> +++ b/src/glsl/nir/glsl_to_nir.cpp
> @@ -216,8 +216,7 @@ constant_copy(ir_constant *ir, void *mem_ctx)
>        break;
>
>     default:
> -      assert(0);
> -      break;
> +      unreachable("not reached");
>     }
>
>     return ret;
> @@ -278,8 +277,7 @@ nir_visitor::visit(ir_variable *ir)
>        break;
>
>     default:
> -      assert(0);
> -      break;
> +      unreachable("not reached");
>     }
>
>     var->data.interpolation = ir->data.interpolation;
> @@ -311,8 +309,7 @@ nir_visitor::visit(ir_variable *ir)
>        var->data.depth_layout = nir_depth_layout_unchanged;
>        break;
>     default:
> -      assert(0);
> -      break;
> +      unreachable("not reached");
>     }
>
>     var->data.location = ir->data.location;
> @@ -374,8 +371,7 @@ nir_visitor::visit(ir_variable *ir)
>        break;
>
>     default:
> -      assert(0);
> -      break;
> +      unreachable("not reached");
>     }
>
>     _mesa_hash_table_insert(var_table, ir, var);
> @@ -429,8 +425,7 @@ nir_visitor::create_overload(ir_function_signature *ir, nir_function *function)
>           break;
>
>        default:
> -         assert(0);
> -         break;
> +         unreachable("not reached");
>        }
>
>        overload->params[i].type = param->type;
> @@ -573,8 +568,7 @@ nir_visitor::visit(ir_loop_jump *ir)
>        type = nir_jump_continue;
>        break;
>     default:
> -      assert(0);
> -      break;
> +      unreachable("not reached");
>     }
>
>     nir_jump_instr *instr = nir_jump_instr_create(this->shader, type);
> @@ -793,8 +787,7 @@ get_instr_dest(nir_instr *instr)
>           return &tex_instr->dest;
>
>        default:
> -         assert(0);
> -         break;
> +         unreachable("not reached");
>     }
>
>     return NULL;
> @@ -1087,8 +1080,7 @@ nir_visitor::visit(ir_expression *ir)
>                dest_size, srcs);
>           break;
>        default:
> -         assert(0);
> -         break;
> +         unreachable("not reached");
>        }
>        break;
>     case ir_unop_trunc: emit(nir_op_ftrunc, dest_size, srcs); break;
> @@ -1207,8 +1199,7 @@ nir_visitor::visit(ir_expression *ir)
>           }
>           break;
>        default:
> -         assert(0);
> -         break;
> +         unreachable("not reached");
>        }
>        break;
>     case ir_binop_add:
> @@ -1296,8 +1287,7 @@ nir_visitor::visit(ir_expression *ir)
>           break;
>
>        default:
> -         assert(0);
> -         break;
> +         unreachable("not reached");
>        }
>
>        instr = emit(op, dest_size, srcs);
> @@ -1402,8 +1392,7 @@ nir_visitor::visit(ir_expression *ir)
>                 case 3: emit(nir_op_ball_fequal3, dest_size, srcs); break;
>                 case 4: emit(nir_op_ball_fequal4, dest_size, srcs); break;
>                 default:
> -                  assert(0);
> -                  break;
> +                  unreachable("not reached");
>              }
>           } else {
>              switch (ir->operands[0]->type->vector_elements) {
> @@ -1412,8 +1401,7 @@ nir_visitor::visit(ir_expression *ir)
>                 case 3: emit(nir_op_ball_iequal3, dest_size, srcs); break;
>                 case 4: emit(nir_op_ball_iequal4, dest_size, srcs); break;
>                 default:
> -                  assert(0);
> -                  break;
> +                  unreachable("not reached");
>              }
>           }
>        } else {
> @@ -1423,8 +1411,7 @@ nir_visitor::visit(ir_expression *ir)
>              case 3: emit(nir_op_fall_equal3, dest_size, srcs); break;
>              case 4: emit(nir_op_fall_equal4, dest_size, srcs); break;
>              default:
> -               assert(0);
> -               break;
> +               unreachable("not reached");
>           }
>        }
>        break;
> @@ -1437,8 +1424,7 @@ nir_visitor::visit(ir_expression *ir)
>                 case 3: emit(nir_op_bany_fnequal3, dest_size, srcs); break;
>                 case 4: emit(nir_op_bany_fnequal4, dest_size, srcs); break;
>                 default:
> -                  assert(0);
> -                  break;
> +                  unreachable("not reached");
>              }
>           } else {
>              switch (ir->operands[0]->type->vector_elements) {
> @@ -1447,8 +1433,7 @@ nir_visitor::visit(ir_expression *ir)
>                 case 3: emit(nir_op_bany_inequal3, dest_size, srcs); break;
>                 case 4: emit(nir_op_bany_inequal4, dest_size, srcs); break;
>                 default:
> -                  assert(0);
> -                  break;
> +                  unreachable("not reached");
>              }
>           }
>        } else {
> @@ -1458,8 +1443,7 @@ nir_visitor::visit(ir_expression *ir)
>              case 3: emit(nir_op_fany_nequal3, dest_size, srcs); break;
>              case 4: emit(nir_op_fany_nequal4, dest_size, srcs); break;
>              default:
> -               assert(0);
> -               break;
> +               unreachable("not reached");
>           }
>        }
>        break;
> @@ -1487,8 +1471,7 @@ nir_visitor::visit(ir_expression *ir)
>           case 3: emit(nir_op_fdot3, dest_size, srcs); break;
>           case 4: emit(nir_op_fdot4, dest_size, srcs); break;
>           default:
> -            assert(0);
> -            break;
> +            unreachable("not reached");
>        }
>        break;
>
> @@ -1545,8 +1528,7 @@ nir_visitor::visit(ir_expression *ir)
>        break;
>
>     default:
> -      assert(0);
> -      break;
> +      unreachable("not reached");
>     }
>  }
>
> @@ -1621,8 +1603,7 @@ nir_visitor::visit(ir_texture *ir)
>        break;
>
>     default:
> -      assert(0);
> -      break;
> +      unreachable("not reached");
>     }
>
>     if (ir->projector != NULL)
> diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h
> index 7b5794d..52bcd87 100644
> --- a/src/glsl/nir/nir.h
> +++ b/src/glsl/nir/nir.h
> @@ -938,8 +938,7 @@ nir_tex_instr_dest_size(nir_tex_instr *instr)
>              ret = 3;
>              break;
>           default:
> -            assert(0);
> -            break;
> +            unreachable("not reached");
>        }
>        if (instr->is_array)
>           ret++;
> diff --git a/src/glsl/nir/nir_lower_system_values.c b/src/glsl/nir/nir_lower_system_values.c
> index f681a6c..631f7cd 100644
> --- a/src/glsl/nir/nir_lower_system_values.c
> +++ b/src/glsl/nir/nir_lower_system_values.c
> @@ -64,8 +64,7 @@ convert_instr(nir_intrinsic_instr *instr)
>        op = nir_intrinsic_load_invocation_id;
>        break;
>     default:
> -      assert(0);
> -      break;
> +      unreachable("not reached");
>     }
>
>     nir_intrinsic_instr *new_instr = nir_intrinsic_instr_create(mem_ctx, op);
> diff --git a/src/glsl/nir/nir_to_ssa.c b/src/glsl/nir/nir_to_ssa.c
> index b9b1cff..548f0c5 100644
> --- a/src/glsl/nir/nir_to_ssa.c
> +++ b/src/glsl/nir/nir_to_ssa.c
> @@ -313,7 +313,7 @@ rewrite_alu_instr_forward(nir_alu_instr *instr, rewrite_state *state)
>        case 2: op = nir_op_vec2; break;
>        case 3: op = nir_op_vec3; break;
>        case 4: op = nir_op_vec4; break;
> -      default: assert(0); break;
> +      default: unreachable("not reached");
>        }
>
>        nir_alu_instr *vec = nir_alu_instr_create(state->mem_ctx, op);
> --
> 2.0.4
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list