Skip to content

Commit 2847ee9

Browse files
committed
SILGen: Generate valid SIL for no-op #_hasSymbol conditions.
1 parent 73bf294 commit 2847ee9

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/SILGen/SILGenDecl.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1602,7 +1602,15 @@ void SILGenFunction::emitStmtCondition(StmtCondition Cond, JumpDest FalseDest,
16021602

16031603
case StmtConditionElement::CK_HasSymbol: {
16041604
auto info = elt.getHasSymbolInfo();
1605-
assert(!info->isInvalid());
1605+
if (info->isInvalid()) {
1606+
// This condition may have referenced a decl that isn't valid in some
1607+
// way but for developer convenience wasn't treated as an error. Just
1608+
// emit a 'true' condition value.
1609+
SILType i1 = SILType::getBuiltinIntegerType(1, getASTContext());
1610+
booleanTestValue = B.createIntegerLiteral(loc, i1, 1);
1611+
break;
1612+
}
1613+
16061614
auto expr = info->getSymbolExpr();
16071615
auto declRef = info->getReferencedDecl();
16081616
assert(declRef);

test/SILGen/has_symbol.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,3 +263,15 @@ func testMetatypes() {
263263

264264
// --- E.self ---
265265
// CHECK: sil hidden_external @$s17has_symbol_helper1EOTwS : $@convention(thin) () -> Builtin.Int1
266+
267+
// CHECK: sil hidden [ossa] @$s4test0A15NotWeaklyLinkedyyF : $@convention(thin) () -> ()
268+
func testNotWeaklyLinked() {
269+
// `Swift.Int` is not weakly imported so this check is a no-op.
270+
271+
// CHECK: [[RES:%[0-9]+]] = integer_literal $Builtin.Int1, -1
272+
// CHECK: cond_br [[RES]], bb{{[0-9]+}}, bb{{[0-9]+}}
273+
if #_hasSymbol(Swift.Int.self) {}
274+
}
275+
276+
// We should not generate a #_hasSymbol query helper for Swift.Int.
277+
// CHECK-NOT: sSiTwS

0 commit comments

Comments
 (0)