Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/ClangImporter/ClangImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8232,6 +8232,9 @@ CxxRecordSemantics::evaluate(Evaluator &evaluator,

auto cxxDecl = dyn_cast<clang::CXXRecordDecl>(decl);
if (!cxxDecl) {
if (hasNonCopyableAttr(decl))
return CxxRecordSemanticsKind::MoveOnly;

return CxxRecordSemanticsKind::Trivial;
}

Expand Down
4 changes: 4 additions & 0 deletions test/Interop/C/struct/Inputs/module.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ module ForeignReference {
module StructAsOptionSet {
header "struct-as-option-set.h"
}

module NoncopyableStructs {
header "noncopyable-struct.h"
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: missing new line

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add it in a follow-up PR

5 changes: 5 additions & 0 deletions test/Interop/C/struct/Inputs/noncopyable-struct.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// RUN: %target-typecheck-verify-swift -I %S/Inputs/

typedef struct __attribute__((swift_attr("~Copyable"))) NonCopyable {
float x, y;
} NonCopyable;
29 changes: 29 additions & 0 deletions test/Interop/C/struct/noncopyable_structs.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

// Check that we get the expected errors for incorrect uses of noncopyable
// imported types with both C and C++ interoperability.

// RUN: %target-swift-frontend -emit-sil -I %S/Inputs/ %s -verify -DERRORS
// RUN: %target-swift-frontend -emit-sil -I %S/Inputs/ %s -verify -DERRORS -cxx-interoperability-mode=default

// Check that we get the expected IR

// RUN: %target-swift-frontend -emit-ir -I %S/Inputs/ %s -o - | %FileCheck %s
// RUN: %target-swift-frontend -emit-ir -I %S/Inputs/ %s -o - -cxx-interoperability-mode=default| %FileCheck %s

import NoncopyableStructs

// CHECK-LABEL: define hidden swiftcc void @"$s19noncopyable_structs9consumeNCyySo11NonCopyableVnF"(float %0, float %1) #0 {
// CHECK: call ptr @"$sSo11NonCopyableVWOh"
// CHECK: define linkonce_odr hidden ptr @"$sSo11NonCopyableVWOh"(ptr %0)
// CHECK-NEXT: entry:
// CHECK-NEXT: ret ptr
func consumeNC(_ nc: consuming NonCopyable) { }

func testNC() {
let nc = NonCopyable() // expected-error{{'nc' consumed more than once}}
consumeNC(nc) // expected-note{{consumed here}}

#if ERRORS
consumeNC(nc) // expected-note{{consumed again here}}
#endif
}