diff options
| author | Ellie Hermaszewska <ellieh@nvidia.com> | 2023-08-29 20:58:44 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-08-29 20:58:44 +0800 |
| commit | f3ecf978a07b02681a4d70a9d83991e6661bf753 (patch) | |
| tree | 124c12ea8a1000caa9405871a21d44dbed83580c | |
| parent | 9d4e044bad6161a593806fc6fb610d41aa8b4b22 (diff) | |
Correct parsing spirv with no rhs operands (#3161)
* Correct parsing spirv with no rhs operands
* Guard against eof
| -rw-r--r-- | source/slang/slang-parser.cpp | 29 | ||||
| -rw-r--r-- | tests/language-feature/spirv-asm/typed-assignment-syntax.slang | 3 |
2 files changed, 23 insertions, 9 deletions
diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp index 57a21a90a..7e6d7d308 100644 --- a/source/slang/slang-parser.cpp +++ b/source/slang/slang-parser.cpp @@ -6411,8 +6411,27 @@ namespace Slang // At this point we can also parse bitwise or expressions // while(!(parser->LookAheadToken(TokenType::RBrace) - || parser->LookAheadToken(TokenType::Semicolon))) + || parser->LookAheadToken(TokenType::Semicolon) + || parser->LookAheadToken(TokenType::EndOfFile)) + || resultTypeOperand + || resultOperand) { + // Insert the LHS result-type operand + if(ret.operands.getCount() == opInfo->resultTypeIndex && resultTypeOperand) + { + ret.operands.add(*resultTypeOperand); + resultTypeOperand.reset(); + continue; + } + + // Insert the LHS result operand + if(ret.operands.getCount() == opInfo->resultIdIndex && resultOperand) + { + ret.operands.add(*resultOperand); + resultOperand.reset(); + continue; + } + if(ret.operands.getCount() == opInfo->maxOperandCount) { parser->diagnose( @@ -6423,14 +6442,6 @@ namespace Slang ); } - // Insert the LHS result-type operand - if(ret.operands.getCount() == opInfo->resultTypeIndex && resultTypeOperand) - ret.operands.add(*resultTypeOperand); - - // Insert the LHS result operand - if(ret.operands.getCount() == opInfo->resultIdIndex && resultOperand) - ret.operands.add(*resultOperand); - if(auto operand = parseSPIRVAsmOperand(parser)) { while(AdvanceIf(parser, TokenType::OpBitOr)) diff --git a/tests/language-feature/spirv-asm/typed-assignment-syntax.slang b/tests/language-feature/spirv-asm/typed-assignment-syntax.slang index 5e449686e..a20fb6e43 100644 --- a/tests/language-feature/spirv-asm/typed-assignment-syntax.slang +++ b/tests/language-feature/spirv-asm/typed-assignment-syntax.slang @@ -18,6 +18,9 @@ void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) int n = outputBuffer[i]; int r = spirv_asm { + // Check that this still works even with no operands on the RHS + %unused : $$uint = OpUndef; + // More normal usage %two : $$int = OpConstant 2; result : $$int = OpIMul $n %two; }; |
