Skip to content

Commit d4ebd5d

Browse files
committed
[NFC] Avoid violating same-filename rule in tests
…and modify resolveFileIDConflicts() to diagnose any such violations instead of asserting. Swift does not allow any two files in the same module to have the same filename, even if they are in different directories. However, this is enforced in the driver, so tests that invoke the frontend directly can violate it. Turns out that a couple of those snuck into the test suite at various points. This commit updates those tests. It also causes the frontend to diagnose the duplicate filename error just as the driver would have, which should help us understand what happened more easily if this crops up again in the future. NFC, since invoking the frontend directly is unsupported.
1 parent 7f91145 commit d4ebd5d

File tree

7 files changed

+19
-11
lines changed

7 files changed

+19
-11
lines changed

include/swift/AST/DiagnosticsCommon.def

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@ WARNING(pound_source_location_creates_pound_file_conflicts,none,
126126
NOTE(fixit_correct_source_location_file,none,
127127
"change file in '#sourceLocation' to '%0'", (StringRef))
128128

129+
// Usually, but not always, emitted from the driver
130+
ERROR(error_two_files_same_name,none,
131+
"filename \"%0\" used twice: '%1' and '%2'",
132+
(StringRef, StringRef, StringRef))
133+
NOTE(note_explain_two_files_same_name,none,
134+
"filenames are used to distinguish private declarations with the same "
135+
"name", ())
136+
129137
//------------------------------------------------------------------------------
130138
// MARK: Circular reference diagnostics
131139
//------------------------------------------------------------------------------

include/swift/AST/DiagnosticsDriver.def

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,6 @@ WARNING(warn_arclite_not_found_when_link_objc_runtime,none,
104104
"unable to find Objective-C runtime support library 'arclite'; "
105105
"pass '-no-link-objc-runtime' to silence this warning", ())
106106

107-
ERROR(error_two_files_same_name,none,
108-
"filename \"%0\" used twice: '%1' and '%2'",
109-
(StringRef, StringRef, StringRef))
110-
NOTE(note_explain_two_files_same_name,none,
111-
"filenames are used to distinguish private declarations with the same "
112-
"name", ())
113-
114107
WARNING(warn_cannot_stat_input,none,
115108
"unable to determine when '%0' was last modified: %1",
116109
(StringRef, StringRef))

lib/AST/Module.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2190,7 +2190,14 @@ resolveFileIDConflicts(const ModuleDecl *module, StringRef fileString,
21902190

21912191
// Don't diagnose #sourceLocations that match the physical file.
21922192
if (pathPair.second.physicalFileLoc.isValid()) {
2193-
assert(isWinner && "physical files should always win; duplicate name?");
2193+
if (!isWinner) {
2194+
// The driver is responsible for diagnosing this, but naughty people who
2195+
// have directly invoked the frontend could make it happen here instead.
2196+
StringRef filename = llvm::sys::path::filename(winner);
2197+
diags.diagnose(SourceLoc(), diag::error_two_files_same_name,
2198+
filename, winner, pathPair.first());
2199+
diags.diagnose(SourceLoc(), diag::note_explain_two_files_same_name);
2200+
}
21942201
continue;
21952202
}
21962203

test/SILOptimizer/specialize_inherited_multifile.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
// RUN: %target-swift-frontend -module-name specialize_inherited_multifile -primary-file %s %S/Inputs/specialize_inherited_multifile.swift -O -emit-sil -sil-verify-all | %FileCheck %s
2+
// RUN: %target-swift-frontend -module-name specialize_inherited_multifile -primary-file %s %S/Inputs/specialize_inherited_multifile_other.swift -O -emit-sil -sil-verify-all | %FileCheck %s
33

44
@_optimize(none) func takesBase<T : Base>(t: T) {}
55

test/Serialization/multi-file-type-eraser.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// REQUIRES: asserts
22
// RUN: %empty-directory(%t)
3-
// RUN: %target-swift-frontend -emit-module -module-name Multi -o %t/multi-file.swiftmodule -primary-file %s %S/Inputs/multi-file-type-eraser.swift
4-
// RUN: %target-swift-frontend -emit-module -module-name Multi -o %t/multi-file-2.swiftmodule %s -primary-file %S/Inputs/multi-file-type-eraser.swift
3+
// RUN: %target-swift-frontend -emit-module -module-name Multi -o %t/multi-file.swiftmodule -primary-file %s %S/Inputs/multi-file-type-eraser-other.swift
4+
// RUN: %target-swift-frontend -emit-module -module-name Multi -o %t/multi-file-2.swiftmodule %s -primary-file %S/Inputs/multi-file-type-eraser-other.swift
55

66
// RUN: %target-swift-frontend -emit-module -module-name Multi %t/multi-file.swiftmodule %t/multi-file-2.swiftmodule -o %t -print-stats 2>&1 | %FileCheck %s
77
// RUN: %target-swift-frontend -emit-module -module-name Multi %t/multi-file-2.swiftmodule %t/multi-file.swiftmodule -o %t -print-stats 2>&1 | %FileCheck %s

0 commit comments

Comments
 (0)