@@ -215,12 +215,18 @@ proc isObjLackingTypeField(typ: PType): bool {.inline.} =
215215 result = (typ.kind == tyObject) and ((tfFinal in typ.flags) and
216216 (typ[0 ] == nil ) or isPureObject (typ))
217217
218- proc isInvalidReturnType (conf: ConfigRef ; rettype : PType ): bool =
218+ proc isInvalidReturnType (conf: ConfigRef ; typ : PType , isProc = true ): bool =
219219 # Arrays and sets cannot be returned by a C procedure, because C is
220220 # such a poor programming language.
221221 # We exclude records with refs too. This enhances efficiency and
222222 # 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 ):
224230 result = true
225231 else :
226232 case mapType (conf, rettype, skResult)
@@ -257,11 +263,11 @@ proc addAbiCheck(m: BModule, t: PType, name: Rope) =
257263 # see `testCodegenABICheck` for example error message it generates
258264
259265
260- proc fillResult (conf: ConfigRef ; param: PNode ) =
266+ proc fillResult (conf: ConfigRef ; param: PNode , proctype: PType ) =
261267 fillLoc (param.sym.loc, locParam, param, ~ " Result" ,
262268 OnStack )
263269 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 ):
265271 incl (param.sym.loc.flags, lfIndirect)
266272 param.sym.loc.storage = OnUnknown
267273
@@ -426,7 +432,7 @@ proc genProcParams(m: BModule, t: PType, rettype, params: var Rope,
426432 check: var IntSet , declareEnvironment= true ;
427433 weakDep= false ) =
428434 params = nil
429- if t[0 ] == nil or isInvalidReturnType (m.config, t[ 0 ] ):
435+ if t[0 ] == nil or isInvalidReturnType (m.config, t):
430436 rettype = ~ " void"
431437 else :
432438 rettype = getTypeDescAux (m, t[0 ], check, skResult)
@@ -461,7 +467,7 @@ proc genProcParams(m: BModule, t: PType, rettype, params: var Rope,
461467 params.addf (" , NI $1Len_$2" , [param.loc.r, j.rope])
462468 inc (j)
463469 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):
465471 var arr = t[0 ]
466472 if params != nil : params.add (" , " )
467473 if mapReturnType (m.config, t[0 ]) != ctArray:
0 commit comments