From: Lei Zhang Date: Thu, 25 Feb 2016 21:11:16 +0000 (-0500) Subject: Fix issues reported by cppcheck. X-Git-Tag: upstream/2018.6~1311 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=712bed022720d0109d477ba4d67def075b5be793;p=platform%2Fupstream%2FSPIRV-Tools.git Fix issues reported by cppcheck. Remove code not being used, add explicit to constructors, and add missing fields in constructors. --- diff --git a/source/assembly_grammar.h b/source/assembly_grammar.h index fab31b8..3364f71 100644 --- a/source/assembly_grammar.h +++ b/source/assembly_grammar.h @@ -37,7 +37,7 @@ namespace libspirv { // Contains methods to query for valid instructions and operands. class AssemblyGrammar { public: - AssemblyGrammar(const spv_const_context context) + explicit AssemblyGrammar(const spv_const_context context) : operandTable_(context->operand_table), opcodeTable_(context->opcode_table), extInstTable_(context->ext_inst_table) {} diff --git a/source/binary.cpp b/source/binary.cpp index 2c42c92..5c6aa8f 100644 --- a/source/binary.cpp +++ b/source/binary.cpp @@ -62,47 +62,6 @@ spv_result_t spvBinaryHeaderGet(const spv_const_binary binary, return SPV_SUCCESS; } -// TODO(dneto): This API is not powerful enough in the case that the -// number and type of operands are not known until partway through parsing -// the operation. This happens when enum operands might have different number -// of operands, or with extended instructions. -spv_operand_type_t spvBinaryOperandInfo(const uint32_t word, - const uint16_t operandIndex, - const spv_opcode_desc opcodeEntry, - const spv_operand_table operandTable, - spv_operand_desc* pOperandEntry) { - spv_operand_type_t type; - if (operandIndex < opcodeEntry->numTypes) { - // NOTE: Do operand table lookup to set operandEntry if successful - const int index = operandIndex - 1; - type = opcodeEntry->operandTypes[index]; - spv_operand_desc entry = nullptr; - if (!spvOperandTableValueLookup(operandTable, type, word, &entry)) { - if (SPV_OPERAND_TYPE_NONE != entry->operandTypes[0]) { - *pOperandEntry = entry; - } - } - } else if (*pOperandEntry) { - // NOTE: Use specified operand entry operand type for this word - const int index = operandIndex - opcodeEntry->numTypes; - type = (*pOperandEntry)->operandTypes[index]; - } else if (SpvOpSwitch == opcodeEntry->opcode) { - // NOTE: OpSwitch is a special case which expects a list of paired extra - // operands - assert(0 && - "This case is previously untested, remove this assert and ensure it " - "is behaving correctly!"); - const int lastIndex = opcodeEntry->numTypes - 1; - const int index = lastIndex + ((operandIndex - lastIndex) % 2); - type = opcodeEntry->operandTypes[index]; - } else { - // NOTE: Default to last operand type in opcode entry - const int index = opcodeEntry->numTypes - 1; - type = opcodeEntry->operandTypes[index]; - } - return type; -} - namespace { // A SPIR-V binary parser. A parser instance communicates detailed parse @@ -228,7 +187,8 @@ class Parser { num_words(num_words_arg), diagnostic(diagnostic_arg), word_index(0), - endian() {} + endian(), + requires_endian_conversion(false) {} State() : State(0, 0, nullptr) {} const uint32_t* words; // Words in the binary SPIR-V module. size_t num_words; // Number of words in the module. diff --git a/source/opcode.cpp b/source/opcode.cpp index 63ba9a9..6e9d240 100644 --- a/source/opcode.cpp +++ b/source/opcode.cpp @@ -466,13 +466,6 @@ int32_t spvOpcodeIsComposite(const SpvOp opcode) { } } -int32_t spvOpcodeAreTypesEqual(const spv_instruction_t* pTypeInst0, - const spv_instruction_t* pTypeInst1) { - if (pTypeInst0->opcode != pTypeInst1->opcode) return false; - if (pTypeInst0->words[1] != pTypeInst1->words[1]) return false; - return true; -} - int32_t spvOpcodeIsPointer(const SpvOp opcode) { switch (opcode) { case SpvOpVariable: @@ -485,16 +478,6 @@ int32_t spvOpcodeIsPointer(const SpvOp opcode) { } } -int32_t spvInstructionIsInBasicBlock(const spv_instruction_t* pFirstInst, - const spv_instruction_t* pInst) { - while (pFirstInst != pInst) { - if (SpvOpFunction == pInst->opcode) break; - pInst--; - } - if (SpvOpFunction != pInst->opcode) return false; - return true; -} - int32_t spvOpcodeGeneratesType(SpvOp op) { switch (op) { case SpvOpTypeVoid: diff --git a/source/print.h b/source/print.h index 7ae3644..fe19969 100644 --- a/source/print.h +++ b/source/print.h @@ -36,7 +36,7 @@ namespace libspirv { class out_stream { public: out_stream() : pStream(nullptr) {} - out_stream(std::stringstream& stream) : pStream(&stream) {} + explicit out_stream(std::stringstream& stream) : pStream(&stream) {} std::ostream& get() { if (pStream) { diff --git a/source/text_handler.h b/source/text_handler.h index 6f003db..386a4dc 100644 --- a/source/text_handler.h +++ b/source/text_handler.h @@ -263,10 +263,9 @@ class AssemblyContext { // It also allows octal input, but we don't care about that case. text_stream >> std::setbase(0); text_stream >> *value_pointer; - bool ok = true; // We should have read something. - ok = (text[0] != 0) && !text_stream.bad(); + bool ok = (text[0] != 0) && !text_stream.bad(); // It should have been all the text. ok = ok && text_stream.eof(); // It should have been in range. diff --git a/source/util/hex_float.h b/source/util/hex_float.h index 879d0ce..25db7f6 100644 --- a/source/util/hex_float.h +++ b/source/util/hex_float.h @@ -42,11 +42,11 @@ class Float16 { public: Float16(uint16_t v) : val(v) {} Float16() = default; - static bool isNan(const Float16 val) { + static bool isNan(const Float16& val) { return ((val.val & 0x7C00) == 0x7C00) && ((val.val & 0x3FF) != 0); } // Returns true if the given value is any kind of infinity. - static bool isInfinity(const Float16 val) { + static bool isInfinity(const Float16& val) { return ((val.val & 0x7C00) == 0x7C00) && ((val.val & 0x3FF) == 0); } Float16(const Float16& other) { val = other.val; } diff --git a/source/validate.h b/source/validate.h index 7833e5a..5438924 100644 --- a/source/validate.h +++ b/source/validate.h @@ -95,7 +95,7 @@ class ValidationState_t; // types are used to manage the state while parsing the function. class Functions { public: - Functions(ValidationState_t& module); + explicit Functions(ValidationState_t& module); // Registers the function in the module. Subsequent instructions will be // called against this function diff --git a/test/TextToBinary.cpp b/test/TextToBinary.cpp index e30e332..6dc8902 100644 --- a/test/TextToBinary.cpp +++ b/test/TextToBinary.cpp @@ -134,12 +134,6 @@ INSTANTIATE_TEST_CASE_P(ParseMask, BadFPFastMathMaskParseTest, "Unroll" // A good word, but for the wrong enum })); -// TODO(dneto): Aliasing like this relies on undefined behaviour. Fix this. -union char_word_t { - char cs[4]; - uint32_t u; -}; - TEST_F(TextToBinaryTest, InvalidText) { ASSERT_EQ(SPV_ERROR_INVALID_TEXT, spvTextToBinary(context, nullptr, 0, &binary, &diagnostic)); diff --git a/test/UnitSPIRV.h b/test/UnitSPIRV.h index 558b790..2e902b0 100644 --- a/test/UnitSPIRV.h +++ b/test/UnitSPIRV.h @@ -169,7 +169,8 @@ inline std::vector MakeVector(std::string input) { // A type for easily creating spv_text_t values, with an implicit conversion to // spv_text. struct AutoText { - AutoText(std::string value) : str(value), text({str.data(), str.size()}) {} + explicit AutoText(std::string value) + : str(value), text({str.data(), str.size()}) {} operator spv_text() { return &text; } std::string str; spv_text_t text; diff --git a/test/Validate.Layout.cpp b/test/Validate.Layout.cpp index 308103b..8c69f21 100644 --- a/test/Validate.Layout.cpp +++ b/test/Validate.Layout.cpp @@ -66,7 +66,7 @@ spv_result_t Equals(int order) { // returns true if order is between MIN and MAX(inclusive) template struct Range { - Range(bool inverse = false) : inverse_(inverse) {} + explicit Range(bool inverse = false) : inverse_(inverse) {} spv_result_t operator()(int order) { return (inverse_ ^ (order >= MIN && order <= MAX)) ? SPV_SUCCESS : RET; }