Skip to content

Commit 8201eaa

Browse files
committed
SIL: Change rule regarding shared_external linkage
The existence of a shared_external function in itself is not an error; it just means we deserialized a witness table or vtable but did not need to deserialize a thunk. However, a direct reference to such a function is an error, because we should have deserialized the body in that case. This fixes a crasher, but the SIL crashers are kind of silly because the SIL parser does not try at all not to crash on invalid input.
1 parent 589107a commit 8201eaa

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

lib/SIL/SILVerifier.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,8 +1131,25 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
11311131
"result of function_ref");
11321132
require(!fnType->getExtInfo().hasContext(),
11331133
"function_ref should have a context-free function result");
1134+
1135+
// Note: in SingleFunction mode, we relax some of these checks because
1136+
// we may not have linked everything yet.
1137+
1138+
SILFunction *RefF = FRI->getReferencedFunction();
1139+
1140+
// A direct reference to a shared_external declaration is an error; we
1141+
// should have deserialized a body.
1142+
if (RefF->isExternalDeclaration()) {
1143+
require(SingleFunction ||
1144+
!hasSharedVisibility(RefF->getLinkage()) ||
1145+
RefF->hasForeignBody(),
1146+
"external declarations of SILFunctions with shared visibility is "
1147+
"not allowed");
1148+
}
1149+
1150+
// A direct reference to a non-public or shared but not fragile function
1151+
// from a fragile function is an error.
11341152
if (F.isSerialized()) {
1135-
SILFunction *RefF = FRI->getReferencedFunction();
11361153
require((SingleFunction && RefF->isExternalDeclaration()) ||
11371154
RefF->hasValidLinkageForFragileRef(),
11381155
"function_ref inside fragile function cannot "
@@ -3912,9 +3929,6 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
39123929

39133930
assert(F->isAvailableExternally() &&
39143931
"external declaration of internal SILFunction not allowed");
3915-
assert(!hasSharedVisibility(F->getLinkage()) &&
3916-
"external declarations of SILFunctions with shared visibility is not "
3917-
"allowed");
39183932
// If F is an external declaration, there is nothing further to do,
39193933
// return.
39203934
return;

validation-test/SIL/crashers/005-swift-silfunction-verify.sil

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// RUN: %target-sil-opt %s
2+
sil shared_external@a:$()->()

0 commit comments

Comments
 (0)