Skip to content

Commit 1f7f6c6

Browse files
committed
api-digester: Don’t compare invalid attributes
The API digester represents unknown attributes as DAK_Count, but passing this value to the `is{Adding,Removing}Breaking{API,ABI}()` functions is not permitted. On some platforms this would cause a crash; on others it hit unreachable code which happened to end up working. Skip these unknown attributes during comparisons to avoid this problem.
1 parent 411b14f commit 1f7f6c6

File tree

4 files changed

+44
-3
lines changed

4 files changed

+44
-3
lines changed

lib/APIDigester/ModuleAnalyzerNodes.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2897,6 +2897,10 @@ void swift::ide::api::SDKNodeDecl::diagnose(SDKNode *Right) {
28972897

28982898
// Diagnose removing attributes.
28992899
for (auto Kind: getDeclAttributes()) {
2900+
if (Kind == swift::DAK_Count)
2901+
// Unknown attribute, diagnosed elsewhere.
2902+
continue;
2903+
29002904
if (!RD->hasDeclAttribute(Kind)) {
29012905
if ((Ctx.checkingABI() ? DeclAttribute::isRemovingBreakingABI(Kind) :
29022906
DeclAttribute::isRemovingBreakingAPI(Kind)) &&
@@ -2909,6 +2913,10 @@ void swift::ide::api::SDKNodeDecl::diagnose(SDKNode *Right) {
29092913

29102914
// Diagnose adding attributes.
29112915
for (auto Kind: RD->getDeclAttributes()) {
2916+
if (Kind == swift::DAK_Count)
2917+
// Unknown attribute, diagnosed elsewhere.
2918+
continue;
2919+
29122920
if (!hasDeclAttribute(Kind)) {
29132921
if ((Ctx.checkingABI() ? DeclAttribute::isAddingBreakingABI(Kind) :
29142922
DeclAttribute::isAddingBreakingAPI(Kind)) &&
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"kind": "Root",
3+
"name": "TopLevel",
4+
"printedName": "TopLevel",
5+
"children": [
6+
{
7+
"kind": "Function",
8+
"declAttributes": ["Available", "ObjC"],
9+
"declKind": "Func",
10+
"name": "foo",
11+
"children": [],
12+
"usr": "s:11diagnostics3fooP"
13+
}
14+
]
15+
}

test/api-digester/diagnostics.json renamed to test/api-digester/Inputs/diagnostics.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
"typeAttributes": ["autoclosure", "fnord", "inout", "Available"],
1010
"declAttributes": ["Available", "Fnord", "ObjC", "inout"],
1111
"declKind": "Subroutine"
12+
},
13+
{
14+
"kind": "Function",
15+
"declAttributes": ["Available", "Fnord", "ObjC", "inout"],
16+
"declKind": "Func",
17+
"name": "foo",
18+
"children": [],
19+
"usr": "s:11diagnostics3fooP"
1220
}
1321
]
1422
}

test/api-digester/diagnostics.swift

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
// REQUIRES: OS=macosx
2-
// RUN: not %api-digester -deserialize-sdk -input-paths %S/diagnostics.json -o - 2>&1 | %FileCheck %s
3-
// RUN: not %api-digester -diagnose-sdk -input-paths %S/diagnostics.json -input-paths %S/diagnostics.json -compiler-style-diags -o - 2>&1 | %FileCheck %s
2+
// RUN: %empty-directory(%t)
3+
4+
// RUN: not %api-digester -deserialize-sdk -input-paths %S/Inputs/diagnostics.json -o - >%t/deserialize.txt 2>&1
5+
// RUN: %FileCheck --input-file %t/deserialize.txt %s
6+
// RUN-X: %FileCheck --input-file %t/deserialize.txt --check-prefix NEGATIVE %s
7+
8+
// RUN: not %api-digester -diagnose-sdk -input-paths %S/Inputs/diagnostics.json -input-paths %S/Inputs/diagnostics-compare.json -compiler-style-diags -o - >%t/diagnose.txt 2>&1
9+
// RUN: %FileCheck --input-file %t/diagnose.txt %s
10+
// RUN: %FileCheck --input-file %t/diagnose.txt --check-prefix NEGATIVE %s
411

512
// CHECK: diagnostics.json:5:3: error: unrecognized key 'badKey' in SDK node
613
// CHECK: diagnostics.json:8:15: error: unrecognized SDK node kind 'Zyzyx'
@@ -11,4 +18,7 @@
1118
// CHECK: diagnostics.json:11:19: error: unrecognized declaration kind 'Subroutine' in SDK node
1219

1320
// Make sure we don't try to output a result:
14-
// CHECK-NOT: "kind": "Root",
21+
// NEGATIVE-NOT: "kind": "Root",
22+
23+
// Should not have any errors in the diagnostics-compare file.
24+
// NEGATIVE-NOT: diagnostics-compare.json:{{.*}}: error:

0 commit comments

Comments
 (0)