Incorrect behavior when trying to bit-cast to and from pointers #47

Open
opened 2024-02-27 05:20:15 +00:00 by sashakoshka · 4 comments
Owner

Source A:

[main argc:I32 argv:**Byte]: I32 'main' = {
	argvindex:Index = [+ [~~Index argv] 1]
	argv = [~~ **Byte argvindex]
	0
}

Behavior A:

llc-16: error: llc-16: <stdin>:11:15: error: invalid cast opcode for cast from 'ptr' to 'i64'
        %5 = bitcast ptr %4 to %"AAAAAAAAAAAAAAAAAAAAAA==::Index"

Source B:

[main argc:I32 argv:**Byte]: I32 'main' = {
	argv = [~~ **Byte [+ [~~Index argv] 1]]
	cstdio::[puts [.argv]]
	0
}

Behavior B:

    common_test.go:86: compiler returned error: /test-data/data/argv/main.fspl:2:20: expected **Byte
        2    |         argv = [~~ **Byte [+ [~~Index argv] 1]]
                                         ^^^^^^^^^^^^^^^^^^^^

The generator should never produce invalid IR (given a well formed AST), and the analyzer should be more consistent. The operation in question (bit casting a pointer to an integer and back) is necessary for working with C code and should be allowed and supported.

Source A: ``` [main argc:I32 argv:**Byte]: I32 'main' = { argvindex:Index = [+ [~~Index argv] 1] argv = [~~ **Byte argvindex] 0 } ``` Behavior A: ``` llc-16: error: llc-16: <stdin>:11:15: error: invalid cast opcode for cast from 'ptr' to 'i64' %5 = bitcast ptr %4 to %"AAAAAAAAAAAAAAAAAAAAAA==::Index" ``` Source B: ``` [main argc:I32 argv:**Byte]: I32 'main' = { argv = [~~ **Byte [+ [~~Index argv] 1]] cstdio::[puts [.argv]] 0 } ``` Behavior B: ``` common_test.go:86: compiler returned error: /test-data/data/argv/main.fspl:2:20: expected **Byte 2 | argv = [~~ **Byte [+ [~~Index argv] 1]] ^^^^^^^^^^^^^^^^^^^^ ``` The generator should never produce invalid IR (given a well formed AST), and the analyzer should be more consistent. The operation in question (bit casting a pointer to an integer and back) is necessary for working with C code and should be allowed and supported.
sashakoshka added the
bug
package: analyzer
package: generator
labels 2024-02-27 05:20:15 +00:00
Author
Owner

Need to uncomment 60c49a1d9a/compiler/compiler_test.go (L43) when this has been resolved

Need to uncomment https://git.tebibyte.media/fspl/fspl/src/commit/60c49a1d9a7093cfe5ec58b2934b2abb0157b302/compiler/compiler_test.go#L43 when this has been resolved
sashakoshka added the
status
ongoing
label 2024-02-28 16:07:21 +00:00
Author
Owner

35479e68a8 partially fixes the generator side of this. These symptoms revealed more possible buggy behavior, see comments in the commit. Need more tests for these cases and to fix them.

https://git.tebibyte.media/fspl/fspl/commit/35479e68a8e14f54a1c3651c05542c4e12437cc6 partially fixes the generator side of this. These symptoms revealed more possible buggy behavior, see comments in the commit. Need more tests for these cases and to fix them.
sashakoshka changed title from Bizarre behavior when trying to cast pointer to Index to Incorrect behavior when trying to cast to and from pointers 2024-02-28 18:53:04 +00:00
sashakoshka changed title from Incorrect behavior when trying to cast to and from pointers to Incorrect behavior when trying to bit-cast to and from pointers 2024-02-28 18:53:17 +00:00
Author
Owner

The analyzer side of this issue has been completely remedied by #50

The analyzer side of this issue has been completely remedied by #50
sashakoshka removed the
package: analyzer
label 2024-02-29 00:35:14 +00:00
Author
Owner

Putting this on the backburner for now as fully fixing this in the generator is non-trivial, and use cases for bit casting crazy stuff like structs to pointers are a bit slim

Putting this on the backburner for now as *fully* fixing this in the generator is non-trivial, and use cases for bit casting crazy stuff like structs to pointers are a bit slim
sashakoshka added
status
backburner
and removed
status
ongoing
labels 2024-02-29 01:10:49 +00:00
Sign in to join this conversation.
No Milestone
No project
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: fspl/fspl#47
No description provided.