Skip to content

Commit be12788

Browse files
committed
SIL: Fix undefined behavior with method call on nullptr
This happened to work with a null genericEnv before, because we didn't touch `this` when the input type didn't contain any type parameters.
1 parent 35488ed commit be12788

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

lib/SIL/IR/SILFunctionType.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3011,14 +3011,16 @@ CanSILFunctionType swift::buildSILFunctionThunkType(
30113011

30123012
auto substFormalTypeIntoThunkContext =
30133013
[&](CanType t) -> CanType {
3014-
return genericEnv->mapTypeIntoContext(
3014+
return GenericEnvironment::mapTypeIntoContext(
3015+
genericEnv,
30153016
mapLocalArchetypesOutOfContext(t, baseGenericSig, capturedEnvs))
30163017
->getCanonicalType();
30173018
};
30183019
auto substLoweredTypeIntoThunkContext =
30193020
[&](CanSILFunctionType t) -> CanSILFunctionType {
30203021
return cast<SILFunctionType>(
3021-
genericEnv->mapTypeIntoContext(
3022+
GenericEnvironment::mapTypeIntoContext(
3023+
genericEnv,
30223024
mapLocalArchetypesOutOfContext(t, baseGenericSig, capturedEnvs))
30233025
->getCanonicalType());
30243026
};

lib/SILOptimizer/Utils/Generics.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1420,7 +1420,8 @@ class FunctionSignaturePartialSpecializer {
14201420
SubstitutionMap::get(
14211421
SpecializedGenericSig,
14221422
[&](SubstitutableType *type) -> Type {
1423-
return CalleeGenericEnv->mapTypeIntoContext(
1423+
return GenericEnvironment::mapTypeIntoContext(
1424+
CalleeGenericEnv,
14241425
SpecializedGenericSig.getReducedType(type));
14251426
},
14261427
LookUpConformanceInModule());

0 commit comments

Comments
 (0)