Bug 22252 – ImportC: Array, Function parameter types should be converted to pointers

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-08-30T04:01:53Z
Last change time
2021-09-07T22:52:05Z
Keywords
ImportC, pull
Assigned to
No Owner
Creator
mhh

Comments

Comment #0 by maxhaton — 2021-08-30T04:01:53Z
C arrays are being mapped to D arrays - This is not even wrong, as the saying goes. Let's say we have the following: --- int setAtOffset(int array[], unsigned int offset) { array[offset] = 4; } --- Which we then import into our D file and use in the following deliberately nonsensical example: --- void offsetTest() { setAtOffset(null, 3); } --- This yields the following asm 000000000000190c <_D6setjmp10offsetTestFZv>: 190c: push rbp 190d: mov rbp,rsp 1910: sub rsp,0x10 1914: mov edx,0x3 <- 1919: mov QWORD PTR [rbp-0x8],rdx <- 191d: xor edi,edi 191f: xor edx,edx 1921: mov rsi,rdx 1924: mov rdx,QWORD PTR [rbp-0x8] <- 1928: call 1938 <setAtOffset> Which is passing 3 into rdx, so as per SystemV it thinks it's the third parameter. Compare with GCC (exactly the same code, it's valid C): offsetTest: mov esi, 3 xor edi, edi jmp setAtOffset Similarly: pragma(msg, typeof(setAtOffset)); Yields: "extern (C) int(int[] array, uint offset)", which is wrong
Comment #1 by bugzilla — 2021-09-01T08:46:23Z
See C11 6.7.6.3-7 and 6.7.6.3-8
Comment #2 by dlang-bot — 2021-09-01T08:50:39Z
@WalterBright created dlang/dmd pull request #13036 "fix Issue 22252 - ImportC: Array, Function parameter types should be …" fixing this issue: - fix Issue 22252 - ImportC: Array, Function parameter types should be converted to pointers https://github.com/dlang/dmd/pull/13036
Comment #3 by dlang-bot — 2021-09-03T05:47:16Z
dlang/dmd pull request #13036 "fix Issue 22252 - ImportC: Array, Function parameter types should be …" was merged into stable: - 55b2fdc17ab0cb3d1527e60a6fe54ace607eeb18 by Walter Bright: fix Issue 22252 - ImportC: Array, Function parameter types should be converted to pointers https://github.com/dlang/dmd/pull/13036
Comment #4 by dlang-bot — 2021-09-07T22:52:05Z
dlang/dmd pull request #13053 "merge stable" was merged into master: - 5f6e4bd3a741e9d30833e82be90059fb9963f8cb by Walter Bright: fix Issue 22252 - ImportC: Array, Function parameter types should be converted to pointers https://github.com/dlang/dmd/pull/13053