diff --git a/CMakeLists.txt b/CMakeLists.txt index 74b7c035..0e7beabf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,6 +81,9 @@ function(default_compile_options TARGET) if (UNIX) target_compile_options(${TARGET} PRIVATE -std=c++11 -fno-exceptions -fno-rtti) + target_compile_options(${TARGET} PRIVATE + -Wall -Wextra -Wno-long-long -Wshadow -Wundef -Wconversion + -Wno-sign-conversion) # For good call stacks in profiles, keep the frame pointers. if(NOT "${SPIRV_PERF}" STREQUAL "") target_compile_options(${TARGET} PRIVATE -fno-omit-frame-pointer) @@ -92,6 +95,9 @@ function(default_compile_options TARGET) target_compile_options(${TARGET} PRIVATE -fsanitize=${SPIRV_USE_SANITIZER}) endif() + else() + target_compile_options(${TARGET} PRIVATE + -Wno-missing-field-initializers) endif() endif() endfunction() @@ -231,6 +237,10 @@ if (NOT ${SPIRV_SKIP_EXECUTABLES}) add_executable(UnitSPIRV ${TEST_SOURCES}) default_compile_options(UnitSPIRV) + if(UNIX) + target_compile_options(UnitSPIRV PRIVATE + -Wno-undef) + endif() target_include_directories(UnitSPIRV PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${gmock_SOURCE_DIR}/include ${gtest_SOURCE_DIR}/include) diff --git a/include/util/hex_float.h b/include/util/hex_float.h index f3d70b2d..5ed1fa0b 100644 --- a/include/util/hex_float.h +++ b/include/util/hex_float.h @@ -102,7 +102,8 @@ class FloatProxy { // This is helpful to have and is guaranteed not to stomp bits. FloatProxy operator-() const { - return data_ ^ (uint_type(0x1) << (sizeof(T) * 8 - 1)); + return static_cast(data_ ^ + (uint_type(0x1) << (sizeof(T) * 8 - 1))); } // Returns the data as a floating point value. @@ -287,19 +288,21 @@ class HexFloat { // Returns the bits associated with the value, without the leading sign bit. uint_type getUnsignedBits() const { - return spvutils::BitwiseCast(value_) & ~sign_mask; + return static_cast(spvutils::BitwiseCast(value_) & + ~sign_mask); } // Returns the bits associated with the exponent, shifted to start at the // lsb of the type. const uint_type getExponentBits() const { - return (getBits() & exponent_mask) >> num_fraction_bits; + return static_cast((getBits() & exponent_mask) >> + num_fraction_bits); } // Returns the exponent in unbiased form. This is the exponent in the // human-friendly form. const int_type getUnbiasedExponent() const { - return (static_cast(getExponentBits()) - exponent_bias); + return static_cast(getExponentBits() - exponent_bias); } // Returns just the significand bits from the value. @@ -317,8 +320,8 @@ class HexFloat { if (exp == min_exponent) { // We are in denorm land. uint_type significand_bits = getSignificandBits(); while ((significand_bits & (first_exponent_bit >> 1)) == 0) { - significand_bits <<= 1; - exp -= 1; + significand_bits = static_cast(significand_bits << 1); + exp = static_cast(exp - 1); } significand_bits &= fraction_encode_mask; } @@ -330,7 +333,7 @@ class HexFloat { int_type unbiased_exponent = getUnbiasedNormalizedExponent(); uint_type significand = getSignificandBits(); for (int_type i = unbiased_exponent; i <= min_exponent; ++i) { - significand <<= 1; + significand = static_cast(significand << 1); } significand &= fraction_encode_mask; return significand; @@ -361,31 +364,32 @@ class HexFloat { // the significand is not zero. significand_is_zero = false; significand |= first_exponent_bit; - significand >>= 1; + significand = static_cast(significand >> 1); } while (exponent < min_exponent) { - significand >>= 1; + significand = static_cast(significand >> 1); ++exponent; } if (exponent == min_exponent) { if (significand == 0 && !significand_is_zero && round_denorm_up) { - significand = 0x1; + significand = static_cast(0x1); } } uint_type new_value = 0; if (negative) { - new_value |= sign_mask; + new_value = static_cast(new_value | sign_mask); } - exponent += exponent_bias; + exponent = static_cast(exponent + exponent_bias); assert(exponent >= 0); // put it all together - exponent = (exponent << exponent_left_shift) & exponent_mask; - significand &= fraction_encode_mask; - new_value |= exponent | significand; + exponent = static_cast((exponent << exponent_left_shift) & + exponent_mask); + significand = static_cast(significand & fraction_encode_mask); + new_value = static_cast(new_value | (exponent | significand)); value_ = BitwiseCast(new_value); } @@ -397,14 +401,14 @@ class HexFloat { // for a valid significand. static uint_type incrementSignificand(uint_type significand, uint_type to_increment, bool* carry) { - significand += to_increment; + significand = static_cast(significand + to_increment); *carry = false; if (significand & first_exponent_bit) { *carry = true; // The implicit 1-bit will have carried, so we should zero-out the // top bit and shift back. - significand &= ~first_exponent_bit; - significand >>= 1; + significand = static_cast(significand & ~first_exponent_bit); + significand = static_cast(significand >> 1); } return significand; } @@ -416,22 +420,30 @@ class HexFloat { template struct negatable_left_shift { - static uint_type val(uint_type val) { return val >> -N; } + static uint_type val(uint_type val) { + return static_cast(val >> -N); + } }; template struct negatable_left_shift= 0>::type> { - static uint_type val(uint_type val) { return val << N; } + static uint_type val(uint_type val) { + return static_cast(val << N); + } }; template struct negatable_right_shift { - static uint_type val(uint_type val) { return val << -N; } + static uint_type val(uint_type val) { + return static_cast(val << -N); + } }; template struct negatable_right_shift= 0>::type> { - static uint_type val(uint_type val) { return val >> N; } + static uint_type val(uint_type val) { + return static_cast(val >> N); + } }; // Returns the significand, rounded to fit in a significand in @@ -465,9 +477,9 @@ class HexFloat { uint_type significand = getNormalizedSignificand(); // If we are up-casting, then we just have to shift to the right location. if (num_throwaway_bits <= 0) { - out_val = significand; + out_val = static_cast(significand); uint_type shift_amount = -num_throwaway_bits; - out_val <<= shift_amount; + out_val = static_cast(out_val << shift_amount); return out_val; } @@ -548,10 +560,10 @@ class HexFloat { if (exponent == min_exponent) { // If we are denormal, normalize the exponent, so that we can encode // easily. - exponent += 1; + exponent = static_cast(exponent + 1); for (uint_type check_bit = first_exponent_bit >> 1; check_bit != 0; - check_bit >>= 1) { - exponent -= 1; + check_bit = static_cast(check_bit >> 1)) { + exponent = static_cast(exponent - 1); if (check_bit & significand) break; } } @@ -590,11 +602,12 @@ class HexFloat { bool round_underflow_up = isNegative() ? round_dir == round_direction::kToNegativeInfinity : round_dir == round_direction::kToPositiveInfinity; - + using other_int_type = typename other_T::int_type; // setFromSignUnbiasedExponentAndNormalizedSignificand will // zero out any underflowing value (but retain the sign). other.setFromSignUnbiasedExponentAndNormalizedSignificand( - negate, exponent, rounded_significand, round_underflow_up); + negate, static_cast(exponent), rounded_significand, + round_underflow_up); return; } @@ -641,18 +654,18 @@ std::ostream& operator<<(std::ostream& os, const HexFloat& value) { const uint_type bits = spvutils::BitwiseCast(value.value()); const char* const sign = (bits & HF::sign_mask) ? "-" : ""; - const uint_type exponent = - (bits & HF::exponent_mask) >> HF::num_fraction_bits; + const uint_type exponent = static_cast( + (bits & HF::exponent_mask) >> HF::num_fraction_bits); - uint_type fraction = (bits & HF::fraction_encode_mask) - << HF::num_overflow_bits; + uint_type fraction = static_cast((bits & HF::fraction_encode_mask) + << HF::num_overflow_bits); const bool is_zero = exponent == 0 && fraction == 0; const bool is_denorm = exponent == 0 && !is_zero; // exponent contains the biased exponent we have to convert it back into // the normal range. - int_type int_exponent = static_cast(exponent) - HF::exponent_bias; + int_type int_exponent = static_cast(exponent - HF::exponent_bias); // If the number is all zeros, then we actually have to NOT shift the // exponent. int_exponent = is_zero ? 0 : int_exponent; @@ -662,12 +675,12 @@ std::ostream& operator<<(std::ostream& os, const HexFloat& value) { if (is_denorm) { while ((fraction & HF::fraction_top_bit) == 0) { - fraction <<= 1; - int_exponent -= 1; + fraction = static_cast(fraction << 1); + int_exponent = static_cast(int_exponent - 1); } // Since this is denormalized, we have to consume the leading 1 since it // will end up being implicit. - fraction <<= 1; // eat the leading 1 + fraction = static_cast(fraction << 1); // eat the leading 1 fraction &= HF::fraction_represent_mask; } @@ -676,7 +689,7 @@ std::ostream& operator<<(std::ostream& os, const HexFloat& value) { // fractional part. while (fraction_nibbles > 0 && (fraction & 0xF) == 0) { // Shift off any trailing values; - fraction >>= 4; + fraction = static_cast(fraction >> 4); --fraction_nibbles; } @@ -828,8 +841,11 @@ std::istream& operator>>(std::istream& is, HexFloat& value) { if (bits_written) { // If we are here the bits represented belong in the fractional // part of the float, and we have to adjust the exponent accordingly. - fraction |= write_bit << (HF::top_bit_left_shift - fraction_index++); - exponent += 1; + fraction = + fraction | + static_cast( + write_bit << (HF::top_bit_left_shift - fraction_index++)); + exponent = static_cast(exponent + 1); } bits_written |= write_bit != 0; } @@ -855,9 +871,12 @@ std::istream& operator>>(std::istream& is, HexFloat& value) { // Handle modifying the exponent here this way we can handle // an arbitrary number of hex values without overflowing our // integer. - exponent -= 1; + exponent = static_cast(exponent - 1); } else { - fraction |= write_bit << (HF::top_bit_left_shift - fraction_index++); + fraction = + fraction | + static_cast( + write_bit << (HF::top_bit_left_shift - fraction_index++)); } } } else { @@ -883,8 +902,9 @@ std::istream& operator>>(std::istream& is, HexFloat& value) { exponent_sign = (next_char == '-') ? -1 : 1; } else if (::isdigit(next_char)) { // Hex-floats express their exponent as decimal. - written_exponent *= 10; - written_exponent += next_char - '0'; + written_exponent = static_cast(written_exponent * 10); + written_exponent = + static_cast(written_exponent + (next_char - '0')); } else { break; } @@ -892,19 +912,19 @@ std::istream& operator>>(std::istream& is, HexFloat& value) { next_char = is.peek(); } - written_exponent *= exponent_sign; - exponent += written_exponent; + written_exponent = static_cast(written_exponent * exponent_sign); + exponent = static_cast(exponent + written_exponent); bool is_zero = is_denorm && (fraction == 0); if (is_denorm && !is_zero) { - fraction <<= 1; - exponent -= 1; + fraction = static_cast(fraction << 1); + exponent = static_cast(exponent - 1); } else if (is_zero) { exponent = 0; } if (exponent <= 0 && !is_zero) { - fraction >>= 1; + fraction = static_cast(fraction >> 1); fraction |= static_cast(1) << HF::top_bit_left_shift; } @@ -915,8 +935,8 @@ std::istream& operator>>(std::istream& is, HexFloat& value) { // Handle actual denorm numbers while (exponent < 0 && !is_zero) { - fraction >>= 1; - exponent += 1; + fraction = static_cast(fraction >> 1); + exponent = static_cast(exponent + 1); fraction &= HF::fraction_encode_mask; if (fraction == 0) { @@ -932,10 +952,14 @@ std::istream& operator>>(std::istream& is, HexFloat& value) { fraction = 0; } - uint_type output_bits = static_cast(negate_value ? 1 : 0) - << HF::top_bit_left_shift; + uint_type output_bits = static_cast( + static_cast(negate_value ? 1 : 0) << HF::top_bit_left_shift); output_bits |= fraction; - output_bits |= (exponent << HF::exponent_left_shift) & HF::exponent_mask; + + uint_type shifted_exponent = static_cast( + static_cast(exponent << HF::exponent_left_shift) & + HF::exponent_mask); + output_bits |= shifted_exponent; T output_float = spvutils::BitwiseCast(output_bits); value.set_value(output_float); diff --git a/test/BinaryDestroy.cpp b/test/BinaryDestroy.cpp index 55ccd4ed..a5cb19cc 100644 --- a/test/BinaryDestroy.cpp +++ b/test/BinaryDestroy.cpp @@ -40,7 +40,6 @@ using BinaryDestroySomething = spvtest::TextToBinaryTest; // Checks safety of destroying a validly constructed binary. TEST_F(BinaryDestroySomething, Default) { - spv_context context = spvContextCreate(); // Use a binary object constructed by the API instead of rolling our own. SetText("OpSource OpenCL_C 120"); spv_binary my_binary = nullptr; @@ -48,7 +47,6 @@ TEST_F(BinaryDestroySomething, Default) { &my_binary, &diagnostic)); ASSERT_NE(nullptr, my_binary); spvBinaryDestroy(my_binary); - spvContextDestroy(context); } } // anonymous namespace diff --git a/test/BinaryHeaderGet.cpp b/test/BinaryHeaderGet.cpp index 420d1a56..84c900de 100644 --- a/test/BinaryHeaderGet.cpp +++ b/test/BinaryHeaderGet.cpp @@ -70,10 +70,10 @@ TEST_F(BinaryHeaderGet, Default) { } TEST_F(BinaryHeaderGet, InvalidCode) { - spv_const_binary_t binary = {nullptr, 0}; + spv_const_binary_t my_binary = {nullptr, 0}; spv_header_t header; ASSERT_EQ(SPV_ERROR_INVALID_BINARY, - spvBinaryHeaderGet(&binary, SPV_ENDIANNESS_LITTLE, &header)); + spvBinaryHeaderGet(&my_binary, SPV_ENDIANNESS_LITTLE, &header)); } TEST_F(BinaryHeaderGet, InvalidPointerHeader) { diff --git a/test/BinaryParse.cpp b/test/BinaryParse.cpp index 67af1203..cd2e6173 100644 --- a/test/BinaryParse.cpp +++ b/test/BinaryParse.cpp @@ -204,9 +204,9 @@ ParsedInstruction MakeParsedInt32TypeInstruction(uint32_t result_id) { class BinaryParseTest : public spvtest::TextToBinaryTestBase<::testing::Test> { protected: - void Parse(const SpirvVector& binary, spv_result_t expected_result) { + void Parse(const SpirvVector& words, spv_result_t expected_result) { EXPECT_EQ(expected_result, - spvBinaryParse(context, &client_, binary.data(), binary.size(), + spvBinaryParse(context, &client_, words.data(), words.size(), invoke_header, invoke_instruction, &diagnostic_)); } @@ -224,42 +224,42 @@ class BinaryParseTest : public spvtest::TextToBinaryTestBase<::testing::Test> { bound, 0 /*reserved*/)) TEST_F(BinaryParseTest, EmptyModuleHasValidHeaderAndNoInstructionCallbacks) { - const auto binary = CompileSuccessfully(""); + const auto words= CompileSuccessfully(""); EXPECT_HEADER(1).WillOnce(Return(SPV_SUCCESS)); EXPECT_CALL(client_, Instruction(_)).Times(0); // No instruction callback. - Parse(binary, SPV_SUCCESS); + Parse(words, SPV_SUCCESS); EXPECT_EQ(nullptr, diagnostic_); } TEST_F(BinaryParseTest, ModuleWithSingleInstructionHasValidHeaderAndInstructionCallback) { - const auto binary = CompileSuccessfully("%1 = OpTypeVoid"); + const auto words = CompileSuccessfully("%1 = OpTypeVoid"); InSequence calls_expected_in_specific_order; EXPECT_HEADER(2).WillOnce(Return(SPV_SUCCESS)); EXPECT_CALL(client_, Instruction(MakeParsedVoidTypeInstruction(1))) .WillOnce(Return(SPV_SUCCESS)); - Parse(binary, SPV_SUCCESS); + Parse(words, SPV_SUCCESS); EXPECT_EQ(nullptr, diagnostic_); } TEST_F(BinaryParseTest, NullHeaderCallbackIsIgnored) { - const auto binary = CompileSuccessfully("%1 = OpTypeVoid"); + const auto words = CompileSuccessfully("%1 = OpTypeVoid"); EXPECT_CALL(client_, Header(_, _, _, _, _, _)) .Times(0); // No header callback. EXPECT_CALL(client_, Instruction(MakeParsedVoidTypeInstruction(1))) .WillOnce(Return(SPV_SUCCESS)); EXPECT_EQ(SPV_SUCCESS, - spvBinaryParse(context, &client_, binary.data(), binary.size(), + spvBinaryParse(context, &client_, words.data(), words.size(), nullptr, invoke_instruction, &diagnostic_)); EXPECT_EQ(nullptr, diagnostic_); } TEST_F(BinaryParseTest, NullInstructionCallbackIsIgnored) { - const auto binary = CompileSuccessfully("%1 = OpTypeVoid"); + const auto words = CompileSuccessfully("%1 = OpTypeVoid"); EXPECT_HEADER((2)).WillOnce(Return(SPV_SUCCESS)); EXPECT_CALL(client_, Instruction(_)).Times(0); // No instruction callback. EXPECT_EQ(SPV_SUCCESS, - spvBinaryParse(context, &client_, binary.data(), binary.size(), + spvBinaryParse(context, &client_, words.data(), words.size(), invoke_header, nullptr, &diagnostic_)); EXPECT_EQ(nullptr, diagnostic_); } @@ -270,7 +270,7 @@ TEST_F(BinaryParseTest, NullInstructionCallbackIsIgnored) { // spv_parsed_instruction_t struct: words, num_words, opcode, result_id, // operands, num_operands. TEST_F(BinaryParseTest, TwoScalarTypesGenerateTwoInstructionCallbacks) { - const auto binary = CompileSuccessfully( + const auto words = CompileSuccessfully( "%1 = OpTypeVoid " "%2 = OpTypeInt 32 1"); InSequence calls_expected_in_specific_order; @@ -279,40 +279,40 @@ TEST_F(BinaryParseTest, TwoScalarTypesGenerateTwoInstructionCallbacks) { .WillOnce(Return(SPV_SUCCESS)); EXPECT_CALL(client_, Instruction(MakeParsedInt32TypeInstruction(2))) .WillOnce(Return(SPV_SUCCESS)); - Parse(binary, SPV_SUCCESS); + Parse(words, SPV_SUCCESS); EXPECT_EQ(nullptr, diagnostic_); } TEST_F(BinaryParseTest, EarlyReturnWithZeroPassingCallbacks) { - const auto binary = CompileSuccessfully( + const auto words = CompileSuccessfully( "%1 = OpTypeVoid " "%2 = OpTypeInt 32 1"); InSequence calls_expected_in_specific_order; EXPECT_HEADER(3).WillOnce(Return(SPV_ERROR_INVALID_BINARY)); // Early exit means no calls to Instruction(). EXPECT_CALL(client_, Instruction(_)).Times(0); - Parse(binary, SPV_ERROR_INVALID_BINARY); + Parse(words, SPV_ERROR_INVALID_BINARY); // On error, the binary parser doesn't generate its own diagnostics. EXPECT_EQ(nullptr, diagnostic_); } TEST_F(BinaryParseTest, EarlyReturnWithZeroPassingCallbacksAndSpecifiedResultCode) { - const auto binary = CompileSuccessfully( + const auto words = CompileSuccessfully( "%1 = OpTypeVoid " "%2 = OpTypeInt 32 1"); InSequence calls_expected_in_specific_order; EXPECT_HEADER(3).WillOnce(Return(SPV_REQUESTED_TERMINATION)); // Early exit means no calls to Instruction(). EXPECT_CALL(client_, Instruction(_)).Times(0); - Parse(binary, SPV_REQUESTED_TERMINATION); + Parse(words, SPV_REQUESTED_TERMINATION); // On early termination, the binary parser doesn't generate its own // diagnostics. EXPECT_EQ(nullptr, diagnostic_); } TEST_F(BinaryParseTest, EarlyReturnWithOnePassingCallback) { - const auto binary = CompileSuccessfully( + const auto words = CompileSuccessfully( "%1 = OpTypeVoid " "%2 = OpTypeInt 32 1 " "%3 = OpTypeFloat 32"); @@ -320,14 +320,14 @@ TEST_F(BinaryParseTest, EarlyReturnWithOnePassingCallback) { EXPECT_HEADER(4).WillOnce(Return(SPV_SUCCESS)); EXPECT_CALL(client_, Instruction(MakeParsedVoidTypeInstruction(1))) .WillOnce(Return(SPV_REQUESTED_TERMINATION)); - Parse(binary, SPV_REQUESTED_TERMINATION); + Parse(words, SPV_REQUESTED_TERMINATION); // On early termination, the binary parser doesn't generate its own // diagnostics. EXPECT_EQ(nullptr, diagnostic_); } TEST_F(BinaryParseTest, EarlyReturnWithTwoPassingCallbacks) { - const auto binary = CompileSuccessfully( + const auto words = CompileSuccessfully( "%1 = OpTypeVoid " "%2 = OpTypeInt 32 1 " "%3 = OpTypeFloat 32"); @@ -337,7 +337,7 @@ TEST_F(BinaryParseTest, EarlyReturnWithTwoPassingCallbacks) { .WillOnce(Return(SPV_SUCCESS)); EXPECT_CALL(client_, Instruction(MakeParsedInt32TypeInstruction(2))) .WillOnce(Return(SPV_REQUESTED_TERMINATION)); - Parse(binary, SPV_REQUESTED_TERMINATION); + Parse(words, SPV_REQUESTED_TERMINATION); // On early termination, the binary parser doesn't generate its own // diagnostics. EXPECT_EQ(nullptr, diagnostic_); @@ -348,7 +348,7 @@ TEST_F(BinaryParseTest, InstructionWithStringOperand) { "the future is already here, it's just not evenly distributed"; const auto str_words = MakeVector(str); const auto instruction = MakeInstruction(SpvOpName, {99}, str_words); - const auto binary = Concatenate({ExpectedHeaderForBound(100), instruction}); + const auto words = Concatenate({ExpectedHeaderForBound(100), instruction}); InSequence calls_expected_in_specific_order; EXPECT_HEADER(100).WillOnce(Return(SPV_SUCCESS)); const auto operands = std::vector{ @@ -361,14 +361,14 @@ TEST_F(BinaryParseTest, InstructionWithStringOperand) { 0 /* No result id for OpName*/, operands.data(), static_cast(operands.size())}))) .WillOnce(Return(SPV_SUCCESS)); - Parse(binary, SPV_SUCCESS); + Parse(words, SPV_SUCCESS); EXPECT_EQ(nullptr, diagnostic_); } // Checks for non-zero values for the result_id and ext_inst_type members // spv_parsed_instruction_t. TEST_F(BinaryParseTest, ExtendedInstruction) { - const auto binary = CompileSuccessfully( + const auto words = CompileSuccessfully( "%extcl = OpExtInstImport \"OpenCL.std\" " "%result = OpExtInst %float %extcl sqrt %x"); EXPECT_HEADER(5).WillOnce(Return(SPV_SUCCESS)); @@ -391,7 +391,7 @@ TEST_F(BinaryParseTest, ExtendedInstruction) { 3 /*result id*/, operands.data(), static_cast(operands.size())}))) .WillOnce(Return(SPV_SUCCESS)); - Parse(binary, SPV_SUCCESS); + Parse(words, SPV_SUCCESS); EXPECT_EQ(nullptr, diagnostic_); } @@ -407,7 +407,6 @@ using BinaryParseWordsAndCountDiagnosticTest = spvtest::TextToBinaryTestBase< ::testing::TestWithParam>; TEST_P(BinaryParseWordsAndCountDiagnosticTest, WordAndCountCases) { - spv_diagnostic diagnostic = nullptr; EXPECT_EQ( SPV_ERROR_INVALID_BINARY, spvBinaryParse(context, nullptr, GetParam().words, GetParam().num_words, @@ -445,7 +444,6 @@ using BinaryParseWordVectorDiagnosticTest = spvtest::TextToBinaryTestBase< ::testing::TestWithParam>; TEST_P(BinaryParseWordVectorDiagnosticTest, WordVectorCases) { - spv_diagnostic diagnostic = nullptr; const auto& words = GetParam().words; EXPECT_THAT(spvBinaryParse(context, nullptr, words.data(), words.size(), nullptr, nullptr, &diagnostic), @@ -459,8 +457,10 @@ INSTANTIATE_TEST_CASE_P( ::testing::ValuesIn(std::vector{ {Concatenate({ExpectedHeaderForBound(1), {spvOpcodeMake(0, SpvOpNop)}}), "Invalid instruction word count: 0"}, - {Concatenate({ExpectedHeaderForBound(1), - {spvOpcodeMake(1, static_cast(0xffff))}}), + {Concatenate( + {ExpectedHeaderForBound(1), + {spvOpcodeMake(1, static_cast( + std::numeric_limits::max()))}}), "Invalid opcode: 65535"}, {Concatenate({ExpectedHeaderForBound(1), MakeInstruction(SpvOpNop, {42})}), @@ -674,7 +674,6 @@ using BinaryParseAssemblyDiagnosticTest = spvtest::TextToBinaryTestBase< ::testing::TestWithParam>; TEST_P(BinaryParseAssemblyDiagnosticTest, AssemblyCases) { - spv_diagnostic diagnostic = nullptr; auto words = CompileSuccessfully(GetParam().assembly); EXPECT_THAT(spvBinaryParse(context, nullptr, words.data(), words.size(), nullptr, nullptr, &diagnostic), diff --git a/test/BinaryToText.cpp b/test/BinaryToText.cpp index 6a61c282..264337e1 100644 --- a/test/BinaryToText.cpp +++ b/test/BinaryToText.cpp @@ -396,7 +396,6 @@ OpStore %2 %3 Aligned|Volatile 4 ; bogus, but not indented TEST_F(TextToBinaryTest, VersionString) { auto words = CompileSuccessfully(""); spv_text decoded_text = nullptr; - spv_diagnostic diagnostic = nullptr; EXPECT_THAT(spvBinaryToText(context, words.data(), words.size(), SPV_BINARY_TO_TEXT_OPTION_NONE, &decoded_text, &diagnostic), @@ -430,7 +429,6 @@ TEST_P(GeneratorStringTest, Sample) { SPV_GENERATOR_WORD(GetParam().generator, GetParam().misc); spv_text decoded_text = nullptr; - spv_diagnostic diagnostic = nullptr; EXPECT_THAT(spvBinaryToText(context, words.data(), words.size(), SPV_BINARY_TO_TEXT_OPTION_NONE, &decoded_text, &diagnostic), diff --git a/test/HexFloat.cpp b/test/HexFloat.cpp index 63376a50..30262262 100644 --- a/test/HexFloat.cpp +++ b/test/HexFloat.cpp @@ -592,7 +592,7 @@ TEST(HexFloatOperationTest, UnbiasedExponent) { float float_fractions(const std::vector& fractions) { float f = 0; for(int32_t i: fractions) { - f += ldexp(1.0f, -i); + f += std::ldexp(1.0f, -i); } return f; } @@ -626,7 +626,7 @@ uint16_t half_bits_set(const std::vector& bits) { for(uint32_t i: bits) { val |= top_bit >> i; } - return val; + return static_cast(val); } TEST(HexFloatOperationTest, NormalizedSignificand) { diff --git a/test/ImmediateInt.cpp b/test/ImmediateInt.cpp index c6e76bb1..ebd30a24 100644 --- a/test/ImmediateInt.cpp +++ b/test/ImmediateInt.cpp @@ -184,7 +184,7 @@ TEST_F(ImmediateIntTest, StringFollowingImmediate) { EXPECT_EQ(original, CompiledInstructions("OpMemberName !1 !4 \"" + name + "\"")) << name; - const uint32_t wordCount = 4 + name.size() / 4; + const uint16_t wordCount = static_cast(4 + name.size() / 4); const uint32_t firstWord = spvOpcodeMake(wordCount, SpvOpMemberName); EXPECT_EQ(original, CompiledInstructions("!" + std::to_string(firstWord) + " %10 !4 \"" + name + "\"")) diff --git a/test/TestFixture.h b/test/TestFixture.h index 68c5c25c..77f51a2d 100644 --- a/test/TestFixture.h +++ b/test/TestFixture.h @@ -65,10 +65,10 @@ class TextToBinaryTestBase : public T { // Compiles SPIR-V text in the given assembly syntax format, asserting // compilation success. Returns the compiled code. - SpirvVector CompileSuccessfully(const std::string& text) { - spv_result_t status = spvTextToBinary(context, text.c_str(), text.size(), + SpirvVector CompileSuccessfully(const std::string& txt) { + spv_result_t status = spvTextToBinary(context, txt.c_str(), txt.size(), &binary, &diagnostic); - EXPECT_EQ(SPV_SUCCESS, status) << text; + EXPECT_EQ(SPV_SUCCESS, status) << txt; SpirvVector code_copy; if (status == SPV_SUCCESS) { code_copy = SpirvVector(binary->code, binary->code + binary->wordCount); @@ -81,26 +81,26 @@ class TextToBinaryTestBase : public T { // Compiles SPIR-V text with the given format, asserting compilation failure. // Returns the error message(s). - std::string CompileFailure(const std::string& text) { - EXPECT_NE(SPV_SUCCESS, spvTextToBinary(context, text.c_str(), text.size(), + std::string CompileFailure(const std::string& txt) { + EXPECT_NE(SPV_SUCCESS, spvTextToBinary(context, txt.c_str(), txt.size(), &binary, &diagnostic)) - << text; + << txt; DestroyBinary(); return diagnostic->error; } // Encodes SPIR-V text into binary and then decodes the binary using // default options. Returns the decoded text. - std::string EncodeAndDecodeSuccessfully(const std::string& text) { - return EncodeAndDecodeSuccessfully(text, SPV_BINARY_TO_TEXT_OPTION_NONE); + std::string EncodeAndDecodeSuccessfully(const std::string& txt) { + return EncodeAndDecodeSuccessfully(txt, SPV_BINARY_TO_TEXT_OPTION_NONE); } // Encodes SPIR-V text into binary and then decodes the binary using // given options. Returns the decoded text. - std::string EncodeAndDecodeSuccessfully(const std::string& text, + std::string EncodeAndDecodeSuccessfully(const std::string& txt, uint32_t disassemble_options) { DestroyBinary(); - spv_result_t error = spvTextToBinary(context, text.c_str(), text.size(), + spv_result_t error = spvTextToBinary(context, txt.c_str(), txt.size(), &binary, &diagnostic); if (error) { spvDiagnosticPrint(diagnostic); @@ -116,7 +116,7 @@ class TextToBinaryTestBase : public T { spvDiagnosticPrint(diagnostic); spvDiagnosticDestroy(diagnostic); } - EXPECT_EQ(SPV_SUCCESS, error) << text; + EXPECT_EQ(SPV_SUCCESS, error) << txt; const std::string decoded_string = decoded_text->str; spvTextDestroy(decoded_text); @@ -132,9 +132,9 @@ class TextToBinaryTestBase : public T { // is then decoded. This is expected to fail. // Returns the error message. std::string EncodeSuccessfullyDecodeFailed( - const std::string& text, const SpirvVector& words_to_append) { + const std::string& txt, const SpirvVector& words_to_append) { SpirvVector code = - spvtest::Concatenate({CompileSuccessfully(text), words_to_append}); + spvtest::Concatenate({CompileSuccessfully(txt), words_to_append}); spv_text decoded_text; EXPECT_NE(SPV_SUCCESS, spvBinaryToText(context, code.data(), code.size(), @@ -151,8 +151,8 @@ class TextToBinaryTestBase : public T { // Compiles SPIR-V text, asserts success, and returns the words representing // the instructions. In particular, skip the words in the SPIR-V header. - SpirvVector CompiledInstructions(const std::string& text) { - const SpirvVector code = CompileSuccessfully(text); + SpirvVector CompiledInstructions(const std::string& txt) { + const SpirvVector code = CompileSuccessfully(txt); SpirvVector result; // Extract just the instructions. // If the code fails to compile, then return the empty vector. diff --git a/test/TextToBinary.cpp b/test/TextToBinary.cpp index 6bd75132..91f1ca52 100644 --- a/test/TextToBinary.cpp +++ b/test/TextToBinary.cpp @@ -140,7 +140,6 @@ union char_word_t { }; TEST_F(TextToBinaryTest, InvalidText) { - spv_binary binary; ASSERT_EQ(SPV_ERROR_INVALID_TEXT, spvTextToBinary(context, nullptr, 0, &binary, &diagnostic)); EXPECT_NE(nullptr, diagnostic); @@ -158,7 +157,6 @@ TEST_F(TextToBinaryTest, InvalidPointer) { TEST_F(TextToBinaryTest, InvalidDiagnostic) { SetText( "OpEntryPoint Kernel 0 \"\"\nOpExecutionMode 0 LocalSizeHint 1 1 1\n"); - spv_binary binary; ASSERT_EQ(SPV_ERROR_INVALID_DIAGNOSTIC, spvTextToBinary(context, text.str, text.length, &binary, nullptr)); } diff --git a/test/UnitSPIRV.h b/test/UnitSPIRV.h index 5cec434a..0264bdf6 100644 --- a/test/UnitSPIRV.h +++ b/test/UnitSPIRV.h @@ -79,7 +79,7 @@ void PrintTo(const WordVector& words, ::std::ostream* os); // A proxy class to allow us to easily write out vectors of SPIR-V words. class WordVector { public: - explicit WordVector(const std::vector& value) : value_(value) {} + explicit WordVector(const std::vector& val) : value_(val) {} explicit WordVector(const spv_binary_t& binary) : value_(binary.code, binary.code + binary.wordCount) {} @@ -179,8 +179,8 @@ struct AutoText { template class EnumCase { public: - EnumCase(E value, std::string name, std::vector operands = {}) - : enum_value_(value), name_(name), operands_(operands) {} + EnumCase(E val, std::string enum_name, std::vector ops = {}) + : enum_value_(val), name_(enum_name), operands_(ops) {} // Returns the enum value as a uint32_t. uint32_t value() const { return static_cast(enum_value_); } // Returns the name of the enumerant.