@@ -1514,6 +1514,17 @@ void CallEmission::emitToUnmappedExplosion(Explosion &out) {
1514
1514
result = emitObjCRetainAutoreleasedReturnValue (IGF, result);
1515
1515
}
1516
1516
1517
+ auto origFnType = getCallee ().getOrigFunctionType ();
1518
+
1519
+ // Specially handle noreturn c function which would return a 'Never' SIL result
1520
+ // type.
1521
+ if (origFnType->getLanguage () == SILFunctionLanguage::C &&
1522
+ origFnType->isNoReturnFunction ()) {
1523
+ auto clangResultTy = result->getType ();
1524
+ extractScalarResults (IGF, clangResultTy, result, out);
1525
+ return ;
1526
+ }
1527
+
1517
1528
// Get the natural IR type in the body of the function that makes
1518
1529
// the call. This may be different than the IR type returned by the
1519
1530
// call itself due to ABI type coercion.
@@ -1527,7 +1538,6 @@ void CallEmission::emitToUnmappedExplosion(Explosion &out) {
1527
1538
// for methods that have covariant ABI-compatible overrides.
1528
1539
auto expectedNativeResultType = nativeSchema.getExpandedType (IGF.IGM );
1529
1540
if (result->getType () != expectedNativeResultType) {
1530
- auto origFnType = getCallee ().getOrigFunctionType ();
1531
1541
assert (origFnType->getLanguage () == SILFunctionLanguage::C ||
1532
1542
origFnType->getRepresentation () == SILFunctionTypeRepresentation::Method);
1533
1543
result =
@@ -1783,9 +1793,23 @@ void CallEmission::emitToExplosion(Explosion &out, bool isOutlined) {
1783
1793
auto &substResultTI =
1784
1794
cast<LoadableTypeInfo>(IGF.getTypeInfo (substResultType));
1785
1795
1796
+ auto origFnType = getCallee ().getOrigFunctionType ();
1797
+ auto isNoReturnCFunction =
1798
+ origFnType->getLanguage () == SILFunctionLanguage::C &&
1799
+ origFnType->isNoReturnFunction ();
1800
+
1786
1801
// If the call is naturally to memory, emit it that way and then
1787
1802
// explode that temporary.
1788
1803
if (LastArgWritten == 1 ) {
1804
+ if (isNoReturnCFunction) {
1805
+ auto fnType = getCallee ().getFunctionPointer ().getFunctionType ();
1806
+ assert (fnType->getNumParams () > 0 );
1807
+ auto resultTy = fnType->getParamType (0 )->getPointerElementType ();
1808
+ auto temp = IGF.createAlloca (resultTy, Alignment (0 ), " indirect.result" );
1809
+ emitToMemory (temp, substResultTI, isOutlined);
1810
+ return ;
1811
+ }
1812
+
1789
1813
StackAddress ctemp = substResultTI.allocateStack (IGF, substResultType,
1790
1814
" call.aggresult" );
1791
1815
Address temp = ctemp.getAddress ();
@@ -1802,6 +1826,13 @@ void CallEmission::emitToExplosion(Explosion &out, bool isOutlined) {
1802
1826
Explosion temp;
1803
1827
emitToUnmappedExplosion (temp);
1804
1828
1829
+ // Specially handle noreturn c function which would return a 'Never' SIL result
1830
+ // type: there is no need to cast the result.
1831
+ if (isNoReturnCFunction) {
1832
+ temp.transferInto (out, temp.size ());
1833
+ return ;
1834
+ }
1835
+
1805
1836
// We might need to bitcast the results.
1806
1837
emitCastToSubstSchema (IGF, temp, substResultTI.getSchema (), out);
1807
1838
}
0 commit comments