Bug 21506 – misalignment of _argptr for variadic functions

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2020-12-26T19:06:31Z
Last change time
2022-11-26T21:45:39Z
Keywords
pull, wrong-code
Assigned to
No Owner
Creator
simon.vanbernem

Comments

Comment #0 by simon.vanbernem — 2020-12-26T19:06:31Z
When compiling the following code with DMD v2.094.2-dirty: import core.stdc.stdio; import core.stdc.stdarg; extern(C++) void print(long a, va_list args){ vprintf("value: %d\n", args); } void proxy0(long a, long b, long c, long d, bool e, ...){ print(a, _argptr); } void proxy1(long d, bool e, ...){ print(d, _argptr); } void main(){ int var = -5; proxy0(1, 2, 3, 4, true, var); proxy1(4, true, var); } the program output is: value: 4 value: -5 when it should be: value: -5 value: -5 I get the expected behavior when compiling with ldc2. The behavior doesn't change if I remove the extern(C++) or use va_start() to pass a va_list to print instead of the _argptr, but this is most similar to my actual code so I left it this way.
Comment #1 by bugzilla — 2022-11-26T07:56:35Z
Should be aligned to STACKALIGN, not REGSIZE.
Comment #2 by dlang-bot — 2022-11-26T07:58:19Z
@WalterBright created dlang/dmd pull request #14654 "fix Issue 21506 - misalignment of _argptr for variadic functions" fixing this issue: - fix Issue 21506 - misalignment of _argptr for variadic functions https://github.com/dlang/dmd/pull/14654
Comment #3 by dlang-bot — 2022-11-26T21:45:39Z
dlang/dmd pull request #14654 "fix Issue 21506 - misalignment of _argptr for variadic functions" was merged into master: - 742cb9eb215efca7f549c0503472853fb3ddeb73 by Walter Bright: fix Issue 21506 - misalignment of _argptr for variadic functions https://github.com/dlang/dmd/pull/14654