Skip to content

Commit 673874d

Browse files
committed
[Serialization] Don't serialize invalid attributes
This isn't just an optimization; we weren't recording that the attribute was invalid, and so it was getting /treated as valid/ when the module was imported into a client later. This would have caught the issue fixed by the previous commit.
1 parent a394205 commit 673874d

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

lib/Serialization/Serialization.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2186,6 +2186,12 @@ void Serializer::writeDeclAttribute(const DeclAttribute *DA) {
21862186
if (DA->isNotSerialized())
21872187
return;
21882188

2189+
// Ignore attributes that have been marked invalid. (This usually means
2190+
// type-checking removed them, but only provided a warning rather than an
2191+
// error.)
2192+
if (DA->isInvalid())
2193+
return;
2194+
21892195
switch (DA->getKind()) {
21902196
case DAK_RawDocComment:
21912197
case DAK_ReferenceOwnership: // Serialized as part of the type.

test/Serialization/attr-invalid.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-module -o %t/attr.swiftmodule %s -verify
3+
// RUN: llvm-bcanalyzer -dump %t/attr.swiftmodule | %FileCheck -check-prefix=CHECK-NON-RESILIENT %s
4+
// RUN: %target-swift-frontend -emit-module -o %t/attr_resilient.swiftmodule -enable-resilience -warnings-as-errors %s
5+
// RUN: llvm-bcanalyzer -dump %t/attr_resilient.swiftmodule | %FileCheck -check-prefix=CHECK-RESILIENT %s
6+
7+
// These two should be checking for the same thing.
8+
// CHECK-RESILIENT: Frozen_DECL_ATTR
9+
// CHECK-NON-RESILIENT-NOT: Frozen_DECL_ATTR
10+
11+
@_frozen // expected-warning {{@_frozen has no effect without -enable-resilience}}
12+
public enum SomeEnum {
13+
case x
14+
}

test/api-digester/compare-dump.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// RUN: %empty-directory(%t.mod)
22
// RUN: %empty-directory(%t.sdk)
33
// RUN: %empty-directory(%t.module-cache)
4-
// RUN: %swift -emit-module -o %t.mod/cake1.swiftmodule %S/Inputs/cake1.swift -parse-as-library -I %S/Inputs/APINotesLeft %clang-importer-sdk-nosource
5-
// RUN: %swift -emit-module -o %t.mod/cake2.swiftmodule %S/Inputs/cake2.swift -parse-as-library -I %S/Inputs/APINotesRight %clang-importer-sdk-nosource
4+
// RUN: %swift -emit-module -o %t.mod/cake1.swiftmodule %S/Inputs/cake1.swift -parse-as-library -enable-resilience -I %S/Inputs/APINotesLeft %clang-importer-sdk-nosource
5+
// RUN: %swift -emit-module -o %t.mod/cake2.swiftmodule %S/Inputs/cake2.swift -parse-as-library -enable-resilience -I %S/Inputs/APINotesRight %clang-importer-sdk-nosource
66
// RUN: %api-digester -dump-sdk -module cake1 -o %t.dump1.json -module-cache-path %t.module-cache %clang-importer-sdk-nosource -I %t.mod -I %S/Inputs/APINotesLeft
77
// RUN: %api-digester -dump-sdk -module cake2 -o %t.dump2.json -module-cache-path %t.module-cache %clang-importer-sdk-nosource -I %t.mod -I %S/Inputs/APINotesRight
88
// RUN: %api-digester -diagnose-sdk -print-module --input-paths %t.dump1.json -input-paths %t.dump2.json > %t.result

0 commit comments

Comments
 (0)