fixes#23665; rework spawn with gcc 14 and fixes other tests (#23660)

fixes #23665
This commit is contained in:
ringabout
2024-06-02 17:54:39 +08:00
committed by GitHub
parent de4c7dfdd9
commit 08f1eac8ac
3 changed files with 16 additions and 3 deletions

View File

@@ -109,6 +109,16 @@ stmtList:
"""
proc castToVoidPointer(g: ModuleGraph, n: PNode, fvField: PNode): PNode =
if g.config.backend == backendCpp:
result = fvField
else:
let ptrType = getSysType(g, n.info, tyPointer)
result = newNodeI(nkCast, fvField.info)
result.add newNodeI(nkEmpty, fvField.info)
result.add fvField
result.typ = ptrType
proc createWrapperProc(g: ModuleGraph; f: PNode; threadParam, argsParam: PSym;
varSection, varInit, call, barrier, fv: PNode;
idgen: IdGenerator;
@@ -156,8 +166,9 @@ proc createWrapperProc(g: ModuleGraph; f: PNode; threadParam, argsParam: PSym;
if barrier == nil:
# by now 'fv' is shared and thus might have beeen overwritten! we need
# to use the thread-local view instead:
let castExpr = castToVoidPointer(g, f, threadLocalProm.newSymNode)
body.add callCodegenProc(g, "nimFlowVarSignal", threadLocalProm.info,
threadLocalProm.newSymNode)
castExpr)
else:
body.add call
if barrier != nil:
@@ -413,7 +424,8 @@ proc wrapProcForSpawn*(g: ModuleGraph; idgen: IdGenerator; owner: PSym; spawnExp
# create flowVar:
result.add newFastAsgnStmt(fvField, callProc(spawnExpr[^1]))
if barrier == nil:
result.add callCodegenProc(g, "nimFlowVarCreateSemaphore", fvField.info, fvField)
let castExpr = castToVoidPointer(g, n, fvField)
result.add callCodegenProc(g, "nimFlowVarCreateSemaphore", fvField.info, castExpr)
elif spawnKind == srByVar:
var field = newSym(skField, getIdent(g.cache, "fv"), idgen, owner, n.info, g.config.options)

View File

@@ -4,6 +4,7 @@ discard """
# Test the new ``emit`` pragma:
{.emit: """
#include <stdio.h>
static int cvariable = 420;
""".}

View File

@@ -18,7 +18,7 @@ renderer.setDrawColor 29, 64, 153, 255
renderer.clear
renderer.setDrawColor 255, 255, 255, 255
when defined(c):
when false: # no long work with gcc 14!
# just to ensure code from NimInAction still works, but
# the `else` branch would work as well in C mode
var points = [