Skip to content

Commit 016489e

Browse files
committed
[BitwiseCopyable] Don't infer for @sensitive.
1 parent 6e975da commit 016489e

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7728,6 +7728,8 @@ NOTE(note_non_bitwise_copyable_type_indirect_enum_element,none,
77287728
"indirect case is here", ())
77297729
ERROR(non_bitwise_copyable_type_suppressed,none,
77307730
"cannot both conform to and suppress conformance to 'BitwiseCopyable'", ())
7731+
ERROR(non_bitwise_copyable_type_sensitive,none,
7732+
"a @sensitive type cannot conform to 'BitwiseCopyable'", ())
77317733
ERROR(non_bitwise_copyable_type_cxx_nontrivial,none,
77327734
"non-trivial C++ type cannot conform to 'BitwiseCopyable'", ())
77337735
ERROR(non_bitwise_copyable_c_type_nontrivial,none,

lib/Sema/TypeCheckBitwise.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,14 @@ static bool checkBitwiseCopyableInstanceStorage(NominalTypeDecl *nominal,
237237
return true;
238238
}
239239

240+
auto &attrs = nominal->getAttrs();
241+
if (attrs.hasAttribute<SensitiveAttr>()) {
242+
if (!isImplicit(check)) {
243+
conformanceDecl->diagnose(diag::non_bitwise_copyable_type_sensitive);
244+
}
245+
return true;
246+
}
247+
240248
if (dc->mapTypeIntoContext(nominal->getDeclaredInterfaceType())
241249
->isNoncopyable()) {
242250
// Already separately diagnosed when explicit.

test/SILGen/bitwise_copyable.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// RUN: %s \
33
// RUN: -emit-silgen \
44
// RUN: -disable-availability-checking \
5+
// RUN: -enable-experimental-feature Sensitive \
56
// RUN: -enable-builtin-module
67

78
// REQUIRES: asserts
@@ -60,3 +61,10 @@ extension NeverGoingToBeBitwiseCopyable : _BitwiseCopyable {
6061
}
6162

6263
struct AlsoNotBitwiseCopyable : ~_BitwiseCopyable {}
64+
65+
@sensitive
66+
struct S_Explicit_Sensitive {
67+
}
68+
69+
func takeS_Explicit_Sensitive(_ s: S_Explicit_Sensitive) {
70+
}

test/Sema/bitwise_copyable.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// RUN: -disable-availability-checking \
33
// RUN: -enable-experimental-feature NonescapableTypes \
44
// RUN: -enable-experimental-feature NoncopyableGenerics \
5+
// RUN: -enable-experimental-feature Sensitive \
56
// RUN: -enable-builtin-module \
67
// RUN: -debug-diagnostic-names
78

@@ -93,6 +94,19 @@ struct S_Explicit_With_Metatype_Optional_AnyObject : _BitwiseCopyable {
9394
var ty: Optional<AnyObject>.Type
9495
}
9596

97+
@sensitive
98+
struct S_Explicit_Sensitive : _BitwiseCopyable { // expected-error {{a @sensitive type cannot conform to 'BitwiseCopyable'}}
99+
}
100+
101+
@sensitive
102+
struct S_Implicit_Sensitive {
103+
}
104+
105+
func passS_Implicit_Sensitive(_ s: S_Implicit_Sensitive) {
106+
take1(s) // expected-error {{type_does_not_conform_decl_owner}}
107+
// expected-note@-94 {{where_requirement_failure_one_subst}}
108+
}
109+
96110
//==============================================================================
97111
//===========================DEPENDENCY-FREE TESTS=(END)======================}}
98112
//==============================================================================

0 commit comments

Comments
 (0)