nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.22k stars 1.46k forks source link

[backport] fixes #23690; SIGSEGV with object variants and RTTI #23703

Closed ringabout closed 2 weeks ago

ringabout commented 3 weeks ago

fixes #23690

dest.`:state` = src.`:state`
var :tmp_553651276 = dest.e1.a
`=wasMoved`(dest.e1.a)
dest.e1.a.kind = src.e1.a.kind
case dest.e1.a.kind
of 0:
  dest.e1.a.a = src.e1.a.a
of 1:
  `=copy`(dest.e1.a.c, src.e1.a.c)
case :tmp_553651276.kind
of 0:
of 1:
  `=destroy`(:tmp_553651276.c)

dest.e1.a.kind = src.e1.a.kind changes the discrimant but it fails to clear the memory of dest.e1.a. Before using hooks for copying, we need to clear the dest, e.g. =wasMoved(dest.e1.a.c).

dest.`:state` = src.`:state`
var :tmp_553651276 = dest.e1.a
`=wasMoved`(dest.e1.a)
dest.e1.a.kind = src.e1.a.kind
case dest.e1.a.kind
of 0:
  `=wasMoved`(dest.e1.a.a)
  dest.e1.a.a = src.e1.a.a
  `=wasMoved`(dest.e1.a.b)
of 1:
  `=wasMoved`(dest.e1.a.c)
  `=copy`(dest.e1.a.c, src.e1.a.c)
case :tmp_553651276.kind
of 0:
of 1:
  `=destroy`(:tmp_553651276.c)
alex65536 commented 2 weeks ago

Thanks for the fix :)

Is it possible to [backport] the commit into stable, by the way?

github-actions[bot] commented 2 weeks ago

Thanks for your hard work on this PR! The lines below are statistics of the Nim compiler built from 262ff648aad7cc2062eb94cb6bf3357f9910c448

Hint: mm: orc; opt: speed; options: -d:release 178739 lines; 8.284s; 664.652MiB peakmem