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: wrong code generation for synthesized object hooks #1338

Merged

Conversation

zerbina
Copy link
Collaborator

@zerbina zerbina commented Jun 7, 2024

Summary

Fix a bug with synthesis of lifetime-tracking hooks for object types
using inheritance, which showed up as a C compiler error when using
recent versions of clang or gcc.

Fixes #1337.

Details

When synthesizing the hooks for object types using inheritance, the
destination accessor expression wasn't wrapped in an object conversion
prior to emitting the parent object handling.

Without the conversion, the synthesized hook passed along its own
parameter to the call of the super type's hook as-is. This is wrong
in general (the argument's type doesn't match the parameter's), but
didn't cause concrete issues until gcc and clang started to disallow
implicit conversions between incompatible pointer types.

Summary
=======

Fix a bug with synthesis of lifetime-tracking hooks for object types
using inheritance, which showed up as a C compiler error when using
recent versions of clang or gcc.

Details
=======

When synthesizing the hooks for object types using inheritance, the
destination accessor expression wasn't wrapped in an object conversion
prior to emitting the super type handling.

Without the conversion, the synthesized hook passed its own parameter
directly to the call of the super type's hook. This is wrong in general
(because the argument's type doesn't match the parameter's), but didn't
cause concrete issues until gcc and clang started to disallow implicit
conversions between incompatible pointer types.
@zerbina zerbina added bug Something isn't working compiler/sem Related to semantic-analysis system of the compiler labels Jun 7, 2024
@zerbina zerbina force-pushed the fix-hook-synthesis-for-objects branch from 4edd5d3 to a38e5ff Compare June 7, 2024 17:55
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm thinking that we should either add a {.passC.} or a config file to turn on -Werror=incompatible-pointer-types for this test

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The config file approach is already used by another test, but it's brittle and I'd rather not embrace it further.

I'll make a separate PR that adds debug functionality for pretty-printing the initial MIR, and then this test can make sure the MIR for the destroy hook is sensible.

@saem
Copy link
Collaborator

saem commented Jun 8, 2024

/merge

Copy link

github-actions bot commented Jun 8, 2024

Merge requested by: @saem

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


@chore-runner chore-runner bot added this pull request to the merge queue Jun 8, 2024
Merged via the queue into nim-works:devel with commit ab50b74 Jun 8, 2024
31 checks passed
@zerbina zerbina deleted the fix-hook-synthesis-for-objects branch June 9, 2024 19:08
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/sem Related to semantic-analysis system of the compiler
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The pointer passed to super type hook is not converted to the super type
3 participants