Skip to content

Fix function pointer assignment - #328

Open
ChAoSUnItY wants to merge 1 commit into
sysprog21:masterfrom
ChAoSUnItY:fix/fp-assign
Open

Fix function pointer assignment#328
ChAoSUnItY wants to merge 1 commit into
sysprog21:masterfrom
ChAoSUnItY:fix/fp-assign

Conversation

@ChAoSUnItY

@ChAoSUnItY ChAoSUnItY commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

This patch fixes function pointer assignment on local variable, direct struct member, and pointer-to-struct member, and also fixes in-register arguments not cleared after invocation of function pointer.


Summary by cubic

Fixes incorrect function-pointer assignment and cleans up register liveness after indirect calls to prevent wrong-address reads/writes and spill corruption. Previously locals and struct members could target the wrong address and call-argument registers stayed live after function-pointer calls; now locals invoke the pointer directly, member stores target the base address, and registers are cleared post-call.

Bug Fixes

  • Skip the load when calling a non-reference local function pointer.
  • Store function pointers to struct or pointer-to-struct members by taking the base address before the write.
  • Target OP_address_of at aggregate backing storage, not the spill slot, and allocate backing storage for parameter and nested aggregates with function-pointer fields.
  • Clear live variable mappings for all registers after indirect calls.
  • Add tests for locals, struct and pointer-to-struct members, parameter and nested aggregates, and stale argument-register cleanup.

Written for commit 0e76361. Summary will update on new commits.

Review in cubic

@jserv
jserv requested a review from DrXiao August 25, 2026 06:52
cubic-dev-ai[bot]

This comment was marked as resolved.

This patch fixes function pointer assignment on local variable, direct
struct member, and pointer-to-struct member, and also fixes in-register
arguments not cleared after invocation of function pointer.
Comment thread src/parser.c
opstack_push(vd);
add_insn(parent, *bb, OP_read, vd, rs1, NULL, PTR_SIZE, NULL);

if (lvalue.is_reference) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

How about adding some comments?

Comment thread src/parser.c
rs2 = opstack_pop();
rs1 = opstack_pop();

if (!lvalue.is_reference) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ditto.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants