fix(cgen): fix address-of and as_cast pointer codegen#27481
Conversation
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6045f791fb
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Addressed the latest review feedback in 528f9ed:
Validation:
|
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 528f9edd0b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
|
Codex Review: Didn't find any major issues. You're on a roll. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@medvednikov / @JalonSolov From my perspective, this PR is ready to merge. Thanks! |
Summary
This PR fixes a C code generation issue where combining the address-of (
&) operator andas_castexpressions (specifically during smartcasts) results in incorrect pointer casting and dereferencing syntax in the generated C output.Details of Changes
In
vlib/v/gen/c/cgen.v:Gen.expr:&) operator codegen path. When the right-hand side is anAsCastexpression, we check if it evaluates to a pointer casting using the newas_cast_will_use_ptr()helper. If so, we avoid writing incorrect prefix operators (like double address-of or invalid dereference syntax).Gen.write_as_cast_call_start:g.is_amp(address-of context) to ensure the compiler generates(Type*)pointer casts rather than standard value casts when smartcasting is performed in an address-of context.Gen.as_cast_will_use_ptr:AsCastnode will result in a pointer-based representation under the hood (e.g. casting interfaces or sum types with differing base types).Checklist
v fmt -w.Tests Run
Rebuilt the V compiler and verified that all compiler and cgen tests pass:
./v -g -keepc -o ./vnew cmd/v ./vnew -silent test vlib/v/gen/c/All tests passed successfully on local machine.