Skip to content

translate-c: fix function prototype decalared inside a function #23429

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 2, 2025

Conversation

flyfish30
Copy link
Contributor

@flyfish30 flyfish30 commented Apr 1, 2025

Fixes #20330

If a function prototype is declarated inside a function, do not translate it to a top-level extern function declaration. Similar to extern local variable, just wrapped it into a block-local struct.

Copy link
Member

@Vexu Vexu left a comment

Choose a reason for hiding this comment

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

Some small nits, these don't matter too much since this is supposed to get replaced by https://github.com/ziglang/translate-c/.

Note that I also edited your description to use a closing keyword.

* If a function prototype is declarated inside a function, do not
  translate it to a top-level extern function declaration. Similar to
  extern local variable, just wrapped it into a block-local struct.

* Add a new extern_local_fn tag of aro_translate_c node for present
  extern local function declaration.

* When a function body has a C function prototype declaration, it adds
  an extern local function declaration. Subsequent function references
  will look for this function declaration.
@flyfish30 flyfish30 force-pushed the fix-extern-func-decl branch from f56a858 to 7dfdd83 Compare April 2, 2025 06:45
@flyfish30
Copy link
Contributor Author

Some small nits, these don't matter too much since this is supposed to get replaced by https://github.com/ziglang/translate-c/.

Will the bugs before 0.15.0 be migrated to the new translate-c package or will they be fixed in the code of this Zig compiler?

@Vexu
Copy link
Member

Vexu commented Apr 2, 2025

Will the bugs before 0.15.0 be migrated to the new translate-c package or will they be fixed in the code of this Zig compiler?

All the issues will be fixed in the new package but they can also be fixed in the Clang version before it is removed.

@Vexu Vexu enabled auto-merge (squash) April 2, 2025 17:26
@Vexu Vexu merged commit de62dc8 into ziglang:master Apr 2, 2025
9 checks passed
@alexrp alexrp added this to the 0.14.1 milestone Apr 2, 2025
@flyfish30 flyfish30 deleted the fix-extern-func-decl branch April 3, 2025 02:49
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.

Translate-C Fails to Properly Translate Function Prototypes within Function Blocks
3 participants