Skip to content

Commit 4d2fe96

Browse files
committed
SIL linker: delay function verification to end of linking
The SIL linker de-serializes functions. Immediately after de-serialization some `[serialized]` flags of referenced functions may not be set correctly, yet. This is fixed by the linker. But it also means that the SIL is only valid after the linker has finished processing all functions. Fixes a SIL verifier error.
1 parent 4071659 commit 4d2fe96

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

lib/SIL/IR/Linker.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void SILLinkerVisitor::deserializeAndPushToWorklist(SILFunction *F) {
9191
"the de-serializer did set the wrong serialized flag");
9292

9393
F->setBare(IsBare);
94-
F->verify();
94+
toVerify.push_back(F);
9595
Worklist.push_back(F);
9696
Changed = true;
9797
++NumFuncLinked;
@@ -463,4 +463,9 @@ void SILLinkerVisitor::process() {
463463
}
464464
}
465465
}
466+
467+
while (!toVerify.empty()) {
468+
auto *fn = toVerify.pop_back_val();
469+
fn->verify();
470+
}
466471
}

lib/SIL/IR/Linker.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ class SILLinkerVisitor : public SILInstructionVisitor<SILLinkerVisitor, void> {
8383
/// Worklist of SILFunctions we are processing.
8484
llvm::SmallVector<SILFunction *, 128> Worklist;
8585

86+
llvm::SmallVector<SILFunction *, 32> toVerify;
87+
8688
/// The current linking mode.
8789
LinkingMode Mode;
8890

test/embedded/fragile-reference.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %target-swift-frontend -target armv7-apple-none-macho -module-name main -parse-as-library -Xcc -D__MACH__ -emit-ir %s -enable-experimental-feature Embedded | %FileCheck %s
2+
// RUN: %target-swift-frontend -target arm64-apple-none-macho -module-name main -parse-as-library -Xcc -D__MACH__ -Xcc -D__arm64__ -Xcc -D__APPLE__ -emit-ir %s -enable-experimental-feature Embedded | %FileCheck %s
3+
// REQUIRES: swift_in_compiler
4+
// REQUIRES: OS=macosx || OS=linux-gnu
5+
@main
6+
public struct Application {
7+
public static func main() {
8+
var x: UInt64 = 0
9+
x <<= 8
10+
}
11+
}
12+
13+
enum MyEnum: UInt8 {
14+
case a = 0
15+
}
16+
17+
// CHECK: define {{.*}}@main(
18+

0 commit comments

Comments
 (0)