Skip to content

Conversation

@jgarzik
Copy link
Contributor

@jgarzik jgarzik commented Dec 29, 2025

Codegen fixes for char/short values on stack:

  • x86_64: Use movzx for loading sub-32-bit values from stack/incoming args to avoid garbage in upper register bits. Store with AND mask to zero-extend.
  • aarch64: Use correct sized load (ldrb/ldrh) which auto zero-extends, instead of forcing 32-bit loads that read adjacent garbage bytes.

IR linearization fix for incomplete struct types:

  • Add resolve_struct_type() call in linearize_init_list_at_offset() to handle forward-declared struct typedefs in local variable initialization (the fix was already in convert_initializer for globals, but missing for locals).

Add regression tests:

  • Unit test for incomplete struct type resolution via typedef
  • Integration tests for char/short stack spill/reload scenarios

🤖 Generated with Claude Code

Codegen fixes for char/short values on stack:
- x86_64: Use movzx for loading sub-32-bit values from stack/incoming args
  to avoid garbage in upper register bits. Store with AND mask to zero-extend.
- aarch64: Use correct sized load (ldrb/ldrh) which auto zero-extends,
  instead of forcing 32-bit loads that read adjacent garbage bytes.

IR linearization fix for incomplete struct types:
- Add resolve_struct_type() call in linearize_init_list_at_offset() to
  handle forward-declared struct typedefs in local variable initialization
  (the fix was already in convert_initializer for globals, but missing for
  locals).

Add regression tests:
- Unit test for incomplete struct type resolution via typedef
- Integration tests for char/short stack spill/reload scenarios

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@jgarzik jgarzik requested a review from Copilot December 29, 2025 14:56
@jgarzik jgarzik self-assigned this Dec 29, 2025
@jgarzik jgarzik added the bug Something isn't working label Dec 29, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes two distinct codegen and IR linearization bugs related to sub-32-bit types and incomplete struct resolution:

  • Codegen fixes: Corrects stack handling for char and short types to prevent garbage in upper register bits during load/reload operations
  • IR linearization fix: Adds struct type resolution to handle forward-declared struct typedefs in local variable initialization
  • Comprehensive tests: Adds regression tests covering both the codegen fixes and the incomplete struct resolution

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
cc/tests/datatypes/short.rs Adds regression test short_stack_spill_reload to verify short values passed through stack preserve correct values without garbage bits
cc/tests/datatypes/char.rs Adds regression test char_stack_spill_reload to verify char values passed through stack preserve correct values without garbage bits
cc/ir/test_linearize.rs Adds unit test test_incomplete_struct_type_resolution to verify incomplete struct types are resolved to complete definitions during linearization
cc/ir/linearize.rs Adds resolve_struct_type() calls in two locations to handle forward-declared struct typedefs in both ast_init_list_to_ir and linearize_init_list_at_offset
cc/arch/x86_64/codegen.rs Implements movzx instruction for zero-extending sub-32-bit loads from stack/incoming args; implements zero-extend via AND mask for sub-32-bit stores
cc/arch/aarch64/codegen.rs Uses appropriately sized load instructions (ldrb/ldrh) for sub-32-bit stack values, which auto zero-extend

@jgarzik jgarzik merged commit 02a2dd4 into main Dec 29, 2025
10 checks passed
@jgarzik jgarzik deleted the updates branch December 29, 2025 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants