Skip to content

Commit b6ba81d

Browse files
authored
Merge pull request #85477 from DougGregor/no-mangled-extern-c-decls
[Clang mangling] Don't mangle when Clang says not to
2 parents 3545603 + e423d77 commit b6ba81d

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4763,8 +4763,10 @@ void ClangImporter::Implementation::getMangledName(
47634763
auto ctorGlobalDecl =
47644764
clang::GlobalDecl(ctor, clang::CXXCtorType::Ctor_Complete);
47654765
mangler->mangleCXXName(ctorGlobalDecl, os);
4766-
} else {
4766+
} else if (mangler->shouldMangleDeclName(clangDecl)) {
47674767
mangler->mangleName(clangDecl, os);
4768+
} else {
4769+
os << clangDecl->getName();
47684770
}
47694771
}
47704772

test/Inputs/clang-importer-sdk/usr/include/string.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77

88
#include <stdint.h>
99

10+
#ifdef __cplusplus
11+
extern "C" {
12+
13+
typedef __SIZE_TYPE__ size_t;
14+
#endif
15+
1016
void* memcpy(void* s1, const void* s2, size_t n);
1117
void* memmove(void* s1, const void* s2, size_t n);
1218
char* strcpy (char* s1, const char* s2);
@@ -30,4 +36,8 @@ void* memset(void* s, int c, size_t n);
3036
char* strerror(int errnum);
3137
size_t strlen(const char* s);
3238

39+
#ifdef __cplusplus
40+
}
41+
#endif
42+
3343
#endif // SDK_STRING_H
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#ifdef __cplusplus
2+
extern "C" {
3+
#endif
4+
5+
typedef __SIZE_TYPE__ size_t;
6+
7+
void* memset(void* s, int c, size_t n);
8+
9+
#ifdef __cplusplus
10+
}
11+
#endif
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %target-swift-emit-silgen(mock-sdk: %clang-importer-sdk) %s -I %S/Inputs -import-bridging-header %S/Inputs/my-memory.h -enable-experimental-cxx-interop | %FileCheck %s
2+
3+
4+
func zerome(ptr: UnsafeMutablePointer<Int>) {
5+
memset(ptr, 0, MemoryLayout<Int>.size)
6+
}
7+
8+
// Verify that the asmname is "memset", not a C++-mangled version
9+
// CHECK: sil [serialized] [asmname "memset"] [clang memset] @$sSo6memsetySvSgAB_s5Int32VSitFTo : $@convention(c) (Optional<UnsafeMutableRawPointer>, Int32, Int) -> Optional<UnsafeMutableRawPointer>

0 commit comments

Comments
 (0)