[Issue 5815] New: Using -O is causing wrong code to be generated for extern(C) method call.
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Apr 6 10:59:09 PDT 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5815
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
AssignedTo: nobody at puremagic.com
ReportedBy: opantm+spam at gmail.com
--- Comment #0 from opantm+spam at gmail.com 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;
import std.c.windows.windows;
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];
return;
}
}
static char[] GetDirectoryPath(string FilePath) {
char[] Copy = FilePath.dup;
uint Result = PathRemoveFileSpecA(Copy.ptr);
TrimToNull(Copy);
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
linked.
The version of DMD being used is 2.052. OS is Windows, and compiled with: "dmd
testfile.d shlwapi.lib (-O)".
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list