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

SIGSEGV when cast is Improperly Formatted #21027

Closed
ammrat13 opened this issue Dec 6, 2022 · 0 comments · Fixed by #21029
Closed

SIGSEGV when cast is Improperly Formatted #21027

ammrat13 opened this issue Dec 6, 2022 · 0 comments · Fixed by #21029

Comments

@ammrat13
Copy link

ammrat13 commented Dec 6, 2022

Description

Running nim c test.nim when the file contains the following code produces a SIGSEGV during compilation:

let x: uint64 = cast(5)

Expected behavior is for the compiler to either infer that the cast should be to uint64 or to issue a syntax error.

Nim Version

Nim Compiler Version 1.6.10 [Linux: amd64]
Compiled at 2022-11-21
Copyright (c) 2006-2021 by Andreas Rumpf

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

Current Output

$ nim c --verbosity:3 test.nim 
/home/ammar/.choosenim/toolchains/nim-1.6.10/config/nim.cfg(47, 3) Hint: added path: '/opt/nimble/pkgs2/' [Path]
    nimblepath="/opt/nimble/pkgs2/"
    ^
/home/runner/work/nightlies/nightlies/nim-1.6.10/compiler/nimblecmd.nim(139, 12) compiler msg initiated here [MsgOrigin]
/home/ammar/.choosenim/toolchains/nim-1.6.10/config/nim.cfg(48, 3) Hint: added path: '/opt/nimble/pkgs/' [Path]
    nimblepath="/opt/nimble/pkgs/"
    ^
/home/runner/work/nightlies/nightlies/nim-1.6.10/compiler/nimblecmd.nim(139, 12) compiler msg initiated here [MsgOrigin]
/home/ammar/.choosenim/toolchains/nim-1.6.10/config/nim.cfg(52, 1) Hint: added path: '/home/ammar/.nimble/pkgs2/' [Path]
  nimblepath="$home/.nimble/pkgs2/"
  ^
/home/runner/work/nightlies/nightlies/nim-1.6.10/compiler/nimblecmd.nim(139, 12) compiler msg initiated here [MsgOrigin]
/home/ammar/.choosenim/toolchains/nim-1.6.10/config/nim.cfg(53, 1) Hint: added path: '/home/ammar/.nimble/pkgs/flush_reload_test-0.0.0' [Path]
  nimblepath="$home/.nimble/pkgs/"
  ^
/home/runner/work/nightlies/nightlies/nim-1.6.10/compiler/nimblecmd.nim(139, 12) compiler msg initiated here [MsgOrigin]
/home/ammar/.choosenim/toolchains/nim-1.6.10/config/nim.cfg(53, 1) Hint: added path: '/home/ammar/.nimble/pkgs/' [Path]
  nimblepath="$home/.nimble/pkgs/"
  ^
/home/runner/work/nightlies/nightlies/nim-1.6.10/compiler/nimblecmd.nim(139, 12) compiler msg initiated here [MsgOrigin]
Hint: used config file '/home/ammar/.choosenim/toolchains/nim-1.6.10/config/nim.cfg' [Conf]
/home/runner/work/nightlies/nightlies/nim-1.6.10/compiler/nimconf.nim(297, 17) compiler msg initiated here [MsgOrigin]
Hint: used config file '/home/ammar/.choosenim/toolchains/nim-1.6.10/config/config.nims' [Conf]
/home/runner/work/nightlies/nightlies/nim-1.6.10/compiler/nimconf.nim(297, 17) compiler msg initiated here [MsgOrigin]
.........................................................
/home/ammar/Desktop/test.nim(1, 1) Hint: (module: 26, symId: 0, typeId: 2, sealed: false) [ProcessingStmt]
  let x: uint64 = cast(5)
  ^
/home/runner/work/nightlies/nightlies/nim-1.6.10/compiler/passaux.nim(29, 10) compiler msg initiated here [MsgOrigin]
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
$ gdb nim
...
Thread 2.1 "nim" received signal SIGSEGV, Segmentation fault.
0x00000000006d1c79 in semCast__sem_15219 ()
...
 ► 0x6d1c79 <semCast__sem_15219+201>    test   byte ptr [rbp + 0x1a], 0x20
   0x6d1c7d <semCast__sem_15219+205>    je     semCast__sem_15219+364                      <semCast__sem_15219+364>
    ↓
   0x6d1d1c <semCast__sem_15219+364>    mov    rdx, qword ptr [r13]
   0x6d1d20 <semCast__sem_15219+368>    mov    rsi, rbp
   0x6d1d23 <semCast__sem_15219+371>    mov    rdi, r12
   0x6d1d26 <semCast__sem_15219+374>    call   isCastable__sem_14972                      <isCastable__sem_14972>
 
   0x6d1d2b <semCast__sem_15219+379>    test   al, al
   0x6d1d2d <semCast__sem_15219+381>    je     semCast__sem_15219+688                      <semCast__sem_15219+688>
 
   0x6d1d33 <semCast__sem_15219+387>    mov    rsi, qword ptr [rbx + 8]
   0x6d1d37 <semCast__sem_15219+391>    mov    edi, 0x3d
   0x6d1d3c <semCast__sem_15219+396>    call   newNodeI__ast_3326                      <newNodeI__ast_3326>
...
(gdb) bt
#0  0x00000000006d1c79 in semCast__sem_15219 ()
#1  0x00000000006aadce in semExpr__sem_52 ()
#2  0x00000000006b4568 in semExprCheck__sem_14628 ()
#3  0x000000000069c057 in semExprWithType__sem_56 ()
#4  0x00000000006f9488 in semVarOrLet__sem_10533 ()
#5  0x00000000006aa6ca in semExpr__sem_52 ()
#6  0x00000000006b2473 in semStmtList__sem_14426 ()
#7  0x00000000006a9ca7 in semExpr__sem_52 ()
#8  0x00000000006abdf8 in semExprNoType__sem_60 ()
#9  0x000000000070d85b in semStmtAndGenerateGenerics__sem_21525 ()
#10 0x000000000070db80 in myProcess__sem_21576 ()
#11 0x0000000000584313 in processTopLevelStmt__passes_140 ()
#12 0x0000000000584983 in processModule__passes_213 ()
#13 0x00000000007e0cec in compileModule__modules_33 ()
#14 0x0000000000866a90 in commandCompileToC__main_367 ()
#15 0x0000000000867bb8 in mainCommand__main_508 ()
#16 0x000000000086a360 in handleCmdLine__nim_41 ()
#17 0x000000000086aaf1 in NimMainInner ()
#18 0x000000000086ad06 in NimMain ()
#19 0x000000000040040d in main ()
#20 0x000000000086b20c in libc_start_main_stage2 ()
#21 0x000000000086b1e5 in __libc_start_init ()
#22 0x0000000000000000 in ?? ()
(gdb) info reg
rax            0x7ffff6b5de30      140737332502064
rbx            0x7ffff6b5dec0      140737332502208
rcx            0x3200              12800
rdx            0x1f                31
rsi            0x7ffff79b2400      140737347527680
rdi            0x7ffff60c1430      140737321374768
rbp            0x0                 0x0
rsp            0x7fffffffd3b0      0x7fffffffd3b0
r8             0x101010101010101   72340172838076673
r9             0x7ffff6b5d060      140737332498528
r10            0x202c              8236
r11            0x6449              25673
r12            0x7ffff7838640      140737345979968
r13            0x7ffff6b5de30      140737332502064
r14            0x8d8af0            9276144
r15            0x7ffff7838640      140737345979968
rip            0x6d1c79            0x6d1c79 <semCast__sem_15219+201>
eflags         0x10206             [ PF IF RF ]
cs             0x33                51
ss             0x2b                43
ds             0x0                 0
es             0x0                 0
fs             0x0                 0
gs             0x0                 0

Expected Output

No response

Possible Solution

No response

Additional Information

For some reason the base pointer is NULL.

Araq pushed a commit that referenced this issue Dec 6, 2022
* fixes #21027; cast expressions need a type

* Apply suggestions from code review

Thanks to @beef331
survivorm pushed a commit to survivorm/Nim that referenced this issue Feb 28, 2023
* fixes nim-lang#21027; cast expressions need a type

* Apply suggestions from code review

Thanks to @beef331
capocasa pushed a commit to capocasa/Nim that referenced this issue Mar 31, 2023
* fixes nim-lang#21027; cast expressions need a type

* Apply suggestions from code review

Thanks to @beef331
narimiran pushed a commit that referenced this issue Apr 25, 2023
* fixes #21027; cast expressions need a type

* Apply suggestions from code review

Thanks to @beef331

(cherry picked from commit 1564ae6)
narimiran pushed a commit that referenced this issue Apr 25, 2023
* fixes #21027; cast expressions need a type

* Apply suggestions from code review

Thanks to @beef331

(cherry picked from commit 1564ae6)
narimiran pushed a commit that referenced this issue Apr 25, 2023
* fixes #21027; cast expressions need a type

* Apply suggestions from code review

Thanks to @beef331

(cherry picked from commit 1564ae6)
narimiran pushed a commit that referenced this issue Apr 25, 2023
* fixes #21027; cast expressions need a type

* Apply suggestions from code review

Thanks to @beef331

(cherry picked from commit 1564ae6)
narimiran pushed a commit that referenced this issue Apr 26, 2023
* fixes #21027; cast expressions need a type

* Apply suggestions from code review

Thanks to @beef331

(cherry picked from commit 1564ae6)
bung87 pushed a commit to bung87/Nim that referenced this issue Jul 29, 2023
* fixes nim-lang#21027; cast expressions need a type

* Apply suggestions from code review

Thanks to @beef331
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.

3 participants