diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2017-10-09 10:16:12 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-10-09 10:16:12 -0700 |
| commit | fe5eef423389b82e7eb2586fb7a16b96afd004f2 (patch) | |
| tree | 83b20983dc33dfaa664c7b8875ea93d2976a31a9 | |
| parent | faf26afdcfd343c79517f56f215bf8dcd5e0b992 (diff) | |
Parser: fix precedence of cast expressions (#203)
We were accidentally parsing this:
(uint) a / b
as this:
(uint) ( a / b )
when it should be:
((uint) a) / b
This is a bug that seems to have been inherited from a long time ago. It has taken a while to bite anybody because the only class of expressions it would hit are multiplicative ones, and in many cases the difference in the cast order won't be noticed for values in a limited range.
| -rw-r--r-- | source/slang/parser.cpp | 4 | ||||
| -rw-r--r-- | tests/parser/cast-precedence.hlsl | 15 |
2 files changed, 18 insertions, 1 deletions
diff --git a/source/slang/parser.cpp b/source/slang/parser.cpp index 38d9c744d..a0e07ea12 100644 --- a/source/slang/parser.cpp +++ b/source/slang/parser.cpp @@ -3321,6 +3321,8 @@ namespace Slang return parseGenericApp(parser, base); } + static RefPtr<Expr> parsePrefixExpr(Parser* parser); + static RefPtr<Expr> parseAtomicExpr(Parser* parser) { switch( peekTokenType(parser) ) @@ -3348,7 +3350,7 @@ namespace Slang tcexpr->FunctionExpr = parser->ParseType(); parser->ReadToken(TokenType::RParent); - auto arg = parser->ParseExpression(Precedence::Multiplicative); // Note(tfoley): need to double-check this + auto arg = parsePrefixExpr(parser); tcexpr->Arguments.Add(arg); return tcexpr; diff --git a/tests/parser/cast-precedence.hlsl b/tests/parser/cast-precedence.hlsl new file mode 100644 index 000000000..d5d0b0322 --- /dev/null +++ b/tests/parser/cast-precedence.hlsl @@ -0,0 +1,15 @@ +//TEST:COMPARE_HLSL: -profile vs_5_0 + +// Confirm that type-cast expressions parse with +// the appropriate precedence. + +cbuffer C : register(b0) +{ + float a; + float b; +}; + +float4 main() : SV_Position +{ + return (uint) a / b; +} |
