Skip to content

Commit

Permalink
don't track result initialization if it is marked noinit (#24499)
Browse files Browse the repository at this point in the history
We don't track `noinit` for variables introduced in
#10566. It should be applied to
`result` if the function is marked `noinit`
  • Loading branch information
ringabout authored Dec 4, 2024
1 parent bbf6a62 commit 2e9e7f1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
6 changes: 5 additions & 1 deletion compiler/sempass2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1644,6 +1644,9 @@ proc trackProc*(c: PContext; s: PSym, body: PNode) =
s.kind in {skProc, skFunc, skConverter, skMethod}:
var res = s.ast[resultPos].sym # get result symbol
t.scopes[res.id] = t.currentBlock
if sfNoInit in s.flags:
# marks result "noinit"
incl res.flags, sfNoInit

track(t, body)

Expand All @@ -1662,7 +1665,8 @@ proc trackProc*(c: PContext; s: PSym, body: PNode) =
if not isEmptyType(s.typ.returnType) and
(s.typ.returnType.requiresInit or s.typ.returnType.skipTypes(abstractInst).kind == tyVar or
noStrictDefs notin c.config.legacyFeatures) and
s.kind in {skProc, skFunc, skConverter, skMethod} and s.magic == mNone:
s.kind in {skProc, skFunc, skConverter, skMethod} and s.magic == mNone and
sfNoInit notin s.flags:
var res = s.ast[resultPos].sym # get result symbol
if res.id notin t.init and breaksBlock(body) != bsNoReturn:
if tfRequiresInit in s.typ.returnType.flags:
Expand Down
1 change: 0 additions & 1 deletion lib/pure/volatile.nim
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ proc volatileLoad*[T](src: ptr T): T {.inline, noinit.} =
when defined(js):
result = src[]
else:
result = default(T)
{.emit: [result, " = (*(", typeof(src[]), " volatile*)", src, ");"].}

proc volatileStore*[T](dest: ptr T, val: T) {.inline.} =
Expand Down

0 comments on commit 2e9e7f1

Please sign in to comment.