Summary: Using -O is causing wrong code to be generated for
                    extern(C) method call.
           Product: D
           Version: unspecified
          Platform: x86_64
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD

--- Comment #0 from 2011-04-06 10:55:30 PDT ---
When attempting to call a Windows API function, PathRemoveFileSpecA, invalid
results are returned when using the -O compiler flag. When using the same file,
but without -O, the correct output is generated.

Test Case:

import std.stdio;

static const ushort MAX_PATH = 260;    
extern(C) BOOL PathRemoveFileSpecA(LPTSTR);    

static void TrimToNull(ref char[] String) {
    for(int i = 0; i < String.length; i++)
        if(String[i] == '\0') {
            String = String[0..i];    

static char[] GetDirectoryPath(string FilePath) {            
    char[] Copy = FilePath.dup;    
    uint Result = PathRemoveFileSpecA(Copy.ptr);
    return Copy;

int main(string[] args) {
    string Path = "D:\\Test Path\\Test.exe";
    auto Dir = GetDirectoryPath(Path);
    writefln("Dir: " ~ Dir);    
    return 0;

Output without -O: "Dir: D:\Test Path"
Output with -O: "object.Error: Access Violation"

For this particular example, shlwapi.lib must be generated with Implib.exe and

The version of DMD being used is 2.052. OS is Windows, and compiled with: "dmd
testfile.d shlwapi.lib (-O)".

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to