[backport] fixes #23796; remove extra indirection for args in importc'ed functions in cpp (#23800)

fixes #23796
This commit is contained in:
Alexander Kernozhitsky
2024-07-06 23:10:15 +02:00
committed by GitHub
parent ce75042a9d
commit 1dcc364cd2
2 changed files with 27 additions and 1 deletions

View File

@@ -346,7 +346,8 @@ proc genArg(p: BProc, n: PNode, param: PSym; call: PNode; result: var Rope; need
let callee = call[0]
if callee.kind == nkSym and
{sfImportc, sfInfixCall, sfCompilerProc} * callee.sym.flags == {sfImportc} and
{lfHeader, lfNoDecl} * callee.sym.loc.flags != {}:
{lfHeader, lfNoDecl} * callee.sym.loc.flags != {} and
needsIndirect:
addAddrLoc(p.config, a, result)
else:
addRdLoc(a, result)

25
tests/ccgbugs/t23796.nim Normal file
View File

@@ -0,0 +1,25 @@
discard """
targets: "c cpp"
"""
# bug #23796
{.emit: """
#ifdef __cplusplus
extern "C" {
#endif
void fooArr(float data[3]) {}
void fooIntArr(int id, float data[3]) {}
#ifdef __cplusplus
}
#endif
""".}
proc fooArr(data: var array[3, cfloat]) {.importc.}
proc fooIntArr(id: cint, data: var array[3, cfloat]) {.importc, nodecl.}
var arr = [cfloat 1, 2, 3]
fooArr(arr)
fooIntArr(1, arr)