Skip to content

Commit fa46f71

Browse files
committed
sprinkle some llvm_unreachable for MSVC (NFC)
MSVC does not realize that the switch is exhaustive and requires that the path is explicitly marked as unreachable. This silences the C4715 warning ("not all control paths return a value").
1 parent f883ca6 commit fa46f71

File tree

18 files changed

+24
-0
lines changed

18 files changed

+24
-0
lines changed

include/swift/SIL/ApplySite.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,7 @@ class FullApplySite : public ApplySite {
519519
case FullApplySiteKind::BeginApplyInst:
520520
return cast<BeginApplyInst>(getInstruction())->getInoutArguments();
521521
}
522+
llvm_unreachable("invalid apply kind");
522523
}
523524

524525
/// Returns true if \p op is the callee operand of this apply site

include/swift/SIL/SILDifferentiabilityWitness.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ class SILDifferentiabilityWitness
113113
case AutoDiffDerivativeFunctionKind::VJP:
114114
return VJP;
115115
}
116+
llvm_unreachable("invalid derivative type");
116117
}
117118
void setJVP(SILFunction *jvp) { JVP = jvp; }
118119
void setVJP(SILFunction *vjp) { VJP = vjp; }

include/swift/SIL/SILInstruction.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8107,6 +8107,7 @@ class DifferentiableFunctionInst final
81078107
case AutoDiffDerivativeFunctionKind::VJP:
81088108
return getVJPFunction();
81098109
}
8110+
llvm_unreachable("invalid derivative kind");
81108111
}
81118112
};
81128113

include/swift/SILOptimizer/Utils/Differentiation/ADContext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ ADContext::emitNondifferentiabilityError(SourceLoc loc,
374374
return diagnose(loc, diag::autodiff_when_differentiating_function_call);
375375
}
376376
}
377+
llvm_unreachable("invalid invoker");
377378
}
378379

379380
} // end namespace autodiff

lib/FrontendTool/FrontendTool.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,6 +1462,7 @@ static bool validateTBDIfNeeded(const CompilerInvocation &Invocation,
14621462
case FrontendOptions::TBDValidationMode::All:
14631463
return true;
14641464
}
1465+
llvm_unreachable("invalid mode");
14651466
}();
14661467

14671468
TBDGenOptions Opts = Invocation.getTBDGenOptions();

lib/IRGen/GenDiffFunc.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class DifferentiableFuncFieldInfo final
6565
case NormalDifferentiableFunctionTypeComponent::VJP:
6666
return "vjp";
6767
}
68+
llvm_unreachable("invalid component type");
6869
}
6970

7071
SILType getType(IRGenModule &IGM, SILType t) const {
@@ -209,6 +210,7 @@ class LinearFuncFieldInfo final : public RecordField<LinearFuncFieldInfo> {
209210
case LinearDifferentiableFunctionTypeComponent::Transpose:
210211
return "transpose";
211212
}
213+
llvm_unreachable("invalid component type");
212214
}
213215

214216
SILType getType(IRGenModule &IGM, SILType t) const {
@@ -223,6 +225,7 @@ class LinearFuncFieldInfo final : public RecordField<LinearFuncFieldInfo> {
223225
LookUpConformanceInModule(IGM.getSwiftModule()));
224226
return SILType::getPrimitiveObjectType(transposeTy);
225227
}
228+
llvm_unreachable("invalid component type");
226229
}
227230
};
228231

@@ -321,6 +324,7 @@ class LinearFuncTypeBuilder
321324
LookUpConformanceInModule(IGM.getSwiftModule()));
322325
return SILType::getPrimitiveObjectType(transposeTy);
323326
}
327+
llvm_unreachable("invalid component type");
324328
}
325329

326330
StructLayout performLayout(ArrayRef<const TypeInfo *> fieldTypes) {

lib/IRGen/GenPointerAuth.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,7 @@ PointerAuthEntity::getTypeDiscriminator(IRGenModule &IGM) const {
584584
llvm_unreachable("not type discriminated");
585585
}
586586
}
587+
llvm_unreachable("invalid representation");
587588
};
588589

589590
auto getCoroutineYieldTypesDiscriminator = [&](CanSILFunctionType fnType) {

lib/IRGen/Linking.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,7 @@ bool LinkEntity::isContextDescriptor() const {
738738
case Kind::DifferentiabilityWitness:
739739
return false;
740740
}
741+
llvm_unreachable("invalid descriptor");
741742
}
742743

743744
llvm::Type *LinkEntity::getDefaultDeclarationType(IRGenModule &IGM) const {
@@ -1088,6 +1089,7 @@ DeclContext *LinkEntity::getDeclContextForEmission() const {
10881089
case Kind::DifferentiabilityWitness:
10891090
return nullptr;
10901091
}
1092+
llvm_unreachable("invalid decl kind");
10911093
}
10921094

10931095
bool LinkEntity::isAlwaysSharedLinkage() const {

lib/SIL/IR/AbstractionPattern.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,7 @@ const {
927927

928928
return AbstractionPattern(getGenericSignature(), memberTy);
929929
}
930+
llvm_unreachable("invalid abstraction pattern kind");
930931
}
931932

932933
AbstractionPattern AbstractionPattern::getAutoDiffDerivativeFunctionType(

lib/SIL/IR/SILInstructions.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,7 @@ getExtracteeType(
751751
LookUpConformanceInModule(module.getSwiftModule()));
752752
return SILType::getPrimitiveObjectType(transposeFnTy);
753753
}
754+
llvm_unreachable("invalid extractee");
754755
}
755756

756757
LinearFunctionExtractInst::LinearFunctionExtractInst(

0 commit comments

Comments
 (0)