www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21506] New: _argptr gives wrong address, depending on number

https://issues.dlang.org/show_bug.cgi?id=21506

          Issue ID: 21506
           Summary: _argptr gives wrong address, depending on number of
                    arguments before varargs
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: simon.vanbernem yahoo.de

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.

--
Dec 26 2020