@@ -20,17 +20,11 @@ namespace Carbon::Check {
20
20
21
21
// Returns the C++ thunk mangled name given the callee function.
22
22
static auto GenerateThunkMangledName (
23
- clang::ASTContext& ast_context ,
23
+ clang::MangleContext& mangle_context ,
24
24
const clang::FunctionDecl& callee_function_decl) -> std::string {
25
25
RawStringOstream mangled_name_stream;
26
- {
27
- // TODO: Create `MangleContext` once.
28
- std::unique_ptr<clang::MangleContext> mangle_context (
29
- ast_context.createMangleContext ());
30
- mangle_context->mangleName (clang::GlobalDecl (&callee_function_decl),
31
- mangled_name_stream);
32
- }
33
-
26
+ mangle_context.mangleName (clang::GlobalDecl (&callee_function_decl),
27
+ mangled_name_stream);
34
28
mangled_name_stream << " .carbon_thunk" ;
35
29
36
30
return mangled_name_stream.TakeStr ();
@@ -185,9 +179,9 @@ static auto BuildThunkParameters(
185
179
// Returns the thunk function declaration given the callee function and the
186
180
// thunk parameter types.
187
181
static auto CreateThunkFunctionDecl (
188
- clang::ASTContext& ast_context,
189
- const clang::FunctionDecl& callee_function_decl,
182
+ Context& context, const clang::FunctionDecl& callee_function_decl,
190
183
llvm::ArrayRef<clang::QualType> thunk_param_types) -> clang::FunctionDecl* {
184
+ clang::ASTContext& ast_context = context.ast_context ();
191
185
clang::SourceLocation clang_loc = callee_function_decl.getLocation ();
192
186
193
187
clang::IdentifierInfo& identifier_info = ast_context.Idents .get (
@@ -216,7 +210,9 @@ static auto CreateThunkFunctionDecl(
216
210
217
211
// Set asm("<callee function mangled name>.carbon_thunk").
218
212
thunk_function_decl->addAttr (clang::AsmLabelAttr::CreateImplicit (
219
- ast_context, GenerateThunkMangledName (ast_context, callee_function_decl),
213
+ ast_context,
214
+ GenerateThunkMangledName (*context.sem_ir ().clang_mangle_context (),
215
+ callee_function_decl),
220
216
clang_loc));
221
217
222
218
return thunk_function_decl;
@@ -278,8 +274,6 @@ static auto BuildThunkBody(clang::Sema& sema,
278
274
279
275
auto BuildCppThunk (Context& context, const SemIR::Function& callee_function)
280
276
-> clang::FunctionDecl* {
281
- clang::ASTContext& ast_context = context.ast_context ();
282
-
283
277
clang::FunctionDecl* callee_function_decl =
284
278
context.sem_ir ()
285
279
.clang_decls ()
@@ -289,9 +283,9 @@ auto BuildCppThunk(Context& context, const SemIR::Function& callee_function)
289
283
290
284
// Build the thunk function declaration.
291
285
auto [thunk_param_types, param_type_changed] =
292
- BuildThunkParameterTypes (ast_context, *callee_function_decl);
286
+ BuildThunkParameterTypes (context. ast_context () , *callee_function_decl);
293
287
clang::FunctionDecl* thunk_function_decl = CreateThunkFunctionDecl (
294
- ast_context , *callee_function_decl, thunk_param_types);
288
+ context , *callee_function_decl, thunk_param_types);
295
289
296
290
// Build the thunk function body.
297
291
clang::Sema& sema = context.sem_ir ().cpp_ast ()->getSema ();
0 commit comments