cl wrapInlineFunc: extern C - #723
Conversation
There was a problem hiding this comment.
Review: emit extern "C" for C++ inline wrappers
The change threads the existing ctx.lang (Config.Language) through writeFunc → writeFuncProto 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-leveloutbuffer beforewriteParam(out, retType, ...), so it is emitted once per function and not repeated on nested parameter/return recursion. Call site coverage is complete (single caller atcl/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.
No description provided.