parent
87ffff96d2
commit
af1e941872
3 changed files with 22 additions and 8 deletions
|
|
@ -138,6 +138,9 @@ proc mapType(typ: PType): TCTypeKind =
|
||||||
var base = skipTypes(typ.lastSon, typedescInst)
|
var base = skipTypes(typ.lastSon, typedescInst)
|
||||||
case base.kind
|
case base.kind
|
||||||
of tyOpenArray, tyArrayConstr, tyArray, tyVarargs: result = ctPtrToArray
|
of tyOpenArray, tyArrayConstr, tyArray, tyVarargs: result = ctPtrToArray
|
||||||
|
of tySet:
|
||||||
|
if mapSetType(base) == ctArray: result = ctPtrToArray
|
||||||
|
else: result = ctPtr
|
||||||
else: result = ctPtr
|
else: result = ctPtr
|
||||||
of tyPointer: result = ctPtr
|
of tyPointer: result = ctPtr
|
||||||
of tySequence: result = ctNimSeq
|
of tySequence: result = ctNimSeq
|
||||||
|
|
@ -149,8 +152,9 @@ proc mapType(typ: PType): TCTypeKind =
|
||||||
else: internalError("mapType")
|
else: internalError("mapType")
|
||||||
|
|
||||||
proc mapReturnType(typ: PType): TCTypeKind =
|
proc mapReturnType(typ: PType): TCTypeKind =
|
||||||
if skipTypes(typ, typedescInst).kind == tyArray: result = ctPtr
|
#if skipTypes(typ, typedescInst).kind == tyArray: result = ctPtr
|
||||||
else: result = mapType(typ)
|
#else:
|
||||||
|
result = mapType(typ)
|
||||||
|
|
||||||
proc isImportedType(t: PType): bool =
|
proc isImportedType(t: PType): bool =
|
||||||
result = t.sym != nil and sfImportc in t.sym.flags
|
result = t.sym != nil and sfImportc in t.sym.flags
|
||||||
|
|
@ -224,7 +228,7 @@ proc ccgIntroducedPtr(s: PSym): bool =
|
||||||
proc fillResult(param: PSym) =
|
proc fillResult(param: PSym) =
|
||||||
fillLoc(param.loc, locParam, param.typ, ~"Result",
|
fillLoc(param.loc, locParam, param.typ, ~"Result",
|
||||||
OnStack)
|
OnStack)
|
||||||
if (mapReturnType(param.typ) != ctArray) and isInvalidReturnType(param.typ):
|
if mapReturnType(param.typ) != ctArray and isInvalidReturnType(param.typ):
|
||||||
incl(param.loc.flags, lfIndirect)
|
incl(param.loc.flags, lfIndirect)
|
||||||
param.loc.s = OnUnknown
|
param.loc.s = OnUnknown
|
||||||
|
|
||||||
|
|
@ -306,7 +310,7 @@ proc getTypeDescWeak(m: BModule; t: PType; check: var IntSet): Rope =
|
||||||
result = getTypeDescAux(m, t, check)
|
result = getTypeDescAux(m, t, check)
|
||||||
|
|
||||||
proc paramStorageLoc(param: PSym): TStorageLoc =
|
proc paramStorageLoc(param: PSym): TStorageLoc =
|
||||||
if param.typ.skipTypes({tyVar, tyTypeDesc}).kind notin {tyArray, tyOpenArray}:
|
if param.typ.skipTypes({tyVar, tyTypeDesc}).kind notin {tyArray, tyOpenArray, tyVarargs, tyArrayConstr}:
|
||||||
result = OnStack
|
result = OnStack
|
||||||
else:
|
else:
|
||||||
result = OnUnknown
|
result = OnUnknown
|
||||||
|
|
@ -315,7 +319,7 @@ proc genProcParams(m: BModule, t: PType, rettype, params: var Rope,
|
||||||
check: var IntSet, declareEnvironment=true;
|
check: var IntSet, declareEnvironment=true;
|
||||||
weakDep=false) =
|
weakDep=false) =
|
||||||
params = nil
|
params = nil
|
||||||
if (t.sons[0] == nil) or isInvalidReturnType(t.sons[0]):
|
if t.sons[0] == nil or isInvalidReturnType(t.sons[0]):
|
||||||
rettype = ~"void"
|
rettype = ~"void"
|
||||||
else:
|
else:
|
||||||
rettype = getTypeDescAux(m, t.sons[0], check)
|
rettype = getTypeDescAux(m, t.sons[0], check)
|
||||||
|
|
@ -348,10 +352,10 @@ proc genProcParams(m: BModule, t: PType, rettype, params: var Rope,
|
||||||
addf(params, ", NI $1Len$2", [param.loc.r, j.rope])
|
addf(params, ", NI $1Len$2", [param.loc.r, j.rope])
|
||||||
inc(j)
|
inc(j)
|
||||||
arr = arr.sons[0]
|
arr = arr.sons[0]
|
||||||
if (t.sons[0] != nil) and isInvalidReturnType(t.sons[0]):
|
if t.sons[0] != nil and isInvalidReturnType(t.sons[0]):
|
||||||
var arr = t.sons[0]
|
var arr = t.sons[0]
|
||||||
if params != nil: add(params, ", ")
|
if params != nil: add(params, ", ")
|
||||||
if (mapReturnType(t.sons[0]) != ctArray):
|
if mapReturnType(t.sons[0]) != ctArray:
|
||||||
add(params, getTypeDescWeak(m, arr, check))
|
add(params, getTypeDescWeak(m, arr, check))
|
||||||
add(params, "*")
|
add(params, "*")
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -668,7 +668,7 @@ proc genProcAux(m: BModule, prc: PSym) =
|
||||||
fillResult(res)
|
fillResult(res)
|
||||||
assignParam(p, res)
|
assignParam(p, res)
|
||||||
if skipTypes(res.typ, abstractInst).kind == tyArray:
|
if skipTypes(res.typ, abstractInst).kind == tyArray:
|
||||||
incl(res.loc.flags, lfIndirect)
|
#incl(res.loc.flags, lfIndirect)
|
||||||
res.loc.s = OnUnknown
|
res.loc.s = OnUnknown
|
||||||
|
|
||||||
for i in countup(1, sonsLen(prc.typ.n) - 1):
|
for i in countup(1, sonsLen(prc.typ.n) - 1):
|
||||||
|
|
|
||||||
10
tests/cpp/treturn_array.nim
Normal file
10
tests/cpp/treturn_array.nim
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
|
||||||
|
# bug #2259
|
||||||
|
type Mat4f* = array[0..15, float]
|
||||||
|
|
||||||
|
proc get_rot_mat*(): Mat4f = discard
|
||||||
|
var mat: Mat4f = get_rot_mat()
|
||||||
|
|
||||||
|
# bug #1389
|
||||||
|
proc calcSizes(): array[2, int] = discard
|
||||||
|
let sizes: array[2, int] = calcSizes()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue