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(

lib/SIL/IR/SILProfiler.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ static Stmt *getProfilerStmtForCase(CaseStmt *caseStmt) {
121121
case CaseParentKind::DoCatch:
122122
return caseStmt->getBody();
123123
}
124+
llvm_unreachable("invalid parent kind");
124125
}
125126

126127
/// Check that the input AST has at least been type-checked.

lib/SILOptimizer/Analysis/MemoryBehavior.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ class MemoryBehaviorVisitor
165165

166166
return MemBehavior::MayWrite;
167167
}
168+
llvm_unreachable("invalid access kind");
168169
}
169170

170171
MemBehavior visitEndAccessInst(EndAccessInst *endAccess) {

lib/SILOptimizer/SILCombiner/SILCombinerMiscVisitors.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,7 @@ static SILValue createValueFromAddr(SILValue addr, SILBuilder *builder,
10271027
// Just return anything not null for the dry-run.
10281028
return elems[0];
10291029
}
1030+
llvm_unreachable("invalid kind");
10301031
}
10311032

10321033
/// Simplify the following two frontend patterns:

lib/SILOptimizer/Utils/ConstantFolding.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,7 @@ IEEESemantics getFPSemantics(BuiltinFloatType *fpType) {
10081008
case BuiltinFloatType::PPC128:
10091009
llvm_unreachable("ppc128 is not supported");
10101010
}
1011+
llvm_unreachable("invalid floating point kind");
10111012
}
10121013

10131014
/// This function, given the exponent and significand of a binary fraction

lib/SILOptimizer/Utils/Differentiation/DifferentiationInvoker.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ SourceLoc DifferentiationInvoker::getLocation() const {
3535
->getLocation()
3636
.getSourceLoc();
3737
}
38+
llvm_unreachable("invalid differentation invoker kind");
3839
}
3940

4041
void DifferentiationInvoker::print(llvm::raw_ostream &os) const {

lib/SILOptimizer/Utils/Differentiation/JVPEmitter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ SILValue JVPEmitter::materializeTangentDirect(AdjointValue val,
221221
case AdjointValueKind::Concrete:
222222
return val.getConcreteValue();
223223
}
224+
llvm_unreachable("invalid value kind");
224225
}
225226

226227
SILValue JVPEmitter::materializeTangent(AdjointValue val, SILLocation loc) {

lib/SILOptimizer/Utils/Differentiation/PullbackEmitter.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,6 +1787,7 @@ SILValue PullbackEmitter::materializeAdjointDirect(AdjointValue val,
17871787
case AdjointValueKind::Concrete:
17881788
return val.getConcreteValue();
17891789
}
1790+
llvm_unreachable("invalid value kind");
17901791
}
17911792

17921793
SILValue PullbackEmitter::materializeAdjoint(AdjointValue val,
@@ -1958,6 +1959,7 @@ AdjointValue PullbackEmitter::accumulateAdjointsDirect(AdjointValue lhs,
19581959
}
19591960
}
19601961
}
1962+
llvm_unreachable("invalid LHS kind");
19611963
}
19621964

19631965
SILValue PullbackEmitter::accumulateDirect(SILValue lhs, SILValue rhs,
@@ -2007,6 +2009,7 @@ SILValue PullbackEmitter::accumulateDirect(SILValue lhs, SILValue rhs,
20072009
return builder.createTuple(loc, adjointTy, adjElements);
20082010
}
20092011
}
2012+
llvm_unreachable("invalid tangent space");
20102013
}
20112014

20122015
void PullbackEmitter::accumulateIndirect(SILValue resultBufAccess,

lib/TBDGen/TBDGen.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ getLinkerPlatformId(OriginallyDefinedInAttr::ActiveVersion Ver) {
259259
case swift::PlatformKind::macCatalystApplicationExtension:
260260
return LinkerPlatformId::macCatalyst;
261261
}
262+
llvm_unreachable("invalid platform kind");
262263
}
263264

264265
static StringRef

0 commit comments

Comments
 (0)