Bug 14131 – va_copy is broken on posix X86_64

Status
NEW
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2015-02-06T10:49:32Z
Last change time
2024-12-13T18:40:02Z
Keywords
pull, wrong-code
Assigned to
No Owner
Creator
yebblies
Moved to GitHub: dmd#17696 →

Comments

Comment #0 by yebblies — 2015-02-06T10:49:32Z
This code fails on posix X86_64 because va_copy doesn't properly copy the argument pointer, instead aliasing the original. void copya(int a, string format, ...) { va_list ap; va_start(ap, format); va_list ap2; va_copy(ap2, ap); auto a1 = va_arg!int(ap); auto a2 = va_arg!int(ap); auto a3 = va_arg!int(ap); assert(a1 == 0x11111111); assert(a2 == 0x22222222); assert(a3 == 0x33333333); auto b1 = va_arg!int(ap2); auto b2 = va_arg!int(ap2); auto b3 = va_arg!int(ap2); assert(b1 == 0x11111111); assert(b2 == 0x22222222); assert(b3 == 0x33333333); va_end(ap); va_end(ap2); } void testCopy() { copya(0, "", 0x11111111, 0x22222222, 0x33333333); }
Comment #1 by yebblies — 2015-02-06T10:56:29Z
Comment #2 by github-bugzilla — 2015-02-07T10:27:03Z
Commits pushed to master at https://github.com/D-Programming-Language/druntime https://github.com/D-Programming-Language/druntime/commit/ee94dbddf7700a5e5864d485e66002e31e6fa670 Partial fix for Issue 14131 - va_copy is broken on posix X86_64 https://github.com/D-Programming-Language/druntime/commit/02270ea991f4218764d2c2cc867c56f082672d4c Merge pull request #1158 from yebblies/va_copy Partial fix for Issue 14131 - va_copy is broken on posix X86_64
Comment #3 by yebblies — 2015-02-07T11:41:14Z
The partial fix makes the original test case work, but this one should still fail. void copyb(ref va_list ap2, va_list ap) { va_copy(ap2, ap); } void copya(int a, string format, ...) { va_list ap; va_start(ap, format); va_list ap2; copyb(ap2, ap); auto a1 = va_arg!int(ap); auto a2 = va_arg!int(ap); auto a3 = va_arg!int(ap); assert(a1 == 0x11111111); assert(a2 == 0x22222222); assert(a3 == 0x33333333); auto b1 = va_arg!int(ap2); auto b2 = va_arg!int(ap2); auto b3 = va_arg!int(ap2); assert(b1 == 0x11111111); assert(b2 == 0x22222222); assert(b3 == 0x33333333); va_end(ap); va_end(ap2); } void testCopy() { copya(0, "", 0x11111111, 0x22222222, 0x33333333); }
Comment #4 by github-bugzilla — 2015-02-07T11:48:56Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/143f780fa6d5fd692d25b8f8318c73f5722616b9 Add test case for Issue 14131 - va_copy is broken on posix X86_64 https://github.com/D-Programming-Language/dmd/commit/97f5400129a489b31f4378cf9a1776ba0debc4b3 Merge pull request #4385 from yebblies/va_copy Add test case for Issue 14131 - va_copy is broken on posix X86_64
Comment #5 by github-bugzilla — 2015-02-07T20:33:09Z
Comment #6 by github-bugzilla — 2015-02-07T20:38:29Z
Comment #7 by github-bugzilla — 2015-02-18T03:39:04Z
Comment #8 by bugzilla — 2020-11-08T06:12:51Z
Have all these commits fixed it? Does the problem remain?
Comment #9 by robert.schadek — 2024-12-13T18:40:02Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17696 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB