I'm getting warning C4744 from the linker when building with LTCG. The
following sample reproduces it:

---------------------------
// Header.h
#include <xmmintrin.h>
class Vector;
extern const Vector ZeroVector;
class Vector
{
public:
Vector( float x_, float y_, float z_, float w_ ) : x(x_), y(y_), z(z_),
w(w_) {}

union
{
struct { float x, y, z, w; };
__m128 q;
};
};
---------------------------
// Source1.cpp
#include "Header.h"
const Vector ZeroVector( 0.0f, 0.0f, 0.0f, 0.0f );
---------------------------
// Source2.cpp
#include "Header.h"
#include <stdio.h>
void main()
{
printf( "%f\n", ZeroVector.x );
}
---------------------------

Is the warning erroneous? The compiler only emits it in LTCG builds - but
could it cause bad code generation in other configs? What's the correct
workaround here, the warning seems to go away only if I tag the declaration
of ZeroVector with __declspec( align(16) ). Should it be necessary in this
case though?

--
Andy

Re: C4744 - 'var' has different type in 'file1' and 'file2' by Doug

Doug
Sat Dec 08 14:52:45 PST 2007

On Sat, 8 Dec 2007 21:14:21 -0000, "Andrew McDonald"
<myrmecophagavir@no-spam-thanks.hotmail.com> wrote:

>I'm getting warning C4744 from the linker when building with LTCG. The
>following sample reproduces it:
>
>---------------------------
>// Header.h
>#include <xmmintrin.h>
>class Vector;
>extern const Vector ZeroVector;
>class Vector
>{
> public:
> Vector( float x_, float y_, float z_, float w_ ) : x(x_), y(y_), z(z_),
>w(w_) {}
>
> union
> {
> struct { float x, y, z, w; };
> __m128 q;
> };
>};
>---------------------------
>// Source1.cpp
>#include "Header.h"
>const Vector ZeroVector( 0.0f, 0.0f, 0.0f, 0.0f );
>---------------------------
>// Source2.cpp
>#include "Header.h"
>#include <stdio.h>
>void main()
>{
> printf( "%f\n", ZeroVector.x );
>}
>---------------------------
>
>Is the warning erroneous? The compiler only emits it in LTCG builds - but
>could it cause bad code generation in other configs? What's the correct
>workaround here, the warning seems to go away only if I tag the declaration
>of ZeroVector with __declspec( align(16) ). Should it be necessary in this
>case though?

Barring any differences in compiler options for source1 and source2, it
looks fine to me. Have you tried adding "extern" to your definition of
ZeroVector in source1.cpp? It should not be necessary, but it's harmless,
and it might help LTCG.

--
Doug Harrison
Visual C++ MVP

Re: C4744 - 'var' has different type in 'file1' and 'file2' by Andrew

Andrew
Mon Dec 10 15:06:22 PST 2007

"Doug Harrison [MVP]" <dsh@mvps.org> wrote...
> On Sat, 8 Dec 2007 21:14:21 -0000, "Andrew McDonald"
> <myrmecophagavir@no-spam-thanks.hotmail.com> wrote:
>
>> I'm getting warning C4744 from the linker when building with LTCG. The
>> following sample reproduces it:
>>
>> [Snip]
>>
>> Is the warning erroneous? The compiler only emits it in LTCG builds - but
>> could it cause bad code generation in other configs? What's the correct
>> workaround here, the warning seems to go away only if I tag the
>> declaration of ZeroVector with __declspec( align(16) ). Should it be
>> necessary in this case though?
>
> Barring any differences in compiler options for source1 and source2, it
> looks fine to me. Have you tried adding "extern" to your definition of
> ZeroVector in source1.cpp? It should not be necessary, but it's harmless,
> and it might help LTCG.

Thanks Doug, but it didn't help. The files can be added to a freshly created
empty Win32 project to create the repro, so no compilation differences. It
can be worked around by disabling that warning around the ZeroVector
declaration, but it's nasty to look at and a hack in cross-platform
situations.

Same thing happens in VS 2008 Beta 2 at least, I'll post it on Connect if it
really is a bug.

--
Andy



Re: C4744 - 'var' has different type in 'file1' and 'file2' by Doug

Doug
Mon Dec 10 20:57:06 PST 2007

On Mon, 10 Dec 2007 23:06:22 -0000, "Andrew McDonald"
<myrmecophagavir@no-spam-thanks.hotmail.com> wrote:

>"Doug Harrison [MVP]" <dsh@mvps.org> wrote...
>> On Sat, 8 Dec 2007 21:14:21 -0000, "Andrew McDonald"
>> <myrmecophagavir@no-spam-thanks.hotmail.com> wrote:
>>
>>> I'm getting warning C4744 from the linker when building with LTCG. The
>>> following sample reproduces it:
>>>
>>> [Snip]
>>>
>>> Is the warning erroneous? The compiler only emits it in LTCG builds - but
>>> could it cause bad code generation in other configs? What's the correct
>>> workaround here, the warning seems to go away only if I tag the
>>> declaration of ZeroVector with __declspec( align(16) ). Should it be
>>> necessary in this case though?
>>
>> Barring any differences in compiler options for source1 and source2, it
>> looks fine to me. Have you tried adding "extern" to your definition of
>> ZeroVector in source1.cpp? It should not be necessary, but it's harmless,
>> and it might help LTCG.
>
>Thanks Doug, but it didn't help. The files can be added to a freshly created
>empty Win32 project to create the repro, so no compilation differences. It
>can be worked around by disabling that warning around the ZeroVector
>declaration, but it's nasty to look at and a hack in cross-platform
>situations.
>
>Same thing happens in VS 2008 Beta 2 at least, I'll post it on Connect if it
>really is a bug.

I have a hard time imagining how this can be a legitimate bug that can only
be discovered at link-time under /LTCG. Not only that, the documentation
for __m128 says its alignment is 16 bytes, so your __declspec seems
redundant. Definitely post to Connect if you don't get a definite answer
here.

--
Doug Harrison
Visual C++ MVP