gen-c: an un-annotated local takes its type from the initialiser (Refs #2161) - #2734
Merged
Conversation
…#2161) The fallback for a local with no declared type was C's `int`. Two arms above it already special-case integer literals (u32/u64), so what the fallback actually caught was everything else -- a CALL among them: pub fn big() -> u64 { return 4294967296; } pub fn plus_one() -> u64 { const v = big(); // int v = big(); return v + 1; } C prints 1. Rust and Zig print 4294967297. The C compiles without a diagnostic, so nothing downstream can tell -- a silent wrong answer, which is worse than a loud one. Now GNU `__auto_type` when there is an initialiser, which is the same builtin the tuple-destructure paths a few hundred lines above already emit, so it costs no new portability. Without an initialiser there is nothing for it to follow and `int` stays. Measured over 746 tracked specs, before binary vs after: specs whose C output changes 396 cc -fsyntax-only -std=gnu11 errors 6163 -> 5958 specs whose generated C is clean 19 -> 20 specs that went clean -> broken 0 That last row is the one that matters at this radius. Parse count 620/746 and tests 1629 passed / 6 failed are both unchanged. The probe now agrees across backends: C prints 4294967297, same as Rust. FROZEN_HASH resealed in the same commit (M5).
Contributor
PR DashboardGenerated at: 2026-08-27 19:03:31 UTC
Summary
Seal Status
|
Contributor
|
📓 NotebookLM Notebook linked to this PR
This notebook contains session context, decisions, and artifacts for this work. |
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.
The fallback for a local with no declared type was C's
int. Two arms above it already special-case integer literals (u32/u64), so what the fallback actually caught was everything else — a call among them:C prints 1. Rust and Zig print 4294967297. The C compiles without a diagnostic, so nothing downstream can tell — a silent wrong answer, which is worse than a loud one.
Now GNU
__auto_typewhen there is an initialiser — the same builtin the tuple-destructure paths a few hundred lines above already emit, so it costs no new portability. Without an initialiser there is nothing for it to follow andintstays.Measured over 746 tracked specs
cc -fsyntax-only -std=gnu11errorsThat last row is the one that matters at this radius. Counting only the totals would have hidden a swap — two fixed and one broken looks the same as one fixed in a sum.
Parse count 620/746 and tests 1629 passed / 6 failed are both unchanged.
The probe now agrees across backends: C prints 4294967297, same as Rust.
Refs #2161