parent
1293a8bca5
commit
8be177627a
2 changed files with 18 additions and 2 deletions
|
|
@ -658,7 +658,8 @@ proc unaryArith(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
|
||||||
getSimpleTypeDesc(p.module, e.typ)]))
|
getSimpleTypeDesc(p.module, e.typ)]))
|
||||||
|
|
||||||
proc genDeref(p: BProc, e: PNode, d: var TLoc; enforceDeref=false) =
|
proc genDeref(p: BProc, e: PNode, d: var TLoc; enforceDeref=false) =
|
||||||
if mapType(e.sons[0].typ) in {ctArray, ctPtrToArray} and not enforceDeref:
|
let mt = mapType(e.sons[0].typ)
|
||||||
|
if mt in {ctArray, ctPtrToArray} and not enforceDeref:
|
||||||
# XXX the amount of hacks for C's arrays is incredible, maybe we should
|
# XXX the amount of hacks for C's arrays is incredible, maybe we should
|
||||||
# simply wrap them in a struct? --> Losing auto vectorization then?
|
# simply wrap them in a struct? --> Losing auto vectorization then?
|
||||||
#if e[0].kind != nkBracketExpr:
|
#if e[0].kind != nkBracketExpr:
|
||||||
|
|
@ -675,7 +676,15 @@ proc genDeref(p: BProc, e: PNode, d: var TLoc; enforceDeref=false) =
|
||||||
of tyPtr:
|
of tyPtr:
|
||||||
d.s = OnUnknown # BUGFIX!
|
d.s = OnUnknown # BUGFIX!
|
||||||
else: internalError(e.info, "genDeref " & $a.t.kind)
|
else: internalError(e.info, "genDeref " & $a.t.kind)
|
||||||
putIntoDest(p, d, a.t.sons[0], ropef("(*$1)", [rdLoc(a)]))
|
if enforceDeref and mt == ctPtrToArray:
|
||||||
|
# we lie about the type for better C interop: 'ptr array[3,T]' is
|
||||||
|
# translated to 'ptr T', but for deref'ing this produces wrong code.
|
||||||
|
# See tmissingderef. So we get rid of the deref instead. The codegen
|
||||||
|
# ends up using 'memcpy' for the array assignment,
|
||||||
|
# so the '&' and '*' cancel out:
|
||||||
|
putIntoDest(p, d, a.t.sons[0], rdLoc(a))
|
||||||
|
else:
|
||||||
|
putIntoDest(p, d, a.t.sons[0], ropef("(*$1)", [rdLoc(a)]))
|
||||||
|
|
||||||
proc genAddr(p: BProc, e: PNode, d: var TLoc) =
|
proc genAddr(p: BProc, e: PNode, d: var TLoc) =
|
||||||
# careful 'addr(myptrToArray)' needs to get the ampersand:
|
# careful 'addr(myptrToArray)' needs to get the ampersand:
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,7 @@
|
||||||
|
discard """
|
||||||
|
ouput: '''foo
|
||||||
|
true'''
|
||||||
|
"""
|
||||||
|
|
||||||
converter p(i: int): bool = return i != 0
|
converter p(i: int): bool = return i != 0
|
||||||
|
|
||||||
|
|
@ -6,3 +10,6 @@ if 1:
|
||||||
while 0:
|
while 0:
|
||||||
echo "bar"
|
echo "bar"
|
||||||
|
|
||||||
|
var a: array[3, bool]
|
||||||
|
a[0] = 3
|
||||||
|
echo a[0]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue