From cb009b3862dc2d5d93a0831c65ac112a72c1645b Mon Sep 17 00:00:00 2001 From: Ehsan Nasiri Date: Tue, 17 Jan 2017 15:10:43 -0500 Subject: [PATCH] Fixes issue #497. The Linkage Attributes Decoration cannot be applied to functions targeted by an OpEntryPoint instruction. --- source/validate_decorations.cpp | 15 +++++++++++++++ test/val/val_decoration_test.cpp | 23 +++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/source/validate_decorations.cpp b/source/validate_decorations.cpp index d7e56e6..134dea8 100644 --- a/source/validate_decorations.cpp +++ b/source/validate_decorations.cpp @@ -107,8 +107,23 @@ spv_result_t ValidateDecorations(ValidationState_t& vstate) { "BuiltIn, consumed per entry-point. Entry Point id " << entry_point << " does not meet this requirement."; } + // The LinkageAttributes Decoration cannot be applied to functions targeted + // by an OpEntryPoint instruction + for (auto& decoration : vstate.id_decorations(entry_point)) { + if (SpvDecorationLinkageAttributes == decoration.dec_type()) { + const char* linkage_name = + reinterpret_cast(&decoration.params()[0]); + return vstate.diag(SPV_ERROR_INVALID_BINARY) + << "The LinkageAttributes Decoration (Linkage name: " + << linkage_name << ") cannot be applied to function id " + << entry_point + << " because it is targeted by an OpEntryPoint instruction."; + } + } } + // TODO: Refactor this function into smaller pieces. + return SPV_SUCCESS; } diff --git a/test/val/val_decoration_test.cpp b/test/val/val_decoration_test.cpp index 8315959..eab9166 100644 --- a/test/val/val_decoration_test.cpp +++ b/test/val/val_decoration_test.cpp @@ -337,5 +337,28 @@ TEST_F(ValidateDecorations, NoBuiltInObjectsConsumedByOpEntryPointGood) { EXPECT_EQ(SPV_SUCCESS, ValidateAndRetrieveValidationState()); } +TEST_F(ValidateDecorations, EntryPointFunctionHasLinkageAttributeBad) { + string spirv = R"( + OpCapability Shader + OpCapability Linkage + OpMemoryModel Logical GLSL450 + OpEntryPoint GLCompute %main "main" + OpDecorate %main LinkageAttributes "import_main" Import +%1 = OpTypeVoid +%2 = OpTypeFunction %1 +%main = OpFunction %1 None %2 +%4 = OpLabel + OpReturn + OpFunctionEnd +)"; + CompileSuccessfully(spirv.c_str()); + EXPECT_EQ(SPV_ERROR_INVALID_BINARY, ValidateInstructions()); + EXPECT_THAT( + getDiagnosticString(), + HasSubstr("The LinkageAttributes Decoration (Linkage name: import_main) " + "cannot be applied to function id 1 because it is targeted by " + "an OpEntryPoint instruction.")); +} + } // anonymous namespace -- 2.7.4