Support for converting a function to a C++ function pointer (#7789)

This commit is contained in:
Geoff Romer
2026-09-30 21:13:36 +00:00
committed by GitHub
parent cbdd6cee65
commit c0bd9606de
26 changed files with 1030 additions and 446 deletions
+15 -5
View File
@@ -77,11 +77,21 @@ auto ExportFieldToCpp(Context& context, SemIR::InstId field_inst_id,
SemIR::FieldDecl field_decl,
SemIR::SpecificId specific_id) -> clang::FieldDecl*;
// Get a `clang::FunctionDecl` that can be used to call a Carbon function.
// If the function is generic, a `clang::FunctionTemplateDecl` will be
// created instead.
auto ExportFunctionToCpp(Context& context, SemIR::LocId loc_id,
SemIR::FunctionId function_id) -> clang::NamedDecl*;
// Returns the `ClangDeclId` of a `clang::FunctionDecl` or
// `clang::FunctionTemplateDecl` that can be used to call the given function.
// Returns null if an error was diagnosed.
auto GetOrExportFunctionToCpp(Context& context, SemIR::LocId loc_id,
SemIR::FunctionId function_id)
-> clang::NamedDecl*;
// Exports the necessary declarations to permit conversion from the given
// Carbon function type to the given C++ function pointer type. If the
// conversion would be invalid, this will return false, and if `diagnose` is
// true it will also emit one or more diagnostics explaining the reason it would
// be invalid. In those diagnostics, `src_id` is the source of the conversion.
auto ExportFunctionToCppPointerConversion(
Context& context, SemIR::InstId src_id, SemIR::FunctionType src_type,
SemIR::CppFunctionPointerType dest_type, bool diagnose) -> bool;
// Exports a Carbon virtual function as a C++ `clang::FunctionDecl` declaration.
// Does not emit a definition.