nim-works / nimskull

An in development statically typed systems programming language; with sustainability at its core. We, the community of users, maintain it.
https://nim-works.github.io/nimskull/index.html
Other
280 stars 39 forks source link

Compiler crash with new mangling module with a cdecl,varargs proc #1394

Closed starsiderfox closed 4 months ago

starsiderfox commented 4 months ago

Specification

The compiler crashes since mangling.nim was added. After a while I've traced it to the presence of an object member that has a {.cdecl, varargs.} procedure even if it's never accessed (trying to access a different member causes the crash).

Example

Try to compile this: (I've only tested with the C backend)

type P = ptr object
    a: proc() 
    b: proc() {.cdecl, varargs.}
var p: P
p.a()

Actual Output

nim.nim                  nim
nim.nim                  handleCmdLine
main.nim                 mainCommand
main.nim                 compileToBackend
main.nim                 commandCompileToC
cbackend.nim             generateCode
cbackend.nim             generateCode
cbackend.nim             processEvent
ccgstmts.nim             genStmts
ccgstmts.nim             gen
ccgstmts.nim             genStmt
ccgexprs.nim             expr cnkCheckedCall /tmp/crasher/test.nim(5, 3)
ccgcalls.nim             genCall
ccgcalls.nim             genAsgnCall
ccgcalls.nim             genClosureCall
cgen.nim                 initLocExpr
ccgexprs.nim             expr cnkFieldAccess /tmp/crasher/test.nim(5, 1)
ccgexprs.nim             genRecordField
ccgexprs.nim             genRecordFieldAux
cgen.nim                 initLocExpr
ccgexprs.nim             expr cnkDeref /tmp/crasher/test.nim(5, 0)
ccgexprs.nim             genDeref
ccgtypes.nim             getTypeDesc
ccgtypes.nim             useType
ccgtypes.nim             useType
ccgtypes.nim             emitTypeDef
ccgtypes.nim             genRecordDesc
ccgtypes.nim             genFieldDesc
ccgtypes.nim             genDecl
ccgtypes.nim             useType
ccgtypes.nim             useType
ccgtypes.nim             emitTypeDef
mangling.nim             computeTypeName
mangling.nim             mangle
mirtypes.nim             callConv
fatal.nim                sysFatal
Error: unhandled exception: value out of range: 2147483650 notin 0 .. 9 [RangeDefect]
saem commented 4 months ago

Fixed in https://github.com/nim-works/nimskull/pull/1396