Bug 6380 - view_as / tag conversion causes logic bug in conditional expressions
view_as / tag conversion causes logic bug in conditional expressions
Status: RESOLVED FIXED
Product: SourceMod
Classification: Unclassified
Component: Compiler
master
All All
: P5 critical
Assigned To: SourceMod Bugs
:
: 6379 (view as bug list)
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2015-06-14 14:53 PDT by pheadxdll
Modified: 2015-11-04 08:04 PST (History)
2 users (show)

See Also:


Attachments
Test case (963 bytes, text/x-csrc)
2015-06-14 14:53 PDT, pheadxdll
no flags Details

Description pheadxdll 2015-06-14 14:53:39 PDT
Created attachment 3996 [details]
Test case

I've hit this bug a few times and finally nailed down the cause.

There's a breakdown in logic in conditional expressions related to tag conversions with view_as that causes the expression to always evaluate to true. Check out the attachment for a test case.

To ways to temporarily fix this:
if(view_as<int>(TFClass_Sniper) == class && true) // Put the tag conversion first.
if(class == (view_as<int>(TFClass_Sniper)) && true) // Put parenthesis around the tag conversion.

Using: SourcePawn Compiler 1.8.0-dev+5455.

Thanks for having a look.
Comment 1 AM Bugzilla Bot 2015-09-04 19:34:33 PDT
Commit pushed to 1.7-dev at https://github.com/alliedmodders/sourcemod

https://github.com/alliedmodders/sourcemod/commit/d8eaf2f302d25fa814ada8fa13a2e2050b2ccf17
Backport change: view_as<> should require parenthesis. (bug 6380)
Comment 2 David Anderson [:dvander] 2015-09-04 19:42:22 PDT
Sorry for not getting to this sooner. Surprisingly, this was inadvertently fixed recently on 1.8 in a change that required parenthesis in view_as<>. I have backported that fix to 1.7.

It took me a while to figure out why this change fixed anything. The reason is view_as<> has the wrong precedence. It was based off the precedence level for the label operator, which is 2, invoking "hier2". But view_as<> uses precedence level 12, meaning it would dive further and find the "&&" operator at preecedence level 11. Requiring parenthesis fixed this because the parser couldn't match any new operators once it encountered the ')'.

I'll fix this issue separately on both branches. Thank you for the report!
Comment 3 David Anderson [:dvander] 2015-09-04 21:09:05 PDT
*** Bug 6379 has been marked as a duplicate of this bug. ***
Comment 4 AM Bugzilla Bot 2015-09-05 17:51:25 PDT
Commit pushed to 1.7-dev at https://github.com/alliedmodders/sourcemod

https://github.com/alliedmodders/sourcemod/commit/fe6b63c17a6babc40a8781f82146ff0afd604356
Backport: Fix view_as<> precedence. (bug 6380)
Comment 5 AM Bugzilla Bot 2015-11-04 08:04:06 PST
Commits pushed to clang-3.8-warnings at https://github.com/alliedmodders/sourcemod

https://github.com/alliedmodders/sourcemod/commit/a1816830269acd38810e5cc306551b9c22ba9579
Fix view_as<> precedence. (bug 6380)

https://github.com/alliedmodders/sourcemod/commit/5d499fe4aac3fadec8579c36e5d81d82d4fce2a9
Merge pull request #33 from alliedmodders/fix-view-as-order

Fix view_as<> precedence. (bug 6380)

Note You need to log in before you can comment on or make changes to this bug.