Skip to content

Commit 392a280

Browse files
authored
spirv-val: forbid multiple graph entry points with the same name (KhronosGroup#6754)
Specification update: KhronosGroup/SPIRV-Registry#426 Signed-off-by: Kevin Petit <kevin.petit@arm.com>
1 parent 113784c commit 392a280

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

source/val/validate.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <iterator>
1919
#include <memory>
2020
#include <string>
21+
#include <unordered_set>
2122
#include <vector>
2223

2324
#include "source/binary.h"
@@ -225,6 +226,7 @@ spv_result_t ValidateBinaryUsingContextAndValidationState(
225226
bool has_mask_task_nv = false;
226227
bool has_mask_task_ext = false;
227228
std::vector<Instruction*> visited_entry_points;
229+
std::unordered_set<std::string> graph_entry_point_names;
228230
for (auto& instruction : vstate->ordered_instructions()) {
229231
{
230232
// In order to do this work outside of Process Instruction we need to be
@@ -281,7 +283,12 @@ spv_result_t ValidateBinaryUsingContextAndValidationState(
281283
execution_model == spv::ExecutionModel::MeshEXT);
282284
}
283285
if (inst->opcode() == spv::Op::OpGraphEntryPointARM) {
284-
const auto graph = inst->GetOperandAs<uint32_t>(1);
286+
const std::string name = inst->GetOperandAs<std::string>(1);
287+
if (!graph_entry_point_names.insert(name).second) {
288+
return vstate->diag(SPV_ERROR_INVALID_DATA, inst)
289+
<< "Graph entry points cannot share the same name.";
290+
}
291+
const auto graph = inst->GetOperandAs<uint32_t>(0);
285292
vstate->RegisterGraphEntryPoint(graph);
286293
}
287294
if (inst->opcode() == spv::Op::OpFunctionCall) {

test/val/val_graph_test.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,24 @@ TEST_F(ValidateGraph,
663663
"corresponding graph I/O '.*'.*"));
664664
}
665665

666+
TEST_F(ValidateGraph, InvalidGraphEntryPointDuplicateNames) {
667+
const std::string src = R"(
668+
%graph_type = OpTypeGraphARM 1 %int8tensor %int8tensor
669+
OpGraphEntryPointARM %graph "duplicatename" %var_int8tensor %var_int8tensor
670+
OpGraphEntryPointARM %graph "duplicatename" %var_int8tensor %var_int8tensor
671+
%graph = OpGraphARM %graph_type
672+
%in = OpGraphInputARM %int8tensor %uint_0
673+
OpGraphSetOutputARM %in %uint_0
674+
OpGraphEndARM
675+
)";
676+
std::string spvasm = GenerateModule(src);
677+
678+
CompileSuccessfully(spvasm, SPVENV);
679+
EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPVENV));
680+
EXPECT_THAT(getDiagnosticString(),
681+
HasSubstr("Graph entry points cannot share the same name"));
682+
}
683+
666684
//
667685
// Graph tests
668686
//

0 commit comments

Comments
 (0)