Return overwrite #2

Closed
opened 2020-09-11 02:19:59 +00:00 by TheCurle · 1 comment
Owner

Consider the following ASM snippet generated by build 10:

movq	$10, %r8
movq	%r8, %rcx
call	OtherFunctionThatReturns40
movq	%rax, %r9 <--
movq	$10, %r9 <--
addq	%r9, %r9 <--
movq	%r9, %rcx 
call	PrintInteger

See the three highlighted lines.
As it currently stands, the register used to output a variable is deallocated as soon as it is populated, allowing the compiler to use the register immediately upon the next assignment.
This leads to things like Print(Function() + 10) behaving like Print(10 + 10).

This could be fixed by just not deallocating the register after it's used, but there would need to be other systems in place to garbage check the register.

Consider the following ASM snippet generated by build 10: movq $10, %r8 movq %r8, %rcx call OtherFunctionThatReturns40 movq %rax, %r9 <-- movq $10, %r9 <-- addq %r9, %r9 <-- movq %r9, %rcx call PrintInteger See the three highlighted lines. As it currently stands, the register used to output a variable is deallocated as soon as it is populated, allowing the compiler to use the register immediately upon the next assignment. This leads to things like `Print(Function() + 10)` behaving like `Print(10 + 10)`. This could be fixed by just not deallocating the register after it's used, but there would need to be other systems in place to garbage check the register.
TheCurle added the
bug
invalid
labels 2020-09-11 02:26:21 +00:00
Author
Owner

I'm actually embarrassed about this one. After spending a day or two working on other things, i realised that i was actually trying to deallocate the register used to input the value. Instead i was deallocating the one used to output, hence... stupid bug.

Onto bigger fish!

I'm actually embarrassed about this one. After spending a day or two working on other things, i realised that i was actually trying to deallocate the register used to *input* the value. Instead i was deallocating the one used to *output*, hence... stupid bug. Onto bigger fish!
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: TheCurle/Erythro#2
No description provided.