mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Clang mangling] Don't mangle when Clang says not to
We have been mangling extern "C" symbols when building with C++ interoperability, leading to incorrectly-mangled names such as _Z6memset that should have been unmangled "memset". Fix this so we get consistent mangling between C and C++ interoperability modes. Fixes rdar://164495210.
This commit is contained in:
@@ -4759,8 +4759,10 @@ void ClangImporter::Implementation::getMangledName(
|
||||
auto ctorGlobalDecl =
|
||||
clang::GlobalDecl(ctor, clang::CXXCtorType::Ctor_Complete);
|
||||
mangler->mangleCXXName(ctorGlobalDecl, os);
|
||||
} else {
|
||||
} else if (mangler->shouldMangleDeclName(clangDecl)) {
|
||||
mangler->mangleName(clangDecl, os);
|
||||
} else {
|
||||
os << clangDecl->getName();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,12 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
typedef __SIZE_TYPE__ size_t;
|
||||
#endif
|
||||
|
||||
void* memcpy(void* s1, const void* s2, size_t n);
|
||||
void* memmove(void* s1, const void* s2, size_t n);
|
||||
char* strcpy (char* s1, const char* s2);
|
||||
@@ -30,4 +36,8 @@ void* memset(void* s, int c, size_t n);
|
||||
char* strerror(int errnum);
|
||||
size_t strlen(const char* s);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // SDK_STRING_H
|
||||
|
||||
9
test/Interop/Cxx/extern-c/decls.swift
Normal file
9
test/Interop/Cxx/extern-c/decls.swift
Normal file
@@ -0,0 +1,9 @@
|
||||
// RUN: %target-swift-emit-silgen(mock-sdk: %clang-importer-sdk) %s -I %S/Inputs -import-bridging-header %S/../../../Inputs/clang-importer-sdk/usr/include/string.h -enable-experimental-cxx-interop | %FileCheck %s
|
||||
|
||||
|
||||
func zerome(ptr: UnsafeMutablePointer<Int>) {
|
||||
memset(ptr, 0, MemoryLayout<Int>.size)
|
||||
}
|
||||
|
||||
// Verify that the asmname is "memset", not a C++-mangled version
|
||||
// CHECK: sil [serialized] [asmname "memset"] [clang memset] @$sSo6memsetySvSgAB_s5Int32VSitFTo : $@convention(c) (Optional<UnsafeMutableRawPointer>, Int32, Int) -> Optional<UnsafeMutableRawPointer>
|
||||
Reference in New Issue
Block a user