Skip to content

Commit c3eb234

Browse files
committed
[cxx-interop] Prevent Swift from importing fields marked with [[no_unique_address]]
1 parent 7418b25 commit c3eb234

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

include/swift/AST/DiagnosticsClangImporter.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,5 +373,8 @@ NOTE(ptr_to_nonescapable,none,
373373
"pointer to non-escapable type %0 cannot be imported",
374374
(const clang::Type*))
375375

376+
WARNING(unsupported_attribute, none,
377+
"Swift doesn't support fields marked with %0", (StringRef))
378+
376379
#define UNDEFINE_DIAGNOSTIC_MACROS
377380
#include "DefineDiagnosticMacros.h"

lib/ClangImporter/ImportDecl.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4383,6 +4383,16 @@ namespace {
43834383
std::optional<ImportedName> correctSwiftName;
43844384
ImportedName importedName;
43854385

4386+
if (decl->hasAttr<clang::NoUniqueAddressAttr>()) {
4387+
// FIXME: Swift doesn't support fields marked with [[no_unique_address]] rdar://148437848
4388+
4389+
Impl.addImportDiagnostic(
4390+
decl,
4391+
Diagnostic(diag::unsupported_attribute, "[[no_unique_address]]"),
4392+
decl->getLocation());
4393+
return nullptr;
4394+
}
4395+
43864396
std::tie(importedName, correctSwiftName) = importFullName(decl);
43874397
if (!importedName) {
43884398
return nullptr;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift %s -o %t/strings -Xfrontend -enable-experimental-cxx-interop
3+
// RUN: %target-codesign %t/strings
4+
// RUN: %target-run %t/strings
5+
6+
// REQUIRES: executable_test
7+
8+
import CxxStdlib
9+
10+
public func test() {
11+
let cxxString: std.string = "Hello"
12+
print(cxxString)
13+
let swiftString = String(cxxString)
14+
print(swiftString)
15+
}
16+

0 commit comments

Comments
 (0)