www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21038] New: Wrong codegen when calling wcslen


          Issue ID: 21038
           Summary: Wrong codegen when calling wcslen
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: tim.dlang t-online.de

The result of wcslen can be too low when compiling with dmd 2.093. Consider the
following two files:

//////////////////// testabcd.d ///////////////////
import core.stdc.stddef;
import core.stdc.stdio;
import core.stdc.wchar_;

const(wchar_t)* name = "abcd";

void test()
        size_t length = wcslen(name);
        printf("length: %zd\n", length);
        printf("data: \"");
        for(const(wchar_t)* s = name; *s; s++)
                printf("%c", *s);

//////////////////// testxyzw.d ///////////////////
import testabcd;

void main()

Running it results in the following output:
length: 3
data: "abcd"

The correct length would be 4. When compiling with ldc it works as expected.

The filenames are important. When testxyzw.d is renamed to testx.d it produces
the expected output.

Jul 11 2020