fix #20972 fixes invalid and UB codegen case object transitions for both refc and ORC [backport] (#21611)

fix #20972 fixes invalid and UB codegen case object transitions for refc and ORC
This commit is contained in:
ringabout
2023-04-04 18:18:43 +08:00
committed by GitHub
parent 31d3606fe8
commit 3575f2bf9c
2 changed files with 20 additions and 3 deletions

View File

@@ -275,10 +275,12 @@ proc genericReset(dest: pointer, mt: PNimType) =
proc selectBranch(discVal, L: int,
a: ptr array[0x7fff, ptr TNimNode]): ptr TNimNode =
result = a[L] # a[L] contains the ``else`` part (but may be nil)
if discVal <% L:
let x = a[discVal]
if x != nil: result = x
result = a[discVal]
if result == nil:
result = a[L]
else:
result = a[L] # a[L] contains the ``else`` part (but may be nil)
proc FieldDiscriminantCheck(oldDiscVal, newDiscVal: int,
a: ptr array[0x7fff, ptr TNimNode],

15
tests/objects/t20972.nim Normal file
View File

@@ -0,0 +1,15 @@
discard """
matrix: "--mm:refc -d:release; --mm:orc -d:release"
"""
{.passC: "-fsanitize=undefined -fsanitize-undefined-trap-on-error -Wall -Wextra -pedantic -flto".}
{.passL: "-fsanitize=undefined -fsanitize-undefined-trap-on-error -flto".}
# bug #20972
type ForkedEpochInfo = object
case kind: bool
of true, false: discard
var info = ForkedEpochInfo(kind: true)
doAssert info.kind
info.kind = false
doAssert not info.kind