Skip to content

refc SIGSEGV on var r = V(g: true, v: A()); discard move r; GC_fullCollect() on case object #25992

Description

@tersec

Nim Version

Nim Compiler Version 2.2.10 [Linux: amd64]
Compiled at 2026-05-27
Copyright (c) 2006-2026 by Andreas Rumpf

active boot switches: -d:release
Nim Compiler Version 2.2.11 [Linux: amd64]
Compiled at 2026-07-06
Copyright (c) 2006-2026 by Andreas Rumpf

git hash: d38dd01e85a149b79e0e002f82fc3b41b223e204
active boot switches: -d:release
Nim Compiler Version 2.3.1 [Linux: amd64]
Compiled at 2026-07-08
Copyright (c) 2006-2026 by Andreas Rumpf

git hash: abdf1ca559e08539f2b5124e049f3a2497c39f61
active boot switches: -d:release

With either:

gcc (Debian 15.3.0-1) 15.3.0
Copyright (C) 2025 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

or

Debian clang version 21.1.8 (7+b4)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm-21/bin

Description

type A = object of RootObj
type V = object
  case g: bool
  of true: v: A
  of false: e: string
var r = V(g: true, v: A())
discard move r
GC_fullCollect()

Worth noting this reproduces an easy-to-spot result, a segmentation fault. Other variations can be set up which corrupt memory in a running program. It partly depends when/if the GC_fullCollect() is run, -d:release, and/or -d:useSysAssert are specified.

Current Output

Traceback (most recent call last)
/tmp/h.nim(8)            h
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
Segmentation fault
Error: execution of an external program failed: '/tmp/h'

Expected Output

no SIGSEGV

Known Workarounds

No response

Additional Information

No response

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions