Skip to content

Commit 6818eef

Browse files
authored
[C++ Interop] Fix method mangling. (#26468)
1 parent 1533a84 commit 6818eef

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

lib/SIL/SILDeclRef.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -684,10 +684,10 @@ std::string SILDeclRef::mangle(ManglingKind MKind) const {
684684
std::string s(1, '\01');
685685
s += asmLabel->getLabel();
686686
return s;
687-
} else if (namedClangDecl->hasAttr<clang::OverloadableAttr>()) {
687+
} else if (namedClangDecl->hasAttr<clang::OverloadableAttr>() ||
688+
getDecl()->getASTContext().LangOpts.EnableCXXInterop) {
688689
std::string storage;
689690
llvm::raw_string_ostream SS(storage);
690-
// FIXME: When we can import C++, use Clang's mangler all the time.
691691
mangleClangDecl(SS, namedClangDecl, getDecl()->getASTContext());
692692
return SS.str();
693693
}

test/ClangImporter/Inputs/custom-modules/cxx_interop.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,8 @@ class Methods {
2929

3030
static int SimpleStaticMethod(int);
3131
};
32+
33+
class Methods2 {
34+
public:
35+
int SimpleMethod(int);
36+
};

test/ClangImporter/cxx_interop_ir.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,12 @@ func basicMethodsConst(a: UnsafeMutablePointer<Methods>) -> Int32 {
5050
func basicMethodsStatic() -> Int32 {
5151
return Methods.SimpleStaticMethod(5)
5252
}
53+
54+
// CHECK-LABEL: define hidden swiftcc i32 @"$s6cxx_ir12basicMethods1as5Int32VSpySo8Methods2VG_tF"(i8*)
55+
// CHECK: [[THIS_PTR1:%.*]] = bitcast i8* %0 to %TSo8Methods2V*
56+
// CHECK: [[THIS_PTR2:%.*]] = bitcast %TSo8Methods2V* [[THIS_PTR1]] to %class.Methods2*
57+
// CHECK: [[RESULT:%.*]] = call i32 @{{_ZN8Methods212SimpleMethodEi|"\?SimpleMethod@Methods2@@QEAAHH@Z"}}(%class.Methods2* [[THIS_PTR2]], i32 4)
58+
// CHECK: ret i32 [[RESULT]]
59+
func basicMethods(a: UnsafeMutablePointer<Methods2>) -> Int32 {
60+
return a.pointee.SimpleMethod(4)
61+
}

0 commit comments

Comments
 (0)