Skip to content

cl wrapInlineFunc: extern C - #723

Merged
xushiwei merged 1 commit into
goplus:devfrom
xushiwei:q
Sep 16, 2026
Merged

xushiwei merged 1 commit into
goplus:devfrom
xushiwei:q

Conversation

@xushiwei

Copy link
Copy Markdown
Member

No description provided.

@fennoai fennoai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review: emit extern "C" for C++ inline wrappers

The change threads the existing ctx.lang (Config.Language) through writeFuncwriteFuncProto and prepends extern "C" to generated wrapper definitions when lang == LanguageCXX. This is correct and necessary: without C linkage, the C++ compiler would name-mangle the _llcppg_* wrapper symbols, breaking the link from the LLGo/Go side that references them by their plain mangling-derived names. The C path (default LanguageC) is untouched, and both C++ golden fixtures (ctor_dtor/wrap.cpp, inline/wrap.cpp) are updated consistently while the C golden file correctly stays unprefixed.

Reviewed for correctness, performance, security, and documentation accuracy — no blocking issues.

  • Correctness: extern "C" is written to the top-level out buffer before writeParam(out, retType, ...), so it is emitted once per function and not repeated on nested parameter/return recursion. Call site coverage is complete (single caller at cl/wrap.go:63).
  • Security / Performance: No concerns — a hardcoded literal gated on an internal enum, written once per wrapped function at build time.

Optional (non-blocking): The function-pointer-return-type path in C++ mode isn't exercised by either golden test (both use void / unsigned int returns). extern "C" <ret>(*name(...))(...) is still valid C++, but adding a golden case with a function-pointer return under LanguageCXX would lock in the emitted formatting for the least-obvious path.

LGTM.

@xushiwei
xushiwei merged commit 9acf839 into goplus:dev Sep 16, 2026
2 checks passed
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.

1 participant