fixes #5901 #21211; don't fold cast function types because of gcc 14 (#23683)

follow up https://github.com/nim-lang/Nim/pull/6265

fixes #5901
fixes #21211

It causes many problems with gcc14 if we fold the cast function types.
Let's check what it will break
This commit is contained in:
ringabout
2024-06-06 02:54:00 +08:00
committed by GitHub
parent 42e8472ca6
commit 2d1533f34f
2 changed files with 8 additions and 2 deletions

View File

@@ -771,7 +771,8 @@ proc getConstExpr(m: PSym, n: PNode; idgen: IdGenerator; g: ModuleGraph): PNode
of nkCast:
var a = getConstExpr(m, n[1], idgen, g)
if a == nil: return
if n.typ != nil and n.typ.kind in NilableTypes:
if n.typ != nil and n.typ.kind in NilableTypes and
not (n.typ.kind == tyProc and a.typ.kind == tyProc):
# we allow compile-time 'cast' for pointer types:
result = a
result.typ = n.typ

View File

@@ -1,6 +1,7 @@
discard """
output: '''
Hello World
Hello World
Hello World'''
joinable: false
"""
@@ -8,7 +9,7 @@ type MyProc = proc() {.cdecl.}
type MyProc2 = proc() {.nimcall.}
type MyProc3 = proc() #{.closure.} is implicit
proc testProc() = echo "Hello World"
proc testProc() {.exportc:"foo".} = echo "Hello World"
template reject(x) = doAssert(not compiles(x))
@@ -23,6 +24,10 @@ proc callPointer(p: pointer) =
ffunc0()
ffunc1()
# bug #5901
proc foo() {.importc.}
(cast[proc(a: int) {.cdecl.}](foo))(5)
callPointer(cast[pointer](testProc))
reject: discard cast[enum](0)