diff options
| -rw-r--r-- | source/slang/parser.cpp | 36 | ||||
| -rw-r--r-- | tests/diagnostics/missing-semicolon-after-semantic.slang | 9 | ||||
| -rw-r--r-- | tests/diagnostics/missing-semicolon-after-semantic.slang.expected | 6 | ||||
| -rw-r--r-- | tests/front-end/uav-write.slang | 20 |
4 files changed, 59 insertions, 12 deletions
diff --git a/source/slang/parser.cpp b/source/slang/parser.cpp index 037268244..82f79af17 100644 --- a/source/slang/parser.cpp +++ b/source/slang/parser.cpp @@ -1863,12 +1863,18 @@ namespace Slang ParseHLSLLayoutSemantic(parser, semantic.Ptr()); return semantic; } - else + else if (parser->LookAheadToken(TokenType::Identifier)) { RefPtr<HLSLSimpleSemantic> semantic = new HLSLSimpleSemantic(); semantic->name = parser->ReadToken(TokenType::Identifier); return semantic; } + else + { + // expect an identifier, just to produce an error message + parser->ReadToken(TokenType::Identifier); + return nullptr; + } } // @@ -1893,20 +1899,26 @@ namespace Slang link = &semantic->next; } - switch (parser->tokenReader.PeekTokenType()) + // If we see another `:`, then that means there + // is yet another semantic to be processed. + // Otherwise we assume we are at the end of the list. + // + // TODO: This could produce sub-optimal diagnostics + // when the user *meant* to apply multiple semantics + // to a single declaration: + // + // Foo foo : register(t0) register(s0); + // ^ + // missing ':' here | + // + // However, that is an uncommon occurence, and trying + // to continue parsing semantics here even if we didn't + // see a colon forces us to be careful about + // avoiding an infinite loop here. + if (!AdvanceIf(parser, TokenType::Colon)) { - case TokenType::LBrace: - case TokenType::Semicolon: - case TokenType::Comma: - case TokenType::RParent: - case TokenType::EndOfFile: return result; - - default: - break; } - - parser->ReadToken(TokenType::Colon); } } diff --git a/tests/diagnostics/missing-semicolon-after-semantic.slang b/tests/diagnostics/missing-semicolon-after-semantic.slang new file mode 100644 index 000000000..00fc3aa6c --- /dev/null +++ b/tests/diagnostics/missing-semicolon-after-semantic.slang @@ -0,0 +1,9 @@ +//TEST:SIMPLE: + +// Forgetting to put in the `;` after declaraing a variable/field +// with a semantic used to put the compiler into an infinite loop. + +struct Test +{ + float4 pos : SV_POSITION +}; diff --git a/tests/diagnostics/missing-semicolon-after-semantic.slang.expected b/tests/diagnostics/missing-semicolon-after-semantic.slang.expected new file mode 100644 index 000000000..ae82385d0 --- /dev/null +++ b/tests/diagnostics/missing-semicolon-after-semantic.slang.expected @@ -0,0 +1,6 @@ +result code = -1 +standard error = { +tests/diagnostics/missing-semicolon-after-semantic.slang(9): error 20001: unexpected '}', expected ';' +} +standard output = { +} diff --git a/tests/front-end/uav-write.slang b/tests/front-end/uav-write.slang new file mode 100644 index 000000000..c70af26a3 --- /dev/null +++ b/tests/front-end/uav-write.slang @@ -0,0 +1,20 @@ +// uav-write.slang +//TEST:SIMPLE: + +// Just confirming that code that writes to a UAV will type-check. + +RWTexture2D<float4> gOutput; + +float4 test(uint2 coord, float4 value) +{ + // read + value = value + gOutput[coord]; + + // write + gOutput[coord] = value; + + // read-modify-write + gOutput[coord] += value; + + return value; +}
\ No newline at end of file |
