Skip to content

Commit d85c6a6

Browse files
authored
val: fix MSVC warning C4146 (minus on unsigned) (KhronosGroup#6282)
DXC is building with -Werror, and doing `-1u` to get an all ones yiels a `unary minus operator applied to unsigned type, result still unsigned` warning.
1 parent 63b3728 commit d85c6a6

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

source/val/validate_composites.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
// Validates correctness of composite SPIR-V instructions.
1818

19+
#include <climits>
20+
1921
#include "source/opcode.h"
2022
#include "source/spirv_target_env.h"
2123
#include "source/val/instruction.h"
@@ -640,7 +642,7 @@ spv_result_t ValidateCompositeConstructCoopMatQCOM(ValidationState_t& _,
640642

641643
// Is the scope Subgrouop ?
642644
{
643-
unsigned scope = -1u;
645+
unsigned scope = UINT_MAX;
644646
unsigned scope_id = result_type_inst->GetOperandAs<unsigned>(2u);
645647
bool status = _.GetConstantValueAs<unsigned>(scope_id, scope);
646648
bool is_scope_spec_const =
@@ -653,7 +655,7 @@ spv_result_t ValidateCompositeConstructCoopMatQCOM(ValidationState_t& _,
653655
}
654656
}
655657

656-
unsigned ar_len = -1u;
658+
unsigned ar_len = UINT_MAX;
657659
unsigned src_arr_len_id = source_type_inst->GetOperandAs<unsigned>(2u);
658660
bool ar_len_status = _.GetConstantValueAs<unsigned>(src_arr_len_id, ar_len);
659661
bool is_src_arr_len_spec_const =
@@ -676,7 +678,7 @@ spv_result_t ValidateCompositeConstructCoopMatQCOM(ValidationState_t& _,
676678
unsigned res_col_id = result_type_inst->GetOperandAs<unsigned>(4u);
677679
unsigned res_use_id = result_type_inst->GetOperandAs<unsigned>(5u);
678680

679-
unsigned cm_use = -1u;
681+
unsigned cm_use = UINT_MAX;
680682
bool cm_use_status = _.GetConstantValueAs<unsigned>(res_use_id, cm_use);
681683

682684
switch (static_cast<spv::CooperativeMatrixUse>(cm_use)) {
@@ -691,7 +693,7 @@ spv_result_t ValidateCompositeConstructCoopMatQCOM(ValidationState_t& _,
691693
}
692694

693695
// result coopmat column length check
694-
unsigned n_cols = -1u;
696+
unsigned n_cols = UINT_MAX;
695697
bool status = _.GetConstantValueAs<unsigned>(res_col_id, n_cols);
696698
bool is_res_col_spec_const =
697699
spvOpcodeIsSpecConstant(_.FindDef(res_col_id)->opcode());
@@ -738,7 +740,7 @@ spv_result_t ValidateCompositeConstructCoopMatQCOM(ValidationState_t& _,
738740
}
739741

740742
// result coopmat row length check
741-
unsigned n_rows = -1u;
743+
unsigned n_rows = UINT_MAX;
742744
bool status = _.GetConstantValueAs<unsigned>(res_row_id, n_rows);
743745
bool is_res_row_spec_const =
744746
spvOpcodeIsSpecConstant(_.FindDef(res_row_id)->opcode());
@@ -785,7 +787,7 @@ spv_result_t ValidateCompositeConstructCoopMatQCOM(ValidationState_t& _,
785787
}
786788

787789
// source array length check
788-
unsigned n_cols = -1u;
790+
unsigned n_cols = UINT_MAX;
789791
bool status = _.GetConstantValueAs<unsigned>(res_col_id, n_cols);
790792
bool is_res_col_spec_const =
791793
spvOpcodeIsSpecConstant(_.FindDef(res_col_id)->opcode());
@@ -848,7 +850,7 @@ spv_result_t ValidateCompositeExtractCoopMatQCOM(ValidationState_t& _,
848850

849851
// Is the scope Subgrouop ?
850852
{
851-
unsigned scope = -1u;
853+
unsigned scope = UINT_MAX;
852854
unsigned scope_id = source_type_inst->GetOperandAs<unsigned>(2u);
853855
bool status = _.GetConstantValueAs<unsigned>(scope_id, scope);
854856
bool is_scope_spec_const =
@@ -861,7 +863,7 @@ spv_result_t ValidateCompositeExtractCoopMatQCOM(ValidationState_t& _,
861863
}
862864
}
863865

864-
unsigned ar_len = -1u;
866+
unsigned ar_len = UINT_MAX;
865867
unsigned res_arr_len_id = result_type_inst->GetOperandAs<unsigned>(2u);
866868
bool ar_len_status = _.GetConstantValueAs<unsigned>(res_arr_len_id, ar_len);
867869
bool is_res_arr_len_spec_const =
@@ -874,7 +876,7 @@ spv_result_t ValidateCompositeExtractCoopMatQCOM(ValidationState_t& _,
874876
unsigned src_col_id = source_type_inst->GetOperandAs<unsigned>(4u);
875877
unsigned src_use_id = source_type_inst->GetOperandAs<unsigned>(5u);
876878

877-
unsigned cm_use = -1u;
879+
unsigned cm_use = UINT_MAX;
878880
bool cm_use_status = _.GetConstantValueAs<unsigned>(src_use_id, cm_use);
879881

880882
switch (static_cast<spv::CooperativeMatrixUse>(cm_use)) {
@@ -889,7 +891,7 @@ spv_result_t ValidateCompositeExtractCoopMatQCOM(ValidationState_t& _,
889891
}
890892

891893
// source coopmat column length check
892-
unsigned n_cols = -1u;
894+
unsigned n_cols = UINT_MAX;
893895
bool status = _.GetConstantValueAs<unsigned>(src_col_id, n_cols);
894896
bool is_src_col_spec_const =
895897
spvOpcodeIsSpecConstant(_.FindDef(src_col_id)->opcode());
@@ -937,7 +939,7 @@ spv_result_t ValidateCompositeExtractCoopMatQCOM(ValidationState_t& _,
937939
}
938940

939941
// source coopmat row length check
940-
unsigned n_rows = -1u;
942+
unsigned n_rows = UINT_MAX;
941943
bool status = _.GetConstantValueAs<unsigned>(src_row_id, n_rows);
942944
bool is_src_row_spec_const =
943945
spvOpcodeIsSpecConstant(_.FindDef(src_row_id)->opcode());
@@ -985,7 +987,7 @@ spv_result_t ValidateCompositeExtractCoopMatQCOM(ValidationState_t& _,
985987
}
986988

987989
// result type check
988-
unsigned n_cols = -1u;
990+
unsigned n_cols = UINT_MAX;
989991
bool status = _.GetConstantValueAs<unsigned>(src_col_id, n_cols);
990992
bool is_src_col_spec_const =
991993
spvOpcodeIsSpecConstant(_.FindDef(src_col_id)->opcode());

0 commit comments

Comments
 (0)