mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 17:51:05 +01:00
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:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user