@@ -215,12 +215,18 @@ proc isObjLackingTypeField(typ: PType): bool {.inline.} =
215
215
result = (typ.kind == tyObject) and ((tfFinal in typ.flags) and
216
216
(typ[0 ] == nil ) or isPureObject (typ))
217
217
218
- proc isInvalidReturnType (conf: ConfigRef ; rettype : PType ): bool =
218
+ proc isInvalidReturnType (conf: ConfigRef ; typ : PType , isProc = true ): bool =
219
219
# Arrays and sets cannot be returned by a C procedure, because C is
220
220
# such a poor programming language.
221
221
# We exclude records with refs too. This enhances efficiency and
222
222
# is necessary for proper code generation of assignments.
223
- if rettype == nil or (tfByCopy notin rettype.flags and getSize (conf, rettype) > conf.target.floatSize* 3 ):
223
+ var rettype = typ
224
+ var isAllowedCall = true
225
+ if isProc:
226
+ rettype = rettype[0 ]
227
+ isAllowedCall = typ.callConv in {ccClosure, ccInline, ccNimCall}
228
+ if rettype == nil or (isAllowedCall and
229
+ getSize (conf, rettype) > conf.target.floatSize* 3 ):
224
230
result = true
225
231
else :
226
232
case mapType (conf, rettype, skResult)
@@ -257,11 +263,11 @@ proc addAbiCheck(m: BModule, t: PType, name: Rope) =
257
263
# see `testCodegenABICheck` for example error message it generates
258
264
259
265
260
- proc fillResult (conf: ConfigRef ; param: PNode ) =
266
+ proc fillResult (conf: ConfigRef ; param: PNode , proctype: PType ) =
261
267
fillLoc (param.sym.loc, locParam, param, ~ " Result" ,
262
268
OnStack )
263
269
let t = param.sym.typ
264
- if mapReturnType (conf, t) != ctArray and isInvalidReturnType (conf, t ):
270
+ if mapReturnType (conf, t) != ctArray and isInvalidReturnType (conf, proctype ):
265
271
incl (param.sym.loc.flags, lfIndirect)
266
272
param.sym.loc.storage = OnUnknown
267
273
@@ -426,7 +432,7 @@ proc genProcParams(m: BModule, t: PType, rettype, params: var Rope,
426
432
check: var IntSet , declareEnvironment= true ;
427
433
weakDep= false ) =
428
434
params = nil
429
- if t[0 ] == nil or isInvalidReturnType (m.config, t[ 0 ] ):
435
+ if t[0 ] == nil or isInvalidReturnType (m.config, t):
430
436
rettype = ~ " void"
431
437
else :
432
438
rettype = getTypeDescAux (m, t[0 ], check, skResult)
@@ -461,7 +467,7 @@ proc genProcParams(m: BModule, t: PType, rettype, params: var Rope,
461
467
params.addf (" , NI $1Len_$2" , [param.loc.r, j.rope])
462
468
inc (j)
463
469
arr = arr[0 ].skipTypes ({tySink})
464
- if t[0 ] != nil and isInvalidReturnType (m.config, t[ 0 ] ):
470
+ if t[0 ] != nil and isInvalidReturnType (m.config, t):
465
471
var arr = t[0 ]
466
472
if params != nil : params.add (" , " )
467
473
if mapReturnType (m.config, t[0 ]) != ctArray:
0 commit comments