Skip to content

Commit 6c68ac2

Browse files
authored
[Serialization] Only diagnose a bad architecture when there are others (swiftlang#20550)
This diagnostic needs to be adapted for swiftinterfaces too, but meanwhile let's not have it get in the way when dealing with a multi-architecture module that has parseable interfaces. MyKit.framework/ Modules/ MyKit.swiftmodule/ x86_64.swiftinterface x86_64.swiftdoc # no x86_64.swiftmodule
1 parent 06b53b2 commit 6c68ac2

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

lib/Serialization/SerializedModuleLoader.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,13 @@ static void addDiagnosticInfoForArchitectureMismatch(ASTContext &ctx,
117117
}
118118
}
119119

120+
if (foundArchs.empty()) {
121+
// Maybe this swiftmodule directory only contains swiftinterfaces, or
122+
// maybe something else is going on. Regardless, we shouldn't emit a
123+
// possibly incorrect diagnostic.
124+
return;
125+
}
126+
120127
ctx.Diags.diagnose(sourceLocation, diag::sema_no_import_arch, moduleName,
121128
archName, foundArchs);
122129
}

test/Serialization/load-invalid-arch.swift

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,29 @@
55
// RUN: touch %t/new_module.swiftmodule/ppc65.swiftmodule
66
// RUN: touch %t/new_module.swiftmodule/i387.swiftdoc
77
// RUN: touch %t/new_module.swiftmodule/ppc65.swiftdoc
8-
// RUN: not %target-swift-frontend %s -typecheck -I %t -show-diagnostics-after-fatal 2>&1 | %FileCheck %s -DTARGET_ARCHITECTURE=$(echo %target-swiftmodule-name | cut -d. -f1)
8+
// RUN: not %target-swift-frontend %s -typecheck -I %t -show-diagnostics-after-fatal 2>&1 | %FileCheck %s -check-prefix=CHECK -check-prefix CHECK-ALL -DTARGET_ARCHITECTURE=$(echo %target-swiftmodule-name | cut -d. -f1)
99

1010
// RUN: %empty-directory(%t)
1111
// RUN: mkdir -p %t/new_module.framework/Modules/new_module.swiftmodule/
1212
// RUN: touch %t/new_module.framework/Modules/new_module.swiftmodule/i387.swiftmodule
1313
// RUN: touch %t/new_module.framework/Modules/new_module.swiftmodule/ppc65.swiftmodule
14-
// RUN: not %target-swift-frontend %s -F %t -typecheck -show-diagnostics-after-fatal 2>&1 | %FileCheck %s -DTARGET_ARCHITECTURE=$(echo %target-swiftmodule-name | cut -d. -f1)
14+
// RUN: not %target-swift-frontend %s -F %t -typecheck -show-diagnostics-after-fatal 2>&1 | %FileCheck %s -check-prefix=CHECK -check-prefix CHECK-ALL -DTARGET_ARCHITECTURE=$(echo %target-swiftmodule-name | cut -d. -f1)
1515

16-
//CHECK: {{.*}} error: could not find module 'new_module' for architecture '[[TARGET_ARCHITECTURE]]'; found: {{ppc65, i387|i387, ppc65}}
17-
//CHECK-NEXT: import new_module
18-
//CHECK-NEXT: ^
19-
//CHECK: error: no such module 'new_module'
20-
//CHECK-NEXT: import new_module
21-
//CHECK-NEXT: ^
22-
//CHECK: error: use of unresolved identifier 'new_module'
23-
//CHECK-NEXT: new_module.foo()
24-
//CHECK-NEXT: ^~~~~~~~~~
16+
// RUN: %empty-directory(%t)
17+
// RUN: mkdir %t/new_module.swiftmodule
18+
// RUN: not %target-swift-frontend %s -typecheck -I %t -show-diagnostics-after-fatal 2>&1 | %FileCheck %s -check-prefix=CHECK-EMPTY -check-prefix CHECK-ALL -DTARGET_ARCHITECTURE=$(echo %target-swiftmodule-name | cut -d. -f1)
19+
20+
// CHECK-ALL-NOT: error:
21+
// CHECK: {{.*}} error: could not find module 'new_module' for architecture '[[TARGET_ARCHITECTURE]]'; found: {{ppc65, i387|i387, ppc65}}
22+
// CHECK-NEXT: import new_module
23+
// CHECK-NEXT: ^
24+
// CHECK-ALL: error: no such module 'new_module'
25+
// CHECK-ALL-NEXT: import new_module
26+
// CHECK-ALL-NEXT: ^
27+
// CHECK-ALL: error: use of unresolved identifier 'new_module'
28+
// CHECK-ALL-NEXT: new_module.foo()
29+
// CHECK-ALL-NEXT: ^~~~~~~~~~
30+
// CHECK-ALL-NOT: error:
2531

2632
import new_module
2733

0 commit comments

Comments
 (0)