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

Compiler segfault in codegen when putting nested importCpp type into seq #20065

Closed
RedBeard0531 opened this issue Jul 20, 2022 · 1 comment · Fixed by #24525
Closed

Compiler segfault in codegen when putting nested importCpp type into seq #20065

RedBeard0531 opened this issue Jul 20, 2022 · 1 comment · Fixed by #24525

Comments

@RedBeard0531
Copy link
Contributor

Example

The following code causes a segfault in the nim compiler itself.

type
  Foo* {.importC, nodecl.} = object # doesn't matter if this is importC or importCpp
    value*: int64
  Bar* {.importCpp, nodecl.} = object # no segfault with importC
    foo*: Foo

discard @[Bar()]

This appears to be a minimal repo. In particular, Foo needs to have a member, and Bar needs to be put into a seq. I don't know what other uses of Bar would also cause a compiler segfault, but discard Bar() was insufficient.

Current Output

> ~/nim/nim/bin/nim cpp repro.nim
Hint: used config file '/home/mstearn/nim/nim/config/nim.cfg' [Conf]
Hint: used config file '/home/mstearn/nim/nim/config/config.nims' [Conf]
.................................................................Traceback (most recent call last)
/home/mstearn/nim/nim/compiler/nim.nim(143) nim
/home/mstearn/nim/nim/compiler/nim.nim(98) handleCmdLine
/home/mstearn/nim/nim/compiler/main.nim(285) mainCommand
/home/mstearn/nim/nim/compiler/main.nim(255) compileToBackend
/home/mstearn/nim/nim/compiler/main.nim(110) commandCompileToC
/home/mstearn/nim/nim/compiler/modules.nim(136) compileProject
/home/mstearn/nim/nim/compiler/modules.nim(56) compileModule
/home/mstearn/nim/nim/compiler/passes.nim(183) processModule
/home/mstearn/nim/nim/compiler/passes.nim(76) processTopLevelStmt
/home/mstearn/nim/nim/compiler/cgen.nim(1991) myProcess
/home/mstearn/nim/nim/compiler/cgen.nim(1985) genTopLevelStmt
/home/mstearn/nim/nim/compiler/cgen.nim(1021) genProcBody
/home/mstearn/nim/nim/compiler/ccgstmts.nim(1607) genStmts
/home/mstearn/nim/nim/compiler/ccgexprs.nim(2883) expr
/home/mstearn/nim/nim/compiler/ccgexprs.nim(2612) genStmtList
/home/mstearn/nim/nim/compiler/ccgstmts.nim(1607) genStmts
/home/mstearn/nim/nim/compiler/ccgexprs.nim(2927) expr
/home/mstearn/nim/nim/compiler/cgen.nim(655) initLocExprSingleUse
/home/mstearn/nim/nim/compiler/ccgexprs.nim(2851) expr
/home/mstearn/nim/nim/compiler/ccgexprs.nim(2442) genMagicExpr
/home/mstearn/nim/nim/compiler/ccgexprs.nim(1561) genArrToSeq
/home/mstearn/nim/nim/compiler/ccgexprs.nim(1544) genSeqConstr
/home/mstearn/nim/nim/compiler/ccgexprs.nim(1405) genNewSeqAux
/home/mstearn/nim/nim/compiler/ccgtypes.nim(1487) genTypeInfoV1
/home/mstearn/nim/nim/compiler/ccgtrav.nim(156) genTraverseProc
/home/mstearn/nim/nim/compiler/ccgtrav.nim(130) genTraverseProcSeq
/home/mstearn/nim/nim/compiler/ccgtrav.nim(94) genTraverseProc
/home/mstearn/nim/nim/compiler/ccgtrav.nim(31) genTraverseProc
/home/mstearn/nim/nim/compiler/ccgtrav.nim(57) genTraverseProc
/home/mstearn/nim/nim/compiler/ccgtrav.nim(94) genTraverseProc
/home/mstearn/nim/nim/compiler/ccgtrav.nim(31) genTraverseProc
/home/mstearn/nim/nim/compiler/ccgtrav.nim(55) genTraverseProc
/home/mstearn/nim/nim/compiler/cgen.nim(78) t
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
zsh: segmentation fault  ~/nim/nim/bin/nim cpp repro.nim

Expected Output

The compiler shouldn't segfault? Ideally this would generate working code. If there is a problem with the source file (I don't think there is), it should output a clear error.

Possible Solution

🤷

Additional Information

Repros at least in 1.6.6 and devel as of efcb89f

@metagn
Copy link
Collaborator

metagn commented Oct 10, 2024

Seems to work in 2.0+

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

Successfully merging a pull request may close this issue.

2 participants