Skip to content

Commit 7c65d9e

Browse files
authored
fixes #25204; Uninitialized variable usage in resize__system_u... in @psystem.nim.c in ORC (#25209)
fixes #25204 ```nim of mUnaryMinusI..mAbsI: unaryArithOverflow(p, e, d, op) of mAddI..mPred: binaryArithOverflow(p, e, d, op) ``` Arithmetic operations may raise exceptions. So we cannot entrust the optimizer to skip `result` initialization in this situation, as complained righteously by `gcc` and `clang`: `warning: ‘result’ may be used uninitialized [-Wmaybe-uninitialize]`. With this PR, `clang -c -Wuninitialized -O1 @psystem.nim.c` no longer gives warnings
1 parent c4c51d7 commit 7c65d9e

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

compiler/cgen.nim

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,11 @@ proc allPathsAsgnResult(p: BProc; n: PNode): InitResultEnum =
12381238
(n[0].kind == nkSym and sfNoReturn in n[0].sym.flags):
12391239
# requires initializations when encountering unreachable code
12401240
result = InitRequired
1241+
elif n[0].kind == nkSym and
1242+
n[0].sym.magic in {mUnaryMinusI..mAbsI, mAddI..mPred} and
1243+
optOverflowCheck in p.config.options:
1244+
# arithmetic operations may raise exceptions
1245+
result = InitRequired
12411246
else:
12421247
for i in 0..<n.safeLen:
12431248
allPathsInBranch(n[i])

0 commit comments

Comments
 (0)