Skip to content

Commit

Permalink
Handle special names by using GetIRBaseName()
Browse files Browse the repository at this point in the history
  • Loading branch information
bricknerb committed Feb 28, 2025
1 parent 3ec0ec8 commit 29e1548
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
5 changes: 2 additions & 3 deletions toolchain/check/import_cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,13 @@ static auto ClangLookup(Context& context, SemIR::LocId loc_id,
CARBON_CHECK(ast);
clang::Sema& sema = ast->getSema();

auto name = context.names().GetAsStringIfIdentifier(name_id);
CARBON_CHECK(name);
llvm::StringRef name = context.names().GetIRBaseName(name_id);

clang::LookupResult lookup(
sema,
clang::DeclarationNameInfo(
clang::DeclarationName(
sema.getPreprocessor().getIdentifierInfo(*name)),
sema.getPreprocessor().getIdentifierInfo(name)),
clang::SourceLocation()),
clang::Sema::LookupNameKind::LookupOrdinaryName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ fn MyF() {
Cpp.foo();
}

// --- function_special_name_decl.h

void base();

// --- import_function_special_name_decl.carbon

library "[[@TEST_NAME]]";

import Cpp library "function_special_name_decl.h";

fn MyF() {
Cpp.base();
}

// --- overloaded_function_decl.h

void foo();
Expand Down Expand Up @@ -194,6 +208,44 @@ fn F() {
// CHECK:STDOUT:
// CHECK:STDOUT: fn @foo[]();
// CHECK:STDOUT:
// CHECK:STDOUT: --- import_function_special_name_decl.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %MyF.type: type = fn_type @MyF [concrete]
// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
// CHECK:STDOUT: %MyF: %MyF.type = struct_value () [concrete]
// CHECK:STDOUT: %base.type: type = fn_type @base [concrete]
// CHECK:STDOUT: %base: %base.type = struct_value () [concrete]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: imports {
// CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
// CHECK:STDOUT: .base = @MyF.%base.decl
// CHECK:STDOUT: }
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: file {
// CHECK:STDOUT: package: <namespace> = namespace [concrete] {
// CHECK:STDOUT: .Cpp = imports.%Cpp
// CHECK:STDOUT: .MyF = %MyF.decl
// CHECK:STDOUT: }
// CHECK:STDOUT: %Cpp.import_cpp = import_cpp {
// CHECK:STDOUT: import Cpp "function_special_name_decl.h"
// CHECK:STDOUT: }
// CHECK:STDOUT: %MyF.decl: %MyF.type = fn_decl @MyF [concrete = constants.%MyF] {} {}
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @MyF() {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %Cpp.ref: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
// CHECK:STDOUT: %base.decl: %base.type = fn_decl @base [concrete = constants.%base] {} {}
// CHECK:STDOUT: %base.ref: %base.type = name_ref base, %base.decl [concrete = constants.%base]
// CHECK:STDOUT: %base.call: init %empty_tuple.type = call %base.ref()
// CHECK:STDOUT: return
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @base[]();
// CHECK:STDOUT:
// CHECK:STDOUT: --- fail_import_overloaded_function_decl.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
Expand Down

0 comments on commit 29e1548

Please sign in to comment.