Give Carbon -> C++ thunks internal linkage. (#7040)

Also declare them `inline` since we're putting the `always_inline`
attribute on them. Use the `internal_linkage` attribute rather than
`SC_Static` since it's a more precise mechanism and matches what we do
for static member functions in reverse interop (where `SC_Static` means
something else and would not give the function internal linkage).
This commit is contained in:
Richard Smith
2026-04-08 21:14:30 +00:00
committed by GitHub
parent b79d9adeca
commit be0c07dc7e
15 changed files with 2124 additions and 2118 deletions
+7 -6
View File
@@ -419,19 +419,20 @@ static auto CreateThunkFunctionDecl(
thunk_param_types, ext_proto_info);
clang::DeclContext* decl_context = ast_context.getTranslationUnitDecl();
// TODO: Thunks should not have external linkage, consider using `SC_Static`.
clang::FunctionDecl* thunk_function_decl =
clang::FunctionDecl::Create(ast_context, decl_context, clang_loc,
clang_loc, name, thunk_function_type,
/*TInfo=*/nullptr, clang::SC_Extern);
clang::FunctionDecl* thunk_function_decl = clang::FunctionDecl::Create(
ast_context, decl_context, clang_loc, clang_loc, name,
thunk_function_type, /*TInfo=*/nullptr, clang::SC_None,
/*UsesFPIntrin=*/false, /*isInlineSpecified=*/true);
decl_context->addDecl(thunk_function_decl);
thunk_function_decl->setParams(
BuildThunkParameters(ast_context, callee_info, thunk_function_decl));
// Set always_inline.
// Force the thunk to be inlined and discarded.
thunk_function_decl->addAttr(
clang::AlwaysInlineAttr::CreateImplicit(ast_context));
thunk_function_decl->addAttr(
clang::InternalLinkageAttr::CreateImplicit(ast_context));
// Set asm("<callee function mangled name>.carbon_thunk").
thunk_function_decl->addAttr(clang::AsmLabelAttr::CreateImplicit(