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

Peephole optimizations incorrectly assume var = value will always set the var to that value #2188

Closed
wixoaGit opened this issue Jan 27, 2025 · 0 comments · Fixed by #2190
Closed
Labels
bug Something isn't working Compiler Involves the OpenDream compiler

Comments

@wixoaGit
Copy link
Member

wixoaGit commented Jan 27, 2025

Some built-in vars have special behavior that will coerce invalid values to valid ones. For example, /tg/ has this code:

dir = ndir
switch(dir)
    if(NORTH)
        offset_old = pixel_y
        pixel_y = APC_PIXEL_OFFSET
    if(SOUTH)
        offset_old = pixel_y
        pixel_y = -APC_PIXEL_OFFSET
    if(EAST)
        offset_old = pixel_x
        pixel_x = APC_PIXEL_OFFSET
    if(WEST)
        offset_old = pixel_x
        pixel_x = -APC_PIXEL_OFFSET

If ndir is null, this will end up setting dir to SOUTH. Our peephole optimizations incorrectly assume this will set dir to null and that we can use the value on the top of the stack instead of re-getting the dir value. This ends up doing switch(null) instead of switch(SOUTH).

@wixoaGit wixoaGit added bug Something isn't working Compiler Involves the OpenDream compiler labels Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Compiler Involves the OpenDream compiler
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant