Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nim cpp -r --gc:arc segfaults on caught AssertionError #13071

Closed
timotheecour opened this issue Jan 8, 2020 · 3 comments · Fixed by #14323
Closed

nim cpp -r --gc:arc segfaults on caught AssertionError #13071

timotheecour opened this issue Jan 8, 2020 · 3 comments · Fixed by #14323

Comments

@timotheecour
Copy link
Member

timotheecour commented Jan 8, 2020

nim cpp -r --gc:arc segfaults on dereferencing e in Exception as e

Example

when true:
  type MyExcept = object of CatchableError
  proc gun()=
    raise newException(MyExcept, "some msg")
  proc fun()=
    try:
      gun()
    except Exception as e:
      echo "caught1"
      echo ("caught2", e.msg, e.name) # segfault here for `nim cpp --gc:arc`
  fun()

Current Output

nim cpp -r --gc:arc main.nim

caught1
("caught2", "some msg", "MyExcept")
Traceback (most recent call last)
/Users/timothee/git_clone/nim/timn/tests/nim/all/t0900.nim(75) t0900
/Users/timothee/git_clone/nim/Nim_prs/lib/system/excpt.nim(73) fun
/Users/timothee/git_clone/nim/Nim_prs/lib/system/refs_v2.nim(116) nimDestroyAndDispose
SIGSEGV: Illegal storage access. (Attempt to read from nil?)

Expected Output

caught1
("caught2", "some msg", "MyExcept")

Additional Information

Traceback (most recent call last)
/Users/timothee/git_clone/nim/timn/tests/nim/all/t0900.nim(63) t0900
/Users/timothee/git_clone/nim/timn/tests/nim/all/t0900.nim(60) fun
/Users/timothee/git_clone/nim/timn/tests/nim/all/t0900.nim(57) gun
/Users/timothee/git_clone/nim/Nim_prs/lib/system/assertions.nim(27) failedAssertImpl
/Users/timothee/git_clone/nim/Nim_prs/lib/system/assertions.nim(20) raiseAssert
/Users/timothee/git_clone/nim/Nim_prs/lib/system/fatal.nim(45) sysFatal
/Users/timothee/git_clone/nim/Nim_prs/lib/system/fatal.nim(33) sysFatal
Error: unhandled exception: /Users/timothee/git_clone/nim/timn/tests/nim/all/t0900.nim(57, 14) `false` threw.. [AssertionError]

this is NOT discussed in this issue

@c-blake
Copy link
Contributor

c-blake commented Jan 14, 2020

I was able to reproduce this with nim-9fc04a555ca0fc9eaff6d4eb9ba47a0a64feb9c2 compiled with and compling client code with gcc-8.3.0 on Linux with no user nim.cfg and only --exceptions:goto and this code:

proc doIt() =
  raise newException(CatchableError, "")
try:
  doIt()
except:
  quit(1)

Putting the try/except in a main() and calling it does not help. Catching except CatchableError: ... or except CatchableError as e: .. also changes nothing. Changing from the default gc to --gc:arc also changes nothing. The exception is not caught in any of those cases. Changing CatchableError to Exception changes nothing, but I guess the intent is for that to fail in exactly this way.

This all seemed really basic. So, I went to tests/exceptions/. Many of those seem to compile and work, but perhaps the most relevant nim c --exceptions:goto tests/exception/texceptions.nim fails to Nim-compile with the exception in expression, saying texceptions.nim(72, 7) Error: expression '1' is of type 'int literal(1)' and has to be discarded. That compiles in other --exception modes and I suspect is a known problem being in tests/.

Commenting out said block makes tests/exception/texceptions.nim compile and then also reproduce this problem in my environment. The first uncaught-that-should-be-caught one that I see is the ValueError raised in fun1. Perhaps @timotheecour can confirm for his environment or @Araq for Windows? I have not yet tried to dig into the generated C code.

@Araq
Copy link
Member

Araq commented Jan 15, 2020

@c-blake Your bug has been fixed, but the original bug with nim cpp remains so I'm leaving this open until my C++ exception handling bugfixes are ready.

@c-blake
Copy link
Contributor

c-blake commented Jan 15, 2020

Cool. Yeah, bug seems squashed to me. Thanks for the rapid response and good luck with the cpp target.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants