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
274 stars 38 forks source link

tprocedural_views fails to compile with gcc 14 #1376

Open alaviss opened 2 months ago

alaviss commented 2 months ago

Example

./koch.py tests --targets:c r tests/lang_experimental/views/tprocedural_views.nim

Actual Output

FAIL: tests/lang_experimental/views/tprocedural_views.nim c        ( 0.18 sec)
Test "tests/lang_experimental/views/tprocedural_views.nim" in category "lang_experimental"
Failure: reNimcCrash
debugInfo:  compiler exit code was 1 but no Error's were found.
$ nimskull/bin/nim c --hints:on -d:testing --clearNimblePath --nimblePath:build/deps/pkgs   --nimCache:nimcache/tests/lang_experimental/views/tprocedural_views.nim_4a8a08f09d37b73795649038408b5f33  tests/lang_experimental/views/tprocedural_views.nim
nimskull/nimcache/tests/lang_experimental/views/tprocedural_views.nim_4a8a08f09d37b73795649038408b5f33/@mtprocedural_views.nim.c: In function ‘NimMainModule’:
nimskull/nimcache/tests/lang_experimental/views/tprocedural_views.nim_4a8a08f09d37b73795649038408b5f33/@mtprocedural_views.nim.c:135:19: error: assignment to ‘NI (**)(NI)’ {aka ‘long int (**)(long int)’} from incompatible pointer type ‘tyProc__AUU7JKzv059aLg8CDEB5NOw’ {aka ‘long int (*)(long int)’} [-Wincompatible-pointer-types]
  135 |         _7.Field0 = _6;
      |                   ^
execution of an external program 'gcc -c  -w -fmax-errors=3   -Inimskull/lib -Inimskull/tests/lang_experimental/views -o nimskull/nimcache/tests/lang_experimental/views/tprocedural_views.nim_4a8a08f09d37b73795649038408b5f33/@mtprocedural_views.nim.c.o nimskull/nimcache/tests/lang_experimental/views/tprocedural_views.nim_4a8a08f09d37b73795649038408b5f33/@mtprocedural_views.nim.c' failed with exit code '1'
zerbina commented 2 months ago

The problem lies in line 35, with the minimal reproducer being:

type
  Proc = proc (x: int): int {.nimcall.}
  Obj = object
    tup: (lent Proc,)

let
  p = proc(x: int): int = x
  o = Obj(tup: (p,))

As can be seen in the (shortened) --showir:transf output:

0 N:LetSection
  0 N:IdentDefs
    0 N:Sym "o" sk:skLet
    1 N:Empty
    2 N:ObjConstr
      0 N:Sym "Obj" sk:skType
      1 N:ExprColonExpr
        0 N:Sym "tup" sk:skField
            offset:  0
        1 N:TupleConstr
          0 N:Sym "p" sk:skLet # <- this is the important part

The HiddenAddr operation for creating a view of p is missing, meaning that a function pointer is assigned to a location expecting a pointer to a function pointer.

All backends are affected.