Optional typed literal number should be concrete in BinaryParser.
authorLei Zhang <antiagainst@google.com>
Tue, 10 Nov 2015 19:29:35 +0000 (14:29 -0500)
committerDavid Neto <dneto@google.com>
Tue, 10 Nov 2015 20:58:16 +0000 (15:58 -0500)
source/binary.cpp
test/BinaryToText.cpp

index f3df4ad..94e51a2 100644 (file)
@@ -451,6 +451,7 @@ spv_result_t Parser::parseOperand(spv_parsed_instruction_t* inst,
 
     case SPV_OPERAND_TYPE_TYPED_LITERAL_NUMBER:
     case SPV_OPERAND_TYPE_OPTIONAL_TYPED_LITERAL_INTEGER:
+      parsed_operand.type = SPV_OPERAND_TYPE_TYPED_LITERAL_NUMBER;
       if (inst->opcode == SpvOpSwitch) {
         // The literal operands have the same type as the value
         // referenced by the selector Id.
index eb1cd1f..61e6ab6 100644 (file)
@@ -497,4 +497,14 @@ TEST_F(MaskSorting, MasksAreSortedFromLSBToMSB) {
                  " %5 %6 %7 %8 %9 %10 %11 %12 %13\n"));
 }
 
+using OperandTypeTest = spvtest::TextToBinaryTest;
+
+TEST_F(OperandTypeTest, OptionalTypedLiteralNumber) {
+  const std::string input =
+      "%1 = OpTypeInt 32 0\n"
+      "%2 = OpConstant %1 42\n"
+      "OpSwitch %2 %3 100 %4\n";
+  EXPECT_EQ(input, EncodeAndDecodeSuccessfully(input));
+}
+
 }  // anonymous namespace