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

fix C codegen regression with closures #1392

Merged

Conversation

zerbina
Copy link
Collaborator

@zerbina zerbina commented Jul 31, 2024

Summary

Fix explicit or implicit creation of a closure leading to C
compiler errors when using strict(er) C compilers.

Details

  • when lowering closure types, use a tkProc type with ccClosure
    calling convention
  • using a ccNimCall type with an additional void parameter meant
    that cgen placed the result type (in case of RVO) after the
    environment type, which is incorrect and doesn't match the signature
    of closure procedures
  • C compilers that require compatible types when implicitly casting
    rightfully reported an error in this case

Summary
-------

Fix explicit or implicit creation of a closure leading to the C
compiler errors when using strict(er) C compilers.

Details
-------

* when lowering the closure types, use a `tkProc` type with `ccClosure`
  calling convention
* using a `ccNimCall` type with an additional `void` parameter meant
  that `cgen` placed the result type (in case of RVO) *after* the
  environment type, which is incorrect and doesn't match the signature
  of closure procedures
* C compilers that require proper typing for pointer assignments
  rightfully reported an error in this case
@zerbina zerbina added bug Something isn't working compiler/backend Related to backend system of the compiler labels Jul 31, 2024
@zerbina zerbina added this to the MIR phase milestone Jul 31, 2024
@saem
Copy link
Collaborator

saem commented Jul 31, 2024

/merge

Copy link

Merge requested by: @saem

Contents after the first section break of the PR description has been removed and preserved below:


Notes for Reviewers

  • test coverage already exists (all closures are affected), but the used C compilers just aren't strict enough
  • I'll make a follow-up PR for using gcc-14 in CI, which is the easiest way of detecting these kinds of code generation issues

@chore-runner chore-runner bot enabled auto-merge July 31, 2024 00:29
@chore-runner chore-runner bot added this pull request to the merge queue Jul 31, 2024
Merged via the queue into nim-works:devel with commit 4fed1a6 Jul 31, 2024
31 checks passed
@zerbina zerbina deleted the fix-closure-codegen-regression branch August 13, 2024 21:03
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/backend Related to backend system of the compiler
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants