mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
C++ interop: support for default arguments. (#6108)
The general strategy here is to force use of a thunk when we want to use default arguments, and have Clang generate uses of the default arguments on its side of the thunk. To support this, change the key type used in `clang_decls` from being just a `Decl*` to being a pair of `Decl*` and number of parameters in the case of function decls. Import distinct `SemIR::Function`s for each number of parameters that's used, and corresponding distinct thunks. --------- Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
This commit is contained in:
co-authored by
Jon Ross-Perkins
parent
82679e6689
commit
1e7b7e53ae
@@ -437,6 +437,20 @@ auto FileContext::BuildFunctionDecl(SemIR::FunctionId function_id,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Don't lower C++ functions that use a thunk. We will never reference them
|
||||
// directly, and their signatures would not be expected to match the
|
||||
// corresponding C++ function anyway.
|
||||
if (function.special_function_kind ==
|
||||
SemIR::Function::SpecialFunctionKind::HasCppThunk) {
|
||||
// Make sure Clang emits this function.
|
||||
// TODO: This shouldn't be necessary: Clang should emit definitions of
|
||||
// functions that it emits calls to. But this doesn't currently work.
|
||||
auto clang_decl_id = sem_ir().functions().Get(function_id).clang_decl_id;
|
||||
HandleReferencedCppFunction(cast<clang::FunctionDecl>(
|
||||
sem_ir().clang_decls().Get(clang_decl_id).key.decl));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// TODO: Consider tracking whether the function has been used, and only
|
||||
// lowering it if it's needed.
|
||||
|
||||
@@ -467,7 +481,7 @@ auto FileContext::BuildFunctionDecl(SemIR::FunctionId function_id,
|
||||
CARBON_CHECK(!specific_id.has_value(),
|
||||
"Specific functions cannot have C++ definitions");
|
||||
HandleReferencedCppFunction(
|
||||
sem_ir().clang_decls().Get(clang_decl_id).decl->getAsFunction());
|
||||
sem_ir().clang_decls().Get(clang_decl_id).key.decl->getAsFunction());
|
||||
// TODO: Check that the signature and mangling generated by Clang and the
|
||||
// one we generated are the same.
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user