Skip to content

Commit cbb9225

Browse files
committed
[NFC] Check that SILGen doesn’t use ABI-only decls
Adds assertions in various places where properties that can vary between ABI-only decls and their counterparts—particularly function and parameter attributes—are handled in SILGen, ensuring that we don’t accidentally end up processing ABI-only decls there.
1 parent 2612bf0 commit cbb9225

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

lib/SIL/IR/SILDeclRef.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ static LinkageLimit getLinkageLimit(SILDeclRef constant) {
451451
using Kind = SILDeclRef::Kind;
452452

453453
auto *d = constant.getDecl();
454+
ASSERT(ABIRoleInfo(d).providesAPI() && "getLinkageLimit() for ABI decl?");
454455

455456
// Back deployment thunks and fallbacks are emitted into the client.
456457
if (constant.backDeploymentKind != SILDeclRef::BackDeploymentKind::None)
@@ -1267,6 +1268,9 @@ std::string SILDeclRef::mangle(ManglingKind MKind) const {
12671268
if (auto *ACE = getAbstractClosureExpr())
12681269
return mangler.mangleClosureEntity(ACE, SKind);
12691270

1271+
ASSERT(ABIRoleInfo(getDecl()).providesAPI()
1272+
&& "SILDeclRef mangling ABI decl directly?");
1273+
12701274
// As a special case, functions can have manually mangled names.
12711275
// Use the SILGen name only for the original non-thunked, non-curried entry
12721276
// point.

lib/SIL/IR/SILFunctionBuilder.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,9 @@ SILFunction *SILFunctionBuilder::getOrCreateFunction(
377377
if (auto *accessor = dyn_cast<AccessorDecl>(decl)) {
378378
auto *storage = accessor->getStorage();
379379
// Add attributes for e.g. computed properties.
380+
ASSERT(ABIRoleInfo(storage).providesAPI()
381+
&& "addFunctionAttributes() on ABI-only accessor?");
382+
380383
addFunctionAttributes(F, storage->getAttrs(), mod,
381384
getOrCreateDeclaration);
382385

@@ -395,6 +398,8 @@ SILFunction *SILFunctionBuilder::getOrCreateFunction(
395398
F->setInlineStrategy(NoInline);
396399
}
397400
}
401+
ASSERT(ABIRoleInfo(decl).providesAPI()
402+
&& "addFunctionAttributes() on ABI-only decl?");
398403
addFunctionAttributes(F, decl->getAttrs(), mod, getOrCreateDeclaration,
399404
constant);
400405
}

lib/SIL/IR/SILSymbolVisitor.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,9 @@ class SILSymbolVisitorImpl : public ASTVisitor<SILSymbolVisitorImpl> {
491491

492492
addFunction(SILDeclRef(AFD));
493493

494+
ASSERT(ABIRoleInfo(AFD).providesAPI()
495+
&& "SILSymbolVisitorImpl visiting ABI-only decl?");
496+
494497
if (auto dynKind = getDynamicKind(AFD)) {
495498
// Add the global function pointer for a dynamically replaceable function.
496499
Visitor.addDynamicFunction(AFD, *dynKind);

lib/SILGen/SILGen.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,6 +1439,9 @@ void SILGenModule::emitAbstractFuncDecl(AbstractFunctionDecl *AFD) {
14391439
// Emit default arguments and property wrapper initializers.
14401440
emitArgumentGenerators(AFD, AFD->getParameters());
14411441

1442+
ASSERT(ABIRoleInfo(AFD).providesAPI()
1443+
&& "emitAbstractFuncDecl() on ABI-only decl?");
1444+
14421445
// If the declaration is exported as a C function, emit its native-to-foreign
14431446
// thunk too, if it wasn't already forced.
14441447
if (AFD->getAttrs().hasAttribute<CDeclAttr>()) {

0 commit comments

Comments
 (0)