mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 22:02:52 +01:00
Support mangling imported C++ functions using Clang's MangleContext (#5062)
Keep a pointer to the Clang declaration in Carbon's function declaration and use it in Carbon mangling by calling Clang mangling. Create Clang's `MangleContext` once on demand. Part of #4666. C++ Interop Demo: ```c++ // hello_world.h void hello_world(); ``` ```c++ // hello_world.cpp #include <cstdio> void hello_world() { printf("Hello World!\n"); } ``` ``` // main.carbon library "Main"; import Cpp library "hello_world.h"; fn Run() -> i32 { Cpp.hello_world(); return 0; } ``` ```shell $ clang -c hello_world.cpp $ bazel-bin/toolchain/carbon compile main.carbon $ bazel-bin/toolchain/carbon link hello_world.o main.o --output=demo $ ./demo Hello World! ```
This commit is contained in:
@@ -237,7 +237,8 @@ static auto ImportFunctionDecl(Context& context, SemIR::LocId loc_id,
|
||||
.definition_id = SemIR::InstId::None},
|
||||
{.return_slot_pattern_id = SemIR::InstId::None,
|
||||
.virtual_modifier = SemIR::FunctionFields::VirtualModifier::None,
|
||||
.self_param_id = SemIR::InstId::None}};
|
||||
.self_param_id = SemIR::InstId::None,
|
||||
.cpp_decl = clang_decl}};
|
||||
|
||||
function_decl.function_id = context.functions().Add(function_info);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user