Skip to content

Commit 508a88e

Browse files
authored
C++ inteop: Set type source info for a generated C++ thunk function (#6049)
This prevents a null pointer access crash when generating a thunk with an automatically deduced trivial return type. In this case, Clang calls `Sema::DeduceFunctionTypeFromReturnExpr()` which calls `Sema::getReturnTypeLoc()`, which requires this information. Part of #5514.
1 parent d60900c commit 508a88e

File tree

2 files changed

+267
-1
lines changed

2 files changed

+267
-1
lines changed

toolchain/check/cpp_thunk.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,10 @@ static auto CreateThunkFunctionDecl(
335335
*callee_info.decl),
336336
clang_loc));
337337

338+
// Set function declaration type source info.
339+
thunk_function_decl->setTypeSourceInfo(ast_context.getTrivialTypeSourceInfo(
340+
thunk_function_decl->getType(), clang_loc));
341+
338342
return thunk_function_decl;
339343
}
340344

0 commit comments

Comments
 (0)