Skip to content

CC fixes#560

Merged
jgarzik merged 7 commits intomainfrom
updates
Feb 9, 2026
Merged

CC fixes#560
jgarzik merged 7 commits intomainfrom
updates

Conversation

@jgarzik
Copy link
Contributor

@jgarzik jgarzik commented Feb 9, 2026

No description provided.

jgarzik and others added 6 commits February 8, 2026 13:44
Serialize tests that modify COLUMNS/LINES env vars with a mutex,
preventing race conditions when tests run in parallel.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
linearize_init_list_at_offset() used the element enumeration index for
positional field lookup instead of a counter that advances past
designated fields. This caused {.b = 20, 30, 40} to store 30 at field
b's offset instead of field c's. Apply the same current_field_idx
pattern already used in the global init handler (ast_init_list_to_ir).

Fix applies to both struct and array branches of the local init handler.

Add unit tests for both struct and array mixed designated+positional
init, plus a comprehensive 8-section integration torture test covering
function pointers, self-referencing structs, anonymous members, large
structs, nested structs, compound literals, and more.

Move cc-specific testing rules from root CLAUDE.md to cc/CLAUDE.md.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…thon compatibility improvements

va_list fixes:
- Add is_indirect flag to LocalVarInfo for va_list parameters
- va_list params store pointer (8 bytes) not struct (24 bytes) due to array decay
- linearize_lvalue loads pointer for indirect locals
- linearize_ident handles va_list expression decay for indirect params
- Fix emit_va_copy temp register collision when dst_reg is RAX

Return type conversion:
- Fix return statements to convert expression type to function return type
- Ensures 'return -1' in long long function sign-extends correctly

Other fixes:
- Separate PIE mode from shared library mode for TLS model selection
- Fix atomic CAS register clobbering via red zone spilling
- Fix large struct member access to return address instead of loading
- Add symbol table mutability for array size inference from initializers
- Disable SSE intrinsics headers (not yet supported)

Tests:
- Add unit tests for va_list parameter handling
- Add e2e tests for return type conversion, va_list cast
- Add PIE/PIC codegen tests
- All 62 tests pass
x86_64:
- Fix incorrect operand size (B32 vs actual arg size) when storing
  va_arg results to stack locations - caused 64-bit pointers to be
  truncated
- Fix missing stack offset adjustment (callee_saved_offset and negation)
  when storing to stack - caused stores to wrong locations

aarch64:
- Fix hardcoded B64 size in va_arg stack store to use actual op_size

These bugs were exposed by CPython's Py_BuildValue("(ssss)", ...) which
passes string pointers through a va_list to helper functions, causing
register pressure and stack spills.

Add e2e test for va_arg with string pointers passed through va_list*.
@jgarzik jgarzik requested a review from Copilot February 9, 2026 20:14
@jgarzik jgarzik self-assigned this Feb 9, 2026
@jgarzik jgarzik added the bug Something isn't working label Feb 9, 2026
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 updates the cc (pcc) compiler and its test suite to improve GCC/CPython compatibility and fix several correctness issues across parsing, IR linearization, and x86_64 codegen.

Changes:

  • Add/extend GCC-compat CLI flag handling (PIE/-no-pie, linker flag passthrough, reject unsupported -m*) and corresponding integration/unit tests.
  • Fix/extend initializer handling (incomplete array size inference with designators; better designated/positional init handling; bitfield init packing; compound literal zero-init) and add regression tests.
  • Improve codegen/ABI correctness (return type conversion, va_list parameter decay handling, large-aggregate copies, atomic CAS reg-clobber fix, TLS model selection refinements).

Reviewed changes

Copilot reviewed 28 out of 28 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
editors/vi/ui/terminal.rs Serialize env-var-mutating tests with a global lock.
cc/token/preprocess.rs Centralize __has_attribute supported-attribute list.
cc/main.rs Add PIE/linker passthrough/unsupported -m* flag handling and tests; adjust codegen creation args.
cc/arch/codegen.rs Extend codegen factory/trait with shared-mode flag.
cc/arch/x86_64/codegen.rs Refine GOT/TLS behavior; fix atomic CAS operand clobbering; add shared-mode support.
cc/arch/x86_64/features.rs Fix stack offset handling and temp-reg usage in varargs/TLS helpers.
cc/arch/x86_64/float.rs Fix stack offset handling for FP moves.
cc/arch/aarch64/features.rs Fix store size selection.
cc/arch/aarch64/codegen.rs Implement set_shared_mode as a no-op placeholder.
cc/parse/parser.rs Infer incomplete array sizes using max designator index; update bound symbol types post-inference.
cc/parse/expression.rs Use shared array-size inference for compound literals with incomplete array types.
cc/symbol.rs Add SymbolTable::get_mut for updating bound symbol entries.
cc/ir/linearize.rs Major initializer/codegen correctness work: designator chains, bitfields, va_list decay, large-aggregate copies, return conversions, purity rules.
cc/parse/test_parser.rs Add unit tests for array-size inference with designator initializers.
cc/ir/test_linearize.rs Add extensive regression tests for init/designators/bitfields/va_list/large copies/conditional short-circuiting.
cc/tests/* Add CPython-focused and multiple new codegen/C99/C89/builtin integration tests.
cc/include/xmmintrin.h / emmintrin.h Hard-error out on unsupported SSE/SSE2 intrinsics.
cc/CLAUDE.md Add cc-specific testing rules doc.
CLAUDE.md Remove duplicated cc-specific test checklist items from root doc.

Gate RIP-relative addressing test to x86_64 only, and replace system
header includes with minimal forward declarations in compound literal
test to avoid platform-specific header parse failures.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jgarzik jgarzik merged commit 31618a0 into main Feb 9, 2026
6 checks passed
@jgarzik jgarzik deleted the updates branch February 9, 2026 21:57
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.

1 participant