[llvm-commits] [PATCH] Don't cast Win32 FILETIME structs to int64

Dimitry Andric dimitry at andric.com
Thu Aug 5 13:47:12 PDT 2010


Subject: Don't cast Win32 FILETIME structs to int64

According to the Microsoft documentation here:
http://msdn.microsoft.com/en-us/library/ms724284%28VS.85%29.aspx

this cast used in lib/System/Win32/Path.inc:

__int64 ft = *reinterpret_cast<__int64*>(&fi.ftLastWriteTime);

should not be done.  The documentation says: "Do not cast a pointer to a
FILETIME structure to either a ULARGE_INTEGER* or __int64* value because
it can cause alignment faults on 64-bit Windows."

When compiling with MinGW gcc 4.5.0, you also get some strict-aliasing
warnings about those casts:

In file included from lib/System/Path.cpp:262:0:
lib/System/Win32/Path.inc: In member function 'const llvm::sys::FileStatus* llvm::sys::PathWithStatus::getFileStatus(bool, std::string*) const':
lib/System/Win32/Path.inc:403:65: warning: dereferencing type-punned pointer will break strict-aliasing rules
lib/System/Win32/Path.inc: In member function 'bool llvm::sys::Path::setStatusInfoOnDisk(const llvm::sys::FileStatus&, std::string*) const':
lib/System/Win32/Path.inc:781:14: warning: dereferencing type-punned pointer will break strict-aliasing rules

Attached is a fix that uses the recommended ULARGE_INTEGER structure,
and fixes the strict-aliasing warnings as a side-effect.  Please review.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: fix-filetime-aliasing.diff
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20100805/6f81d013/attachment.ksh>


More information about the llvm-commits mailing list