Skip to content

Fix @[Primitive] codegen for typedefs#16110

Merged
straight-shoota merged 4 commits intocrystal-lang:masterfrom
HertzDevil:bug/codegen-typedef-primitives
Aug 29, 2025
Merged

Fix @[Primitive] codegen for typedefs#16110
straight-shoota merged 4 commits intocrystal-lang:masterfrom
HertzDevil:bug/codegen-typedef-primitives

Conversation

@HertzDevil
Copy link
Contributor

@HertzDevil HertzDevil commented Aug 24, 2025

Fixes #16097.

These include typedef receivers in Pointer#+, Pointer#-, Pointer#realloc, Proc#call, and all lib struct or union setters, as well as typedef arguments in all @[Primitive(:binary)] methods (e.g. #&+ and #==).

This does not affect the interpreter (see #14151).

@HertzDevil HertzDevil added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:codegen labels Aug 24, 2025
@straight-shoota straight-shoota added this to the 1.18.0 milestone Aug 24, 2025
@ysbaddaden
Copy link
Collaborator

CI is completely broken?

@straight-shoota straight-shoota removed this from the 1.18.0 milestone Aug 26, 2025
@HertzDevil
Copy link
Contributor Author

Apparently returning a typedef of a Proc type from a lib fun makes Crystal think that it has two pointers instead of one, so codegen itself is broken here

Comment on lines +221 to +232
it "can invoke pointer primitives on typedef" do
codegen(<<-CRYSTAL)
lib Test
type K = Void*
fun foo : K
end

Test.foo + 1
Test.foo - Test.foo
Test.foo.realloc(1)
CRYSTAL
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: On Crystal 1.0 this spec fails: https://github.com/crystal-lang/crystal/actions/runs/17244868139/job/48931777770?pr=16110

Module validation failed: Function return type does not match operand type of return inst!
           ret void* %10
          i8* (Exception)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's most certainly a pre-LLVM 15 issue with non-opaque pointers, we should have enabled LLVM CI for compiler source code dealing with codegen

@straight-shoota straight-shoota added this to the 1.18.0 milestone Aug 27, 2025
@straight-shoota straight-shoota merged commit 1a74cbe into crystal-lang:master Aug 29, 2025
39 checks passed
@HertzDevil HertzDevil deleted the bug/codegen-typedef-primitives branch August 29, 2025 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:codegen

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: codegen_binary_op called with UInt64 == LibX11::KeySym

3 participants