fixes openarray hoist with gcc 14 (#23647)

blocks https://github.com/nim-lang/Nim/pull/23673

---------

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
This commit is contained in:
ringabout
2024-06-04 15:43:12 +08:00
committed by GitHub
parent d22e8f7f82
commit 17475fc5d3
2 changed files with 18 additions and 2 deletions

View File

@@ -2944,6 +2944,18 @@ proc asBracketExpr(c: PContext; n: PNode): PNode =
return result
return nil
proc isOpenArraySym(x: PNode): bool =
var x = x
while true:
case x.kind
of {nkAddr, nkHiddenAddr}:
x = x[0]
of {nkHiddenStdConv, nkHiddenDeref}:
x = x[1]
else:
break
result = x.kind == nkSym
proc hoistParamsUsedInDefault(c: PContext, call, letSection, defExpr: var PNode) =
# This takes care of complicated signatures such as:
# proc foo(a: int, b = a)
@@ -2964,7 +2976,10 @@ proc hoistParamsUsedInDefault(c: PContext, call, letSection, defExpr: var PNode)
if defExpr.kind == nkSym and defExpr.sym.kind == skParam and defExpr.sym.owner == call[0].sym:
let paramPos = defExpr.sym.position + 1
if call[paramPos].skipAddr.kind != nkSym:
if call[paramPos].skipAddr.kind != nkSym and not (
skipTypes(call[paramPos].typ, abstractVar).kind in {tyOpenArray, tyVarargs} and
isOpenArraySym(call[paramPos])
):
let hoistedVarSym = newSym(skLet, getIdent(c.graph.cache, genPrefix), c.idgen,
c.p.owner, letSection.info, c.p.owner.options)
hoistedVarSym.typ = call[paramPos].typ

View File

@@ -3,4 +3,5 @@ func test*(input: var openArray[int32], start: int = 0, fin: int = input.len - 1
var someSeq = @[1'i32]
test(someSeq)
test(someSeq)
# bug with gcc 14