Fix conversion warnings reported by GCC.
authorDavid Neto <dneto@google.com>
Wed, 6 Jan 2016 18:08:39 +0000 (13:08 -0500)
committerDavid Neto <dneto@google.com>
Wed, 6 Jan 2016 22:36:33 +0000 (17:36 -0500)
include/util/hex_float.h
source/binary.cpp
source/ext_inst.cpp
source/opcode.cpp
source/operand.cpp
source/validate_types.h

index 6ec7a8b..3ad2039 100644 (file)
@@ -274,7 +274,7 @@ class HexFloat {
 
   // How far from the right edge the fraction is shifted.
   static const uint32_t fraction_right_shift =
-      (sizeof(uint_type) * 8) - num_fraction_bits;
+      static_cast<uint32_t>(sizeof(uint_type) * 8) - num_fraction_bits;
 
   // The maximum representable unbiased exponent.
   static const int_type max_exponent =
@@ -798,7 +798,7 @@ std::istream& operator>>(std::istream& is, HexFloat<T, Traits>& value) {
       // We know this is not denormalized since we have stripped all leading
       // zeroes and we are not a ".".
       is_denorm = false;
-      uint8_t number = get_nibble_from_character(next_char);
+      int number = get_nibble_from_character(next_char);
       for (int i = 0; i < 4; ++i, number <<= 1) {
         uint_type write_bit = (number & 0x8) ? 0x1 : 0x0;
         if (bits_written) {
index 94cbf9c..f504a01 100755 (executable)
@@ -73,7 +73,7 @@ spv_operand_type_t spvBinaryOperandInfo(const uint32_t word,
   spv_operand_type_t type;
   if (operandIndex < opcodeEntry->numTypes) {
     // NOTE: Do operand table lookup to set operandEntry if successful
-    uint16_t index = operandIndex - 1;
+    const int index = operandIndex - 1;
     type = opcodeEntry->operandTypes[index];
     spv_operand_desc entry = nullptr;
     if (!spvOperandTableValueLookup(operandTable, type, word, &entry)) {
@@ -83,7 +83,7 @@ spv_operand_type_t spvBinaryOperandInfo(const uint32_t word,
     }
   } else if (*pOperandEntry) {
     // NOTE: Use specified operand entry operand type for this word
-    uint16_t index = operandIndex - opcodeEntry->numTypes;
+    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
@@ -91,12 +91,12 @@ spv_operand_type_t spvBinaryOperandInfo(const uint32_t word,
     assert(0 &&
            "This case is previously untested, remove this assert and ensure it "
            "is behaving correctly!");
-    uint16_t lastIndex = opcodeEntry->numTypes - 1;
-    uint16_t index = lastIndex + ((operandIndex - lastIndex) % 2);
+    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
-    uint16_t index = opcodeEntry->numTypes - 1;
+    const int index = opcodeEntry->numTypes - 1;
     type = opcodeEntry->operandTypes[index];
   }
   return type;
index d1a0ab9..41f1723 100644 (file)
@@ -149,14 +149,18 @@ spv_result_t spvExtInstTableGet(spv_ext_inst_table* pExtInstTable) {
 
   static const spv_ext_inst_group_t groups[] = {
       {SPV_EXT_INST_TYPE_GLSL_STD_450,
-       sizeof(glslStd450Entries) / sizeof(spv_ext_inst_desc_t),
+       static_cast<uint32_t>(sizeof(glslStd450Entries) /
+                             sizeof(spv_ext_inst_desc_t)),
        glslStd450Entries},
       {SPV_EXT_INST_TYPE_OPENCL_STD,
-       sizeof(openclEntries) / sizeof(spv_ext_inst_desc_t), openclEntries},
+       static_cast<uint32_t>(sizeof(openclEntries) /
+                             sizeof(spv_ext_inst_desc_t)),
+       openclEntries},
   };
 
   static const spv_ext_inst_table_t table = {
-      sizeof(groups) / sizeof(spv_ext_inst_group_t), groups};
+      static_cast<uint32_t>(sizeof(groups) / sizeof(spv_ext_inst_group_t)),
+      groups};
 
   *pExtInstTable = &table;
 
index 114fe84..caaeddb 100644 (file)
@@ -263,10 +263,10 @@ void spvOpcodeTableInitialize(spv_opcode_desc_t* entries,
     // Result ID always comes next, if present
     if (opcode.hasResult)
       opcode.operandTypes[opcode.numTypes++] = SPV_OPERAND_TYPE_RESULT_ID;
-    const uint16_t maxNumOperands =
-        sizeof(opcode.operandTypes) / sizeof(opcode.operandTypes[0]);
-    const uint16_t maxNumClasses =
-        sizeof(opcode.operandClass) / sizeof(opcode.operandClass[0]);
+    const uint16_t maxNumOperands = static_cast<uint16_t>(
+        sizeof(opcode.operandTypes) / sizeof(opcode.operandTypes[0]));
+    const uint16_t maxNumClasses = static_cast<uint16_t>(
+        sizeof(opcode.operandClass) / sizeof(opcode.operandClass[0]));
     for (uint16_t classIndex = 0;
          opcode.numTypes < maxNumOperands && classIndex < maxNumClasses;
          classIndex++) {
@@ -340,7 +340,8 @@ spv_result_t spvOpcodeTableGet(spv_opcode_table* pInstTable) {
   if (!copied_entries) return SPV_ERROR_OUT_OF_MEMORY;
   ::memcpy(copied_entries, opcodeTableEntries, size);
 
-  const uint32_t count = sizeof(opcodeTableEntries) / sizeof(spv_opcode_desc_t);
+  const uint32_t count = static_cast<uint32_t>(sizeof(opcodeTableEntries) /
+                                               sizeof(spv_opcode_desc_t));
   spv_opcode_table_t* table = new spv_opcode_table_t{count, copied_entries};
 
   spvOpcodeTableInitialize(copied_entries, count);
index 02c1b03..bcb372a 100644 (file)
@@ -1007,108 +1007,114 @@ static const spv_operand_desc_t capabilityInfoEntries[] = {
 #undef CASE
 #undef CASE_CAP
 
+// Evaluates to the number of elements of array A.
+// If we could use constexpr, then we could make this a template function.
+// If the source arrays were std::array, then we could have used
+// std::array::size.
+#define ARRAY_SIZE(A) (static_cast<uint32_t>(sizeof(A)/sizeof(A[0])))
+
 static const spv_operand_desc_group_t opcodeEntryTypes[] = {
+  // TODO(dneto): Reformat this table.
     {SPV_OPERAND_TYPE_SOURCE_LANGUAGE,
-     sizeof(sourceLanguageEntries) / sizeof(spv_operand_desc_t),
+     ARRAY_SIZE(sourceLanguageEntries),
      sourceLanguageEntries},
     {SPV_OPERAND_TYPE_EXECUTION_MODEL,
-     sizeof(executionModelEntries) / sizeof(spv_operand_desc_t),
+     ARRAY_SIZE(executionModelEntries),
      executionModelEntries},
     {SPV_OPERAND_TYPE_ADDRESSING_MODEL,
-     sizeof(addressingModelEntries) / sizeof(spv_operand_desc_t),
+     ARRAY_SIZE(addressingModelEntries),
      addressingModelEntries},
     {SPV_OPERAND_TYPE_MEMORY_MODEL,
-     sizeof(memoryModelEntries) / sizeof(spv_operand_desc_t),
+     ARRAY_SIZE(memoryModelEntries),
      memoryModelEntries},
     {SPV_OPERAND_TYPE_EXECUTION_MODE,
-     sizeof(executionModeEntries) / sizeof(spv_operand_desc_t),
+     ARRAY_SIZE(executionModeEntries),
      executionModeEntries},
     {SPV_OPERAND_TYPE_STORAGE_CLASS,
-     sizeof(storageClassEntries) / sizeof(spv_operand_desc_t),
+     ARRAY_SIZE(storageClassEntries),
      storageClassEntries},
     {SPV_OPERAND_TYPE_DIMENSIONALITY,
-     sizeof(dimensionalityEntries) / sizeof(spv_operand_desc_t),
+     ARRAY_SIZE(dimensionalityEntries),
      dimensionalityEntries},
     {SPV_OPERAND_TYPE_SAMPLER_ADDRESSING_MODE,
-     sizeof(samplerAddressingModeEntries) / sizeof(spv_operand_desc_t),
+     ARRAY_SIZE(samplerAddressingModeEntries),
      samplerAddressingModeEntries},
     {SPV_OPERAND_TYPE_SAMPLER_FILTER_MODE,
-     sizeof(samplerFilterModeEntries) / sizeof(spv_operand_desc_t),
+     ARRAY_SIZE(samplerFilterModeEntries),
      samplerFilterModeEntries},
     {SPV_OPERAND_TYPE_SAMPLER_IMAGE_FORMAT,
-     sizeof(samplerImageFormatEntries) / sizeof(spv_operand_desc_t),
+     ARRAY_SIZE(samplerImageFormatEntries),
      samplerImageFormatEntries},
     {SPV_OPERAND_TYPE_IMAGE_CHANNEL_ORDER,
-     sizeof(imageChannelOrderEntries) / sizeof(spv_operand_desc_t),
+     ARRAY_SIZE(imageChannelOrderEntries),
      imageChannelOrderEntries},
     {SPV_OPERAND_TYPE_IMAGE_CHANNEL_DATA_TYPE,
-     sizeof(imageChannelDataTypeEntries) / sizeof(spv_operand_desc_t),
+     ARRAY_SIZE(imageChannelDataTypeEntries),
      imageChannelDataTypeEntries},
     {SPV_OPERAND_TYPE_IMAGE,
-     sizeof(imageOperandEntries) / sizeof(spv_operand_desc_t),
+     ARRAY_SIZE(imageOperandEntries),
      imageOperandEntries},
     {SPV_OPERAND_TYPE_OPTIONAL_IMAGE,  // Same as *_IMAGE
-     sizeof(imageOperandEntries) / sizeof(spv_operand_desc_t),
+     ARRAY_SIZE(imageOperandEntries),
      imageOperandEntries},
     {SPV_OPERAND_TYPE_FP_FAST_MATH_MODE,
-     sizeof(fpFastMathModeEntries) / sizeof(spv_operand_desc_t),
+     ARRAY_SIZE(fpFastMathModeEntries),
      fpFastMathModeEntries},
     {SPV_OPERAND_TYPE_FP_ROUNDING_MODE,
-     sizeof(fpRoundingModeEntries) / sizeof(spv_operand_desc_t),
+     ARRAY_SIZE(fpRoundingModeEntries),
      fpRoundingModeEntries},
     {SPV_OPERAND_TYPE_LINKAGE_TYPE,
-     sizeof(linkageTypeEntries) / sizeof(spv_operand_desc_t),
+     ARRAY_SIZE(linkageTypeEntries),
      linkageTypeEntries},
     {SPV_OPERAND_TYPE_ACCESS_QUALIFIER,
-     sizeof(accessQualifierEntries) / sizeof(spv_operand_desc_t),
+     ARRAY_SIZE(accessQualifierEntries),
      accessQualifierEntries},
     {SPV_OPERAND_TYPE_FUNCTION_PARAMETER_ATTRIBUTE,
-     sizeof(functionParameterAttributeEntries) / sizeof(spv_operand_desc_t),
+     ARRAY_SIZE(functionParameterAttributeEntries),
      functionParameterAttributeEntries},
     {SPV_OPERAND_TYPE_DECORATION,
-     sizeof(decorationEntries) / sizeof(spv_operand_desc_t), decorationEntries},
+     ARRAY_SIZE(decorationEntries), decorationEntries},
     {SPV_OPERAND_TYPE_BUILT_IN,
-     sizeof(builtInEntries) / sizeof(spv_operand_desc_t), builtInEntries},
+     ARRAY_SIZE(builtInEntries), builtInEntries},
     {SPV_OPERAND_TYPE_SELECTION_CONTROL,
-     sizeof(selectionControlEntries) / sizeof(spv_operand_desc_t),
+     ARRAY_SIZE(selectionControlEntries),
      selectionControlEntries},
     {SPV_OPERAND_TYPE_LOOP_CONTROL,
-     sizeof(loopControlEntries) / sizeof(spv_operand_desc_t),
+     ARRAY_SIZE(loopControlEntries),
      loopControlEntries},
     {SPV_OPERAND_TYPE_FUNCTION_CONTROL,
-     sizeof(functionControlEntries) / sizeof(spv_operand_desc_t),
+     ARRAY_SIZE(functionControlEntries),
      functionControlEntries},
     {SPV_OPERAND_TYPE_MEMORY_SEMANTICS_ID,
-     sizeof(memorySemanticsEntries) / sizeof(spv_operand_desc_t),
+     ARRAY_SIZE(memorySemanticsEntries),
      memorySemanticsEntries},
     {SPV_OPERAND_TYPE_MEMORY_ACCESS,
-     sizeof(memoryAccessEntries) / sizeof(spv_operand_desc_t),
+     ARRAY_SIZE(memoryAccessEntries),
      memoryAccessEntries},
     {SPV_OPERAND_TYPE_OPTIONAL_MEMORY_ACCESS,  // Same as *_MEMORY_ACCESS
-     sizeof(memoryAccessEntries) / sizeof(spv_operand_desc_t),
+     ARRAY_SIZE(memoryAccessEntries),
      memoryAccessEntries},
     {SPV_OPERAND_TYPE_SCOPE_ID,
-     sizeof(scopeEntries) / sizeof(spv_operand_desc_t), scopeEntries},
+     ARRAY_SIZE(scopeEntries), scopeEntries},
     {SPV_OPERAND_TYPE_GROUP_OPERATION,
-     sizeof(groupOperationEntries) / sizeof(spv_operand_desc_t),
+     ARRAY_SIZE(groupOperationEntries),
      groupOperationEntries},
     {SPV_OPERAND_TYPE_KERNEL_ENQ_FLAGS,
-     sizeof(kernelKernelEnqueueFlagssEntries) / sizeof(spv_operand_desc_t),
+     ARRAY_SIZE(kernelKernelEnqueueFlagssEntries),
      kernelKernelEnqueueFlagssEntries},
     {SPV_OPERAND_TYPE_KERNEL_PROFILING_INFO,
-     sizeof(kernelProfilingInfoEntries) / sizeof(spv_operand_desc_t),
+     ARRAY_SIZE(kernelProfilingInfoEntries),
      kernelProfilingInfoEntries},
     {SPV_OPERAND_TYPE_CAPABILITY,
-     sizeof(capabilityInfoEntries) / sizeof(spv_operand_desc_t),
+     ARRAY_SIZE(capabilityInfoEntries),
      capabilityInfoEntries},
 };
 
 spv_result_t spvOperandTableGet(spv_operand_table* pOperandTable) {
   if (!pOperandTable) return SPV_ERROR_INVALID_POINTER;
 
-  static const spv_operand_table_t table = {
-      sizeof(opcodeEntryTypes) / sizeof(spv_operand_desc_group_t),
-      opcodeEntryTypes};
+  static const spv_operand_table_t table = {ARRAY_SIZE(opcodeEntryTypes),
+                                            opcodeEntryTypes};
 
   *pOperandTable = &table;
 
index d9e31e3..d64e2d9 100644 (file)
@@ -112,7 +112,7 @@ class ValidationState_t {
 
   // The stage which is being processed by the validation. Partially based on
   // Section 2.4. Logical Layout of a Module
-  uint8_t module_layout_order_stage_;
+  uint32_t module_layout_order_stage_;
 
   // The section of the code being processed
   ModuleLayoutSection current_layout_stage_;