Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assembler: Can't set an ID in instruction without result ID #2852

Merged
merged 1 commit into from
Sep 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions source/text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,11 @@ spv_result_t spvTextEncodeOpcode(const spvtools::AssemblyGrammar& grammar,
<< "Expected <result-id> at the beginning of an instruction, found '"
<< firstWord << "'.";
}
if (!opcodeEntry->hasResult && !result_id.empty()) {
return context->diagnostic()
<< "Cannot set ID " << result_id << " because " << opcodeName
<< " does not produce a result ID.";
}
pInst->opcode = opcodeEntry->opcode;
context->setPosition(nextPosition);
// Reserve the first word for the instruction.
Expand Down
15 changes: 14 additions & 1 deletion test/assembly_format_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace {
using spvtest::ScopedContext;
using spvtest::TextToBinaryTest;

TEST_F(TextToBinaryTest, NotPlacingResultIDAtTheBeginning) {
TEST_F(TextToBinaryTest, InstOpcodeProducesResultIDButNoIDDefinedFails) {
SetText("OpTypeMatrix %1 %2 1000");
EXPECT_EQ(SPV_ERROR_INVALID_TEXT,
spvTextToBinary(ScopedContext().context, text.str, text.length,
Expand All @@ -33,5 +33,18 @@ TEST_F(TextToBinaryTest, NotPlacingResultIDAtTheBeginning) {
EXPECT_EQ(0u, diagnostic->position.line);
}

TEST_F(TextToBinaryTest,
InstDefinesResultIDButOpcodeDoesNotProduceAResultFails) {
SetText("\n\n%foo = OpName %1 \"bar\"");
EXPECT_EQ(SPV_ERROR_INVALID_TEXT,
spvTextToBinary(ScopedContext().context, text.str, text.length,
&binary, &diagnostic));
ASSERT_NE(nullptr, diagnostic);
EXPECT_STREQ(
"Cannot set ID %foo because OpName does not produce a result ID.",
diagnostic->error);
EXPECT_EQ(2u, diagnostic->position.line);
}

} // namespace
} // namespace svptools
4 changes: 2 additions & 2 deletions test/c_interface_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ TEST(CInterface, DefaultConsumerNullDiagnosticForInvalidValidating) {
}

TEST(CInterface, SpecifyConsumerNullDiagnosticForAssembling) {
const char input_text[] = "%1 = OpName\n";
const char input_text[] = " OpName\n";

auto context = spvContextCreate(SPV_ENV_UNIVERSAL_1_1);
int invocation = 0;
Expand Down Expand Up @@ -213,7 +213,7 @@ TEST(CInterface, SpecifyConsumerNullDiagnosticForValidating) {
// When having both a consumer and an diagnostic object, the diagnostic object
// should take priority.
TEST(CInterface, SpecifyConsumerSpecifyDiagnosticForAssembling) {
const char input_text[] = "%1 = OpName";
const char input_text[] = " OpName";

auto context = spvContextCreate(SPV_ENV_UNIVERSAL_1_1);
int invocation = 0;
Expand Down
6 changes: 3 additions & 3 deletions test/opt/ccp_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,10 +570,10 @@ TEST_F(CCPTest, SkipSpecConstantInstrucitons) {
%10 = OpSpecConstantFalse %bool
%main = OpFunction %void None %4
%11 = OpLabel
%12 = OpBranchConditional %10 %l1 %l2
%l1 = OpLabel
OpBranchConditional %10 %L1 %L2
%L1 = OpLabel
OpReturn
%l2 = OpLabel
%L2 = OpLabel
OpReturn
OpFunctionEnd
)";
Expand Down
2 changes: 1 addition & 1 deletion test/opt/copy_prop_array_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,7 @@ OpDecorate %MyCBuffer Binding 0
OpStore %23 %35
%36 = OpAccessChain %_ptr_Function_v4float %23 %24
%37 = OpLoad %v4float %36
%39 = OpStore %36 %v4const
OpStore %36 %v4const
OpStore %out_var_SV_Target %37
OpReturn
OpFunctionEnd
Expand Down
5 changes: 3 additions & 2 deletions test/opt/optimizer_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ TEST_P(VulkanToWebGPUPassTest, Ran) {
std::vector<uint32_t> optimized;
class ValidatorOptions validator_options;
ASSERT_TRUE(opt.Run(binary.data(), binary.size(), &optimized,
validator_options, true));
validator_options, true))
<< GetParam().input << "\n";
std::string disassembly;
{
SpirvTools tools(SPV_ENV_WEBGPU_0);
Expand Down Expand Up @@ -412,7 +413,7 @@ INSTANTIATE_TEST_SUITE_P(
"%void_f = OpTypeFunction %void\n"
"%func = OpFunction %void None %void_f\n"
"%label = OpLabel\n"
"%val0 = OpAtomicStore %u32_var %cross_device "
" OpAtomicStore %u32_var %cross_device "
"%acquire_release_atomic_counter_workgroup %u32_1\n"
"%val1 = OpAtomicIIncrement %u32 %u32_var %cross_device "
"%acquire_release_atomic_counter_workgroup\n"
Expand Down
4 changes: 2 additions & 2 deletions test/opt/upgrade_memory_model_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ OpMemoryModel Logical GLSL450
%func = OpFunction %void None %func_ty
%1 = OpLabel
%ld = OpLoad %int %var
%st = OpStore %var %ld
OpStore %var %ld
OpReturn
OpFunctionEnd
)";
Expand All @@ -116,7 +116,7 @@ OpMemoryModel Logical GLSL450
%param = OpFunctionParameter %ptr_int_Workgroup
%1 = OpLabel
%ld = OpLoad %int %param
%st = OpStore %param %ld
OpStore %param %ld
OpReturn
OpFunctionEnd
)";
Expand Down
14 changes: 9 additions & 5 deletions test/text_to_binary.constant_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,6 @@ INSTANTIATE_TEST_SUITE_P(

using OpConstantInvalidTypeTest =
spvtest::TextToBinaryTestBase<::testing::TestWithParam<std::string>>;

TEST_P(OpConstantInvalidTypeTest, InvalidTypes) {
const std::string input = "%1 = " + GetParam() +
"\n"
Expand Down Expand Up @@ -360,8 +359,11 @@ INSTANTIATE_TEST_SUITE_P(
"OpTypeReserveId",
"OpTypeQueue",
"OpTypePipe ReadOnly",
"OpTypeForwardPointer %a UniformConstant",
// At least one thing that isn't a type at all

// Skip OpTypeForwardPointer doesn't even produce a result ID.
// The assembler errors out if we try to check it in this scenario.

// Try at least one thing that isn't a type at all
"OpNot %a %b"
},
}));
Expand Down Expand Up @@ -470,8 +472,10 @@ INSTANTIATE_TEST_SUITE_P(
"OpTypeReserveId",
"OpTypeQueue",
"OpTypePipe ReadOnly",
"OpTypeForwardPointer %a UniformConstant",
// At least one thing that isn't a type at all

// Skip testing OpTypeForwardPointer because it doesn't even produce a result ID.

// Try at least one thing that isn't a type at all
"OpNot %a %b"
},
}));
Expand Down
9 changes: 6 additions & 3 deletions test/text_to_binary.control_flow_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ TEST_P(OpSwitchInvalidTypeTestCase, InvalidTypes) {
"%1 = " + GetParam() +
"\n"
"%3 = OpCopyObject %1 %2\n" // We only care the type of the expression
"%4 = OpSwitch %3 %default 32 %c\n";
" OpSwitch %3 %default 32 %c\n";
EXPECT_THAT(CompileFailure(input),
Eq("The selector operand for OpSwitch must be the result of an "
"instruction that generates an integer scalar"));
Expand Down Expand Up @@ -371,8 +371,11 @@ INSTANTIATE_TEST_SUITE_P(
"OpTypeReserveId",
"OpTypeQueue",
"OpTypePipe ReadOnly",
"OpTypeForwardPointer %a UniformConstant",
// At least one thing that isn't a type at all

// Skip OpTypeForwardPointer becasuse it doesn't even produce a result
// ID.

// At least one thing that isn't a type at all
"OpNot %a %b"
},
}));
Expand Down
4 changes: 2 additions & 2 deletions test/val/val_adjacency_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ OpBranch %end_label
%false_label = OpLabel
OpBranch %end_label
%end_label = OpLabel
%line = OpLine %string 0 0
OpLine %string 0 0
%result = OpPhi %bool %true %true_label %false %false_label
)";

Expand Down Expand Up @@ -178,7 +178,7 @@ OpBranch %end_label
%false_label = OpLabel
OpBranch %end_label
%end_label = OpLabel
%line = OpLine %string 0 0
OpLine %string 0 0
%result = OpPhi %bool %true %true_label %false %false_label
)";

Expand Down
18 changes: 9 additions & 9 deletions test/val/val_atomics_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ OpAtomicStore %f32_var %device %relaxed %u32_1

TEST_F(ValidateAtomics, AtomicExchangeShaderSuccess) {
const std::string body = R"(
%val1 = OpAtomicStore %u32_var %device %relaxed %u32_1
OpAtomicStore %u32_var %device %relaxed %u32_1
%val2 = OpAtomicExchange %u32 %u32_var %device %relaxed %u32_0
)";

Expand All @@ -720,7 +720,7 @@ TEST_F(ValidateAtomics, AtomicExchangeKernelSuccess) {
const std::string body = R"(
OpAtomicStore %f32_var %device %relaxed %f32_1
%val2 = OpAtomicExchange %f32 %f32_var %device %relaxed %f32_0
%val3 = OpAtomicStore %u32_var %device %relaxed %u32_1
OpAtomicStore %u32_var %device %relaxed %u32_1
%val4 = OpAtomicExchange %u32 %u32_var %device %relaxed %u32_0
)";

Expand All @@ -743,7 +743,7 @@ OpAtomicStore %f32_var %device %relaxed %f32_1

TEST_F(ValidateAtomics, AtomicExchangeWrongResultType) {
const std::string body = R"(
%val1 = OpStore %f32vec4_var %f32vec4_0000
OpStore %f32vec4_var %f32vec4_0000
%val2 = OpAtomicExchange %f32vec4 %f32vec4_var %device %relaxed %f32vec4_0000
)";

Expand All @@ -768,7 +768,7 @@ TEST_F(ValidateAtomics, AtomicExchangeWrongPointerType) {

TEST_F(ValidateAtomics, AtomicExchangeWrongPointerDataType) {
const std::string body = R"(
%val1 = OpStore %f32vec4_var %f32vec4_0000
OpStore %f32vec4_var %f32vec4_0000
%val2 = OpAtomicExchange %f32 %f32vec4_var %device %relaxed %f32vec4_0000
)";

Expand Down Expand Up @@ -822,7 +822,7 @@ OpAtomicStore %f32_var %device %relaxed %f32_1

TEST_F(ValidateAtomics, AtomicCompareExchangeShaderSuccess) {
const std::string body = R"(
%val1 = OpAtomicStore %u32_var %device %relaxed %u32_1
OpAtomicStore %u32_var %device %relaxed %u32_1
%val2 = OpAtomicCompareExchange %u32 %u32_var %device %relaxed %relaxed %u32_0 %u32_0
)";

Expand All @@ -834,7 +834,7 @@ TEST_F(ValidateAtomics, AtomicCompareExchangeKernelSuccess) {
const std::string body = R"(
OpAtomicStore %f32_var %device %relaxed %f32_1
%val2 = OpAtomicCompareExchange %f32 %f32_var %device %relaxed %relaxed %f32_0 %f32_1
%val3 = OpAtomicStore %u32_var %device %relaxed %u32_1
OpAtomicStore %u32_var %device %relaxed %u32_1
%val4 = OpAtomicCompareExchange %u32 %u32_var %device %relaxed %relaxed %u32_0 %u32_0
)";

Expand All @@ -857,7 +857,7 @@ OpAtomicStore %f32_var %device %relaxed %f32_1

TEST_F(ValidateAtomics, AtomicCompareExchangeWrongResultType) {
const std::string body = R"(
%val1 = OpStore %f32vec4_var %f32vec4_0000
OpStore %f32vec4_var %f32vec4_0000
%val2 = OpAtomicCompareExchange %f32vec4 %f32vec4_var %device %relaxed %relaxed %f32vec4_0000 %f32vec4_0000
)";

Expand All @@ -882,7 +882,7 @@ TEST_F(ValidateAtomics, AtomicCompareExchangeWrongPointerType) {

TEST_F(ValidateAtomics, AtomicCompareExchangeWrongPointerDataType) {
const std::string body = R"(
%val1 = OpStore %f32vec4_var %f32vec4_0000
OpStore %f32vec4_var %f32vec4_0000
%val2 = OpAtomicCompareExchange %f32 %f32vec4_var %device %relaxed %relaxed %f32_0 %f32_1
)";

Expand Down Expand Up @@ -975,7 +975,7 @@ OpAtomicStore %f32_var %device %relaxed %f32_1

TEST_F(ValidateAtomics, AtomicCompareExchangeWeakSuccess) {
const std::string body = R"(
%val3 = OpAtomicStore %u32_var %device %relaxed %u32_1
OpAtomicStore %u32_var %device %relaxed %u32_1
%val4 = OpAtomicCompareExchangeWeak %u32 %u32_var %device %relaxed %relaxed %u32_0 %u32_0
)";

Expand Down
4 changes: 2 additions & 2 deletions test/val/val_id_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2317,8 +2317,8 @@ TEST_F(ValidateIdWithMessage, OpLoadGood) {
%6 = OpFunction %1 None %4
%7 = OpLabel
%8 = OpLoad %2 %5
%9 = OpReturn
%10 = OpFunctionEnd
OpReturn
OpFunctionEnd
)";
CompileSuccessfully(spirv.c_str());
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
Expand Down
Loading