Conversation
Add switch-aware recursion into nested loops/blocks/if in the linearizer so case labels inside loops work (Duff's device pattern). Fix collect_cases_from_stmt to find case/default labels in nested statements, and linearize_switch_stmt to propagate switch context through do-while/while/for/block/if bodies. Add two new integration tests: statement edge cases (null stmts, empty blocks, dangling else, omitted for clauses, void return, expression stmts) and classic Duff's device memory copy. Check off all 27 Section 6 items in c99-checklist.md (100%). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add c89_lexical_elements_mega covering comments, integer constants (decimal/octal/hex with all suffix combos), floating constants (decimal/hex with e/E/p/P exponents and f/F/l/L suffixes), character constants (all 11 escape sequences, octal, hex, wide L'x'), string literals (concatenation, escapes, null termination), identifiers (case sensitivity, 63+ char names), and punctuators. Check off 49/50 Section 9 items (100%). Mark trigraphs as N/A (will not implement: deprecated in C99, removed in C11). Add "Will not implement" section to README listing _Imaginary and trigraphs with rationale. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add c89_operators_comprehensive_mega covering all compound assignment operators (-=, /=, %=, &=, |=, ^=, <<=, >>=), bitwise NOT (~), comma operator, all 15 precedence levels with targeted binding tests, and associativity (right-to-left for =/?:/compound-assign, left-to-right for -/÷/>>/<). Check off all 63 Section 4 items in c99-checklist.md (100%). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add c99_expressions_mega covering casts (pointer↔integer round-trip, between pointer types, void, widening/narrowing), constant expressions (address constants, compile-time eval, sizeof in array size), implicit conversions (integer promotions, usual arithmetic, default argument promotions, array/function-to-pointer decay, lvalue conversion), and compound literals. Check off all 34 Section 5 items (100%). Remove 3 C11 items that don't belong in a C99 checklist: _Generic, _Thread_local mention, static_assert-declaration. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add K&R (old-style) function definition parsing: after closing ')' of parameter list, if next token is a type keyword, parse parameter type declarations and update param types before function body. Follows sparse's approach. Add c89_declarations_mega covering K&R functions, struct forward declaration, self-referential structs, flexible array members, zero-width bit-fields, pointer-to-array, extern incomplete array, function returning function pointer, all typedef variants including redeclaration, all initializer patterns (designated, mixed, out-of-order, compound literals). Check off all 55 Section 7 items in c99-checklist.md (100%). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add c99_types_keywords_mega covering all type specifier synonyms (signed short int, etc.), _Bool/stdbool.h, storage class specifiers, type qualifiers with combinations (const volatile, restrict), function specifiers (inline variants), derived types, enums with negatives, and type compatibility. Check off: Section 1 (35+1 N/A, 97%), Section 2 (37+4 N/A, 91%), Section 3 (15/15, 100%). Mark _Imaginary variants as N/A (will not implement). Complex arithmetic/library items left unchecked pending complex.h end-to-end support. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…lex codegen Fix hex float suffix: strip f/l suffixes from hex float literals before parsing (0x1.0p5f now works correctly). Add __builtin_complex(real, imag) builtin to construct complex values. Add builtin complex.h header with complex/I macros and function decls. Fix three complex number codegen bugs: - Real scalar init to complex variable (double _Complex z = 3.0) was treating the scalar value as a memory address - Mixed real+complex binary ops (3.0 + complex_val) crashed because emit_complex_binary expected both operands to be complex addresses - Add promote_real_to_complex helper for the binary op fix Add c99_complex_mega test covering I macro, complex arithmetic (+,-,*,/), mixed real+complex ops, creal/cimag extraction. Add hex float suffix tests to c99_features_gaps_mega. Check off remaining Section 10 and Section 2 complex items. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add c99_stdlib_headers_mega proving all 24 C89/C99 standard library headers compile and key functions work: ctype.h, errno.h, math.h (C99 additions), stdio.h (snprintf, %lld, %zu), stdlib.h (strtoll, llabs, atoll), stdint.h types/limits, inttypes.h PRId32/PRIx64, fenv.h fegetround, wchar.h, wctype.h, iso646.h alternative spellings. Test all predefined macros: __DATE__, __TIME__, __FILE__, __LINE__, __STDC__, __STDC_VERSION__, __STDC_HOSTED__, __func__. Add builtin iso646.h header (alternative operator spellings). Check off: Section 11 (120/120, 100%), Section 12 (11/11, 100%), Section 13 (25/25, 100%). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…t complete Add c99_translation_limits_mega proving compiler meets C99 minimum translation limits: 63+ char identifiers, 130 struct members, 130 enum constants, 20 function params, 15-level block nesting, 30 case labels, 15-level parenthesized expressions. Check off Section 14 (22/22, 100%), Appendix A grammar (5/5), Appendix B ABI (7/7), Appendix C testing (11/13). Final checklist: 622 checked + 8 N/A + 2 unchecked = 99.7% complete. Only unchecked: GCC torture tests and clang test suite (external). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Remove completed sections: C11 alignment specifiers (all phases), C11 atomics phases 1-7, _Static_assert, anonymous structs/unions, stdalign.h, Pass 6 inlining. Condense remaining items: R10 tech debt, _Generic, atomics phase 8, TLS ARM64/dynamic models, optimization passes 1-5/7-8, assembly peephole. 558→100 lines. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR completes several C99 conformance “finishing touches” in the cc (pcc) compiler crate, primarily around complex numbers, K&R-style function definitions, and switch/case handling edge cases, and adds broad integration test coverage to validate the implemented features.
Changes:
- Add
__builtin_complexparsing/AST/IR support and wire up builtin<complex.h>and<iso646.h>headers. - Extend parsing and IR linearization to handle K&R parameter declarations and Duff’s-device-style
caselabels inside nested statements. - Add multiple “mega-tests” for C89/C99 lexical elements, declarations, expressions, types/keywords, translation limits, stdlib headers, complex arithmetic, and operator precedence/associativity.
Reviewed changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
cc/types.rs |
Adds TypeTable::make_complex helper to map base float types to their complex equivalents. |
cc/parse/parser.rs |
Implements K&R (old-style) parameter declaration parsing between ) and {. |
cc/parse/expression.rs |
Adds parsing for __builtin_complex(real, imag). |
cc/parse/ast.rs |
Introduces ExprKind::BuiltinComplex AST node. |
cc/kw.rs |
Adds __builtin_complex keyword entry. |
cc/ir/linearize_emit.rs |
Adds helper to promote real scalars to complex temps for mixed complex arithmetic. |
cc/ir/linearize.rs |
Adds IR emission for BuiltinComplex and supports real↔complex promotion in complex binary ops. |
cc/ir/linearize_stmt.rs |
Improves complex initialization handling and extends switch-case collection/linearization for Duff’s device patterns. |
cc/builtin_headers.rs |
Registers builtin header text for complex.h and iso646.h. |
cc/include/complex.h |
Adds builtin <complex.h> header content (macro + prototypes). |
cc/include/iso646.h |
Adds builtin <iso646.h> header content (operator-spelling macros). |
cc/tests/c99/*.rs, cc/tests/c89/*.rs, cc/tests/*/mod.rs |
Adds/extends large integration tests exercising the new and existing C89/C99 features. |
cc/doc/c99-checklist.md |
Updates checklist status to reflect completion of many C99 items and adds N/A rationale. |
cc/doc/TODO.md |
Refactors/condenses TODO content (esp. C11 sections and optimization pipeline notes). |
cc/README.md |
Documents explicitly “will not implement” items (_Imaginary, trigraphs). |
Exhaustive checklist of 259 items covering all C11 additions, changes, and removals relative to C99. Covers new keywords, _Generic, _Static_assert, anonymous structs/unions, alignment, _Noreturn, atomics, threads, Unicode support, memory model, new headers, and changed semantics. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ock-free macros - aarch64 _Thread_local: implement Local Exec and Initial Exec TLS models with mrs tpidr_el0, :tprel_hi12:/:tprel_lo12_nc: (LE) and :gottpoff:/:gottpoff_lo12: (IE). Previously silently generated wrong code (treated TLS as regular globals). - _Noreturn codegen: emit Unreachable after noreturn calls in the linearizer, producing ud2 (x86) / brk (aarch64) safety traps and enabling DCE of dead code after noreturn calls. - Add <stdnoreturn.h> builtin header (noreturn macro). - Add ATOMIC_*_LOCK_FREE macros to <stdatomic.h>. - Audit and check off sections 1-5, 8-13, 18-20 of c11-checklist (0% → 59%, 154/259 items verified). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
make_complex now returns the input unchanged if already complex, and handles Float16 → complex_float16 explicitly instead of falling through to the default double _Complex. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- aarch64 TLS: gate :tprel_hi12:/:tprel_lo12_nc: relocations to Linux only (macOS uses TLV descriptors, not ELF TLS). Fixes assembler "unknown AArch64 fixup kind" errors on macOS. - macOS: define _FORTIFY_SOURCE=0 to prevent headers from redirecting memset/memcpy/strcpy to __memset_chk etc. Fixes 5 pre-existing "undeclared function" errors on macOS CI. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.