Skip to content

Commit c3182d1

Browse files
committed
[gardening] Replace else-if with early returns and sink computation of ownership in the SILVerifier.
Noticed this while doing other work. Just chopping it off to ease review on the larger patch.
1 parent 30a8e15 commit c3182d1

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

lib/SIL/SILVerifier.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4031,8 +4031,6 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
40314031
auto mappedTy = F.mapTypeIntoContext(ty);
40324032
SILArgument *bbarg = *argI;
40334033
++argI;
4034-
auto ownershipkind = ValueOwnershipKind(
4035-
M, mappedTy, fnConv.getSILArgumentConvention(bbarg->getIndex()));
40364034
if (bbarg->getType() != mappedTy) {
40374035
llvm::errs() << what << " type mismatch!\n";
40384036
llvm::errs() << " argument: "; bbarg->dump();
@@ -4045,6 +4043,9 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
40454043
return;
40464044
}
40474045

4046+
auto ownershipkind = ValueOwnershipKind(
4047+
M, mappedTy, fnConv.getSILArgumentConvention(bbarg->getIndex()));
4048+
40484049
if (bbarg->getOwnershipKind() != ownershipkind) {
40494050
llvm::errs() << what << " ownership kind mismatch!\n";
40504051
llvm::errs() << " argument: " << bbarg->getOwnershipKind() << '\n';

lib/SILOptimizer/Utils/Local.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2887,7 +2887,9 @@ swift::analyzeStaticInitializer(SILValue V,
28872887
return false;
28882888
}
28892889
return true;
2890-
} else if (auto *TI = dyn_cast<TupleInst>(V)) {
2890+
}
2891+
2892+
if (auto *TI = dyn_cast<TupleInst>(V)) {
28912893
// If it is not a tuple which is a simple type, bail.
28922894
if (!isSimpleType(TI->getType(), TI->getModule()))
28932895
return false;
@@ -2898,7 +2900,9 @@ swift::analyzeStaticInitializer(SILValue V,
28982900
return false;
28992901
}
29002902
return true;
2901-
} else if (auto *bi = dyn_cast<BuiltinInst>(V)) {
2903+
}
2904+
2905+
if (auto *bi = dyn_cast<BuiltinInst>(V)) {
29022906
switch (bi->getBuiltinInfo().ID) {
29032907
case BuiltinValueKind::FPTrunc:
29042908
if (auto *LI = dyn_cast<LiteralInst>(bi->getArguments()[0])) {
@@ -2908,13 +2912,15 @@ swift::analyzeStaticInitializer(SILValue V,
29082912
default:
29092913
return false;
29102914
}
2911-
} else if (isa<IntegerLiteralInst>(V)
2912-
|| isa<FloatLiteralInst>(V)
2913-
|| isa<StringLiteralInst>(V)) {
2915+
}
2916+
2917+
if (isa<IntegerLiteralInst>(V)
2918+
|| isa<FloatLiteralInst>(V)
2919+
|| isa<StringLiteralInst>(V)) {
29142920
return true;
2915-
} else {
2916-
return false;
29172921
}
2922+
2923+
return false;
29182924
}
29192925

29202926
/// Replace load sequence which may contain

0 commit comments

Comments
 (0)