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 crash with new mangling module with a cdecl,varargs proc #1394

Closed
starsiderfox opened this issue Aug 3, 2024 · 1 comment · Fixed by #1396
Closed

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

starsiderfox opened this issue Aug 3, 2024 · 1 comment · Fixed by #1396
Assignees
Labels
bug Something isn't working compiler/backend Related to backend system of the compiler

Comments

@starsiderfox
Copy link
Contributor

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]
@starsiderfox starsiderfox added the bug Something isn't working label Aug 3, 2024
@zerbina zerbina added the compiler/backend Related to backend system of the compiler label Aug 3, 2024
@zerbina zerbina self-assigned this Aug 3, 2024
github-merge-queue bot pushed a commit that referenced this issue Aug 4, 2024
## Summary

Fix the compiler crashing when a non-closure `proc` type with C-style
varargs is used somewhere. Only the C backend was affected.

Fixes #1394.

## Details

* `mirtypes.callConv` didn't consider the `x` field storing a boolean
  value in the most-significant bit, resulting in range defect
* the integer value is now properly masked before converting it to a
  `TCallingConvention` enum value
@saem
Copy link
Collaborator

saem commented Aug 4, 2024

Fixed in #1396

@saem saem closed this as completed Aug 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compiler/backend Related to backend system of the compiler
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants