diff --git a/readme.md b/readme.md index 4ebc22ff..6f549d9b 100644 --- a/readme.md +++ b/readme.md @@ -32,6 +32,7 @@ The validator is incomplete. See the Future Work section for more information. * Values: Fixes values for some decorations: BuiltIn LocalInvocationId, and BuiltIn SubgroupId * All handling of FPFastMathMode masks. + * LinkageAttributes now requires the literal string operand. 2015-09-09 * Avoid confusion about ownership of storage: diff --git a/source/operand.cpp b/source/operand.cpp index 1f15f54a..e52036f7 100644 --- a/source/operand.cpp +++ b/source/operand.cpp @@ -751,7 +751,7 @@ static const spv_operand_desc_t decorationEntries[] = { DecorationLinkageAttributes, SPV_OPCODE_FLAGS_CAPABILITIES, CapabilityLinkage, - {SPV_OPERAND_TYPE_LINKAGE_TYPE, SPV_OPERAND_TYPE_NONE}}, + {SPV_OPERAND_TYPE_LITERAL_STRING, SPV_OPERAND_TYPE_LINKAGE_TYPE, SPV_OPERAND_TYPE_NONE}}, }; static const spv_operand_desc_t builtInEntries[] = { diff --git a/test/TextToBinary.Annotation.cpp b/test/TextToBinary.Annotation.cpp index 9844c73d..80873791 100644 --- a/test/TextToBinary.Annotation.cpp +++ b/test/TextToBinary.Annotation.cpp @@ -236,7 +236,44 @@ INSTANTIATE_TEST_CASE_P(TextToBinaryDecorateFPFastMathMode, OpDecorateEnumTest, #undef CASE // clang-format on -// TODO(dneto): OpDecorate with Linkage attributes +// Test OpDecorate Linkage + +// A single test case for a linkage +struct DecorateLinkageCase { + const uint32_t linkage_type_value; + const std::string linkage_type_name; + const std::string external_name; +}; + +using OpDecorateLinkageTest = test_fixture::TextToBinaryTestBase< + ::testing::TestWithParam>; + +TEST_P(OpDecorateLinkageTest, AnyLinkageDecoration) { + // This string should assemble, but should not validate. + std::string input = "OpDecorate %1 LinkageAttributes \"" + GetParam().external_name + + "\" " + GetParam().linkage_type_name; + std::vector expected_operands{1, spv::DecorationLinkageAttributes}; + std::vector encoded_external_name = + MakeVector(GetParam().external_name); + expected_operands.insert(expected_operands.end(), + encoded_external_name.begin(), + encoded_external_name.end()); + expected_operands.push_back(GetParam().linkage_type_value); + EXPECT_THAT(CompiledInstructions(input), + Eq(MakeInstruction(spv::OpDecorate, expected_operands))); +} + +// clang-format off +#define CASE(ENUM) spv::LinkageType##ENUM, #ENUM +INSTANTIATE_TEST_CASE_P(TextToBinaryDecorateLinkage, OpDecorateLinkageTest, + ::testing::ValuesIn(std::vector{ + { CASE(Import), "a" }, + { CASE(Export), "foo" }, + { CASE(Import), "some kind of long name with spaces etc." }, + // TODO(dneto): utf-8, escaping, quoting cases. + })); +#undef CASE +// clang-format on // TODO(dneto): OpMemberDecorate // TODO(dneto): OpDecorationGroup