From 17475fc5d3f1f198e1038ca35b4c2a4b48b2379a Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Tue, 4 Jun 2024 15:43:12 +0800 Subject: [PATCH] fixes openarray hoist with gcc 14 (#23647) blocks https://github.com/nim-lang/Nim/pull/23673 --------- Co-authored-by: Andreas Rumpf --- compiler/semexprs.nim | 17 ++++++++++++++++- tests/ccgbugs/t10964.nim | 3 ++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 8fcf5936ef..10695ed1d0 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -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 diff --git a/tests/ccgbugs/t10964.nim b/tests/ccgbugs/t10964.nim index a331b16cdc..c19db69971 100644 --- a/tests/ccgbugs/t10964.nim +++ b/tests/ccgbugs/t10964.nim @@ -3,4 +3,5 @@ func test*(input: var openArray[int32], start: int = 0, fin: int = input.len - 1 var someSeq = @[1'i32] -test(someSeq) \ No newline at end of file +test(someSeq) +# bug with gcc 14 \ No newline at end of file