Apparent aliasing problem when optimizing
Zack Weinberg
zack@codesourcery.com
Thu Apr 10 05:51:00 GMT 2003
Marc Singer <elf@buici.com> writes:
> The function SendTo::sendto_folder() fails when the file is compiled
> with -Os optimization. The trouble is that the function *always*
> returns NULL when optimized. It's OK when -O0 optimization is
> applied. I've included the the assembler output as a comment near the
> function. It looks like the compiler only sees the initialization of
> psf with NULL and no explicit change. However, the BindToObject call
> will update psf if it succeeds.
Change
HRESULT result =
m_psfDesktop->BindToObject (pidl, __null, IID_IShellFolder, &(void*)psf);
to
HRESULT result =
m_psfDesktop->BindToObject (pidl, __null, IID_IShellFolder, (PVOID*)&psf);
and it should start working correctly. (Your code should get a
warning, or perhaps even a hard error - you're applying the & operator
to a cast to non-reference type, which is not an lvalue, so it's
invalid.)
I see several other places where the code contains the same mistake.
zw
More information about the Gcc-bugs
mailing list