Skip to content

Commit 8a0e512

Browse files
committed
[frontend] Fix TBD validation almost always done for modules
The logic to do or not the validation of TBD against IR was incorrect. In the case of modules, the comment described what was supposed to happen (skipping the validation if the module had SIB files), but the code was returning if the module had or not SIB files, which would have returned true for any module without SIB files without checking if the compiler was build in a debug configuration or not. This was only visible in the case of non-debug builds, and it only appeared for us in a convoluted mix of optimized builds with -enable-testing on some modules.
1 parent 2755f74 commit 8a0e512

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

lib/FrontendTool/FrontendTool.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1390,10 +1390,14 @@ static bool validateTBDIfNeeded(const CompilerInvocation &Invocation,
13901390
// may have serialized hand-crafted SIL definitions that are invisible to
13911391
// TBDGen as it is an AST-only traversal.
13921392
if (auto *mod = MSF.dyn_cast<ModuleDecl *>()) {
1393-
return llvm::none_of(mod->getFiles(), [](const FileUnit *File) -> bool {
1393+
bool hasSIB = llvm::any_of(mod->getFiles(), [](const FileUnit *File) -> bool {
13941394
auto SASTF = dyn_cast<SerializedASTFile>(File);
13951395
return SASTF && SASTF->isSIB();
13961396
});
1397+
1398+
if (hasSIB) {
1399+
return false;
1400+
}
13971401
}
13981402

13991403
// "Default" mode's behavior varies if using a debug compiler.

test/TBD/sib-module.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: %target-swiftc_driver -emit-sib -module-name mysibmodule %s -o - | %target-swiftc_driver -emit-module -module-name mysibmodule -o %t/mysibmodule.swiftmodule -
4+
5+
/// Since -validate-tbd-against-ir=default, TBD validation is not done since the module has a SIB file
6+
// RUN: %target-swift-frontend -emit-sil %t/mysibmodule.swiftmodule | %FileCheck %s
7+
8+
// RUN: %target-swiftc_driver -emit-module -module-name mynonsibmodule -o %t/mynonsibmodule.swiftmodule %s
9+
10+
/// Since -validate-tbd-against-ir=default, TBD validation is done or not depending on the build configuration
11+
// RUN: %target-swift-frontend -emit-sil %t/mynonsibmodule.swiftmodule | %FileCheck %s
12+
13+
public class MyClass {
14+
var x : Int
15+
16+
public init(input : Int) {
17+
x = 2 * input
18+
}
19+
20+
public func do_something(input : Int) -> Int {
21+
return x * input
22+
}
23+
}
24+
25+
// CHECK: class MyClass

0 commit comments

Comments
 (0)