Skip to content

--gc:arc segfaults when returning result from a proc #15609

Closed
@n5m

Description

When returning result from a proc, --gc:arc fails while --gc:refc does not.

Example

type
  Wrapper = object
    discard

proc newWrapper(): ref Wrapper =
  new(result)

  # Uncommenting this line works with --gc:refc, fails with --gc:arc
  # Commenting this line works with --gc:refc and --gc:arc
  result

when isMainModule:
  let w: ref Wrapper = newWrapper()
  echo $w[]

Current Output

When result is uncommented

Compiling with nim compile --gc:arc return_result.nim

$ ./return_result 
Traceback (most recent call last)
/home/user/return_result.nim(15) return_result
SIGSEGV: Illegal storage access. (Attempt to read from nil?)

Compiling with nim compile --gc:refc return_result.nim

$ ./return_result 
()

When result is commented

No matter if you compile with --gc:arc or --gc:refc, both output the same.

$ ./return_result 
()

Expected Output

I expect to encounter a SIGSEGV in neither case.

Additional Information

git hash bdcd87a

$ nim --version
Nim Compiler Version 1.4.0 [Linux: amd64]
Compiled at 2020-10-16
Copyright (c) 2006-2020 by Andreas Rumpf

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions