Bug 22976 – importC: fails to multiply by element size when doing address-of

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-04-03T05:27:14Z
Last change time
2022-04-18T06:19:43Z
Keywords
ImportC, pull, wrong-code
Assigned to
No Owner
Creator
duser

Attachments

IDFilenameSummaryContent-TypeSize
1846addrfix.patchfixtext/plain1043

Comments

Comment #0 by duser — 2022-04-03T05:27:14Z
struct S { unsigned short xs[2]; }; struct S s1 = { { 0xabcd, 0x1234 } }; struct S *sp = &s1; int printf(char *, ...); int main() { unsigned short *xp = &sp->xs[1]; printf("%hx\n", *xp); // 34ab unsigned short x = sp->xs[1]; printf("%hx\n", x); // 1234 return 0; } introduced in https://github.com/dlang/dmd/pull/13925
Comment #1 by bugzilla — 2022-04-05T07:54:59Z
Probably forgot to multiply by sizeof.
Comment #2 by duser — 2022-04-17T22:29:45Z
Created attachment 1846 fix attaching my patch i've been using that fixes this
Comment #3 by dlang-bot — 2022-04-18T05:21:20Z
@WalterBright created dlang/dmd pull request #14005 "fix Issue 22976 - importC: fails to multiply by element size when doi…" fixing this issue: - fix Issue 22976 - importC: fails to multiply by element size when doing address-of https://github.com/dlang/dmd/pull/14005
Comment #4 by dlang-bot — 2022-04-18T06:19:43Z
dlang/dmd pull request #14005 "fix Issue 22976 - importC: fails to multiply by element size when doi…" was merged into master: - 1f561d908198c96e62b899370d16f4b4588da05d by Walter Bright: fix Issue 22976 - importC: fails to multiply by element size when doing address-of https://github.com/dlang/dmd/pull/14005