Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 3

Qt-interest Archive, June 2007
Visual Studio 64-bit portability warnings


Message 1 in thread

I'm compiling with Visual Studio 2002, using Qt 4.3.0.

 

With 64-bit portability warnings turned on (/Wp64), I get the following
errors:

 

c:\Qt\4.3.0\src\corelib\arch\qatomic_windows.h(146): warning C4311:
'reinterpret_cast' : pointer truncation from 'void *' to 'long'

 

c:\Qt\4.3.0\src\corelib\arch\qatomic_windows.h(146): warning C4312:
'reinterpret_cast' : conversion from 'long' to 'void *' of greater size

 

I'd like to keep 64-bit warnings on, but...

 

Sam Dutton
 





SAM DUTTON
SENIOR SITE DEVELOPER

200 GRAY'S INN ROAD
LONDON
WC1X 8XZ
UNITED KINGDOM
T +44 (0)20 7430 4496
F 
E SAM.DUTTON@xxxxxxxxx
WWW.ITN.CO.UK
Please Note:

 

Any views or opinions are solely those of the author and do not necessarily represent 
those of Independent Television News Limited unless specifically stated. 
This email and any files attached are confidential and intended solely for the use of the individual
or entity to which they are addressed. 
If you have received this email in error, please notify postmaster@xxxxxxxxx 

Please note that to ensure regulatory compliance and for the protection of our clients and business,
we may monitor and read messages sent to and from our systems.

Thank You.


Message 2 in thread

There appear to be a lot of places where things like this need to be cleaned
up. At the very least, these are bugs in the 64-bit version. I get the same
warnings (errors if building 64-bit) in VS 2005. 'size_t' should be used
with pointer<->integer conversion, not 'long'.

Keith
**Please do not reply to me, reply to the list.**

On 06-12-2007 12:14 PM, "Dutton, Sam" wrote:

> I¹m compiling with Visual Studio 2002, using Qt 4.3.0.
>  
> With 64-bit portability warnings turned on (/Wp64), I get the following
> errors:
>  
> c:\Qt\4.3.0\src\corelib\arch\qatomic_windows.h(146): warning C4311:
> 'reinterpret_cast' : pointer truncation from 'void *' to 'long'
>  
> c:\Qt\4.3.0\src\corelib\arch\qatomic_windows.h(146): warning C4312:
> 'reinterpret_cast' : conversion from 'long' to 'void *' of greater size
>  
> I¹d like to keep 64-bit warnings on, but?
>  
> Sam Dutton
>  
> 
> SAM DUTTON
> SENIOR SITE DEVELOPER
> 
> 200 GRAY'S INN ROAD
> LONDON
> WC1X 8XZ
> UNITED KINGDOM
> T +44 (0)20 7430 4496
> F 
> E SAM.DUTTON@xxxxxxxxx
> WWW.ITN.CO.UK <http://WWW.ITN.CO.UK>
> 
> Please Note:
> 


Message 3 in thread

Hi,

> c:\Qt\4.3.0\src\corelib\arch\qatomic_windows.h(146): warning C4311: 
> 'reinterpret_cast' : pointer truncation from 'void *' to 'long'

What's exactly in line 146?

--
 [ signature omitted ] 

Message 4 in thread

On 06-12-2007 4:02 PM, "Dimitri" wrote:

> Hi,
> 
>> c:\Qt\4.3.0\src\corelib\arch\qatomic_windows.h(146): warning C4311:
>> 'reinterpret_cast' : pointer truncation from 'void *' to 'long'
> 
> What's exactly in line 146?
> 
> --
> Dimitri

LOL, of all people to ask... (Dimitri usually chides people for not looking
in the docs first, or in this case, the source code.)

Here is the relevant section of qatomic_windows.h:

> #  ifndef _M_IX86
> extern "C" {
>     void *_InterlockedCompareExchangePointer(void * volatile *, void *, void
> *);
>     void *_InterlockedExchangePointer(void * volatile *, void *);
> }
> #    pragma intrinsic (_InterlockedCompareExchangePointer)
> #    pragma intrinsic (_InterlockedExchangePointer)
> #  else
> #    define _InterlockedCompareExchangePointer(a,b,c) \
>         reinterpret_cast<void
> *>(_InterlockedCompareExchange(reinterpret_cast<volatile long *>(a),
> reinterpret_cast<long>(b), reinterpret_cast<long>(c)))
> #    define _InterlockedExchangePointer(a, b) \
>         reinterpret_cast<void
> *>(_InterlockedExchange(reinterpret_cast<volatile long *>(a),
> reinterpret_cast<long>(b)))
> #  endif
> 
> inline int q_atomic_test_and_set_int(volatile int *ptr, int expected, int
> newval)
> { return _InterlockedCompareExchange(reinterpret_cast<volatile long *>(ptr),
> newval, expected) == expected; }
> 
> inline int q_atomic_test_and_set_ptr(volatile void *ptr, void *expected, void
> *newval)
> { return _InterlockedCompareExchangePointer(reinterpret_cast<void * volatile
> *>(ptr), newval, expected) == expected; }

The #else case of the ifndef is used. Since pointers are being passed in,
size_t (or ptrdif_t)  should be used instead of long because size_t is
guaranteed to be (at least)  the same size as a pointer, long is not.

Keith
**Please do not reply to me, reply to the list.**


Message 5 in thread

Hi,

> LOL, of all people to ask... (Dimitri usually chides people for not 
> looking in the docs first, or in this case, the source code.)

The source code depends on the version, that's why I have to ask.

> Here is the relevant section of qatomic_windows.h:
> [...]

Actually what I need to know is what is in line 146.

--
 [ signature omitted ] 

Message 6 in thread

On 6/12/07, Dimitri <dimitri@xxxxxxxxxxxxx> wrote:
> Hi,
>
> > LOL, of all people to ask... (Dimitri usually chides people for not
> > looking in the docs first, or in this case, the source code.)
>
> The source code depends on the version, that's why I have to ask.

>> c:\Qt\4.3.0\src\corelib\arch\qatomic_windows.h(146): warning C4311:

I bet he's using 4.3.0.

-- 
 [ signature omitted ] 

Message 7 in thread

Hi,

> I bet he's using 4.3.0.

Actually I really need to know is what is in line 146.

My sources are directly from our version control system, files have different 
headers, therefore line numbering is different. Unfortunately I do not have 
the resources to install all versions of Qt on my computer.

--
 [ signature omitted ] 

Message 8 in thread

On 06-13-2007 12:31 AM, "Dimitri" wrote:

> Hi,
> 
>> I bet he's using 4.3.0.
> 
> Actually I really need to know is what is in line 146.
> 
> My sources are directly from our version control system, files have different
> headers, therefore line numbering is different. Unfortunately I do not have
> the resources to install all versions of Qt on my computer.
> 
> --
> Dimitri

I guess I just assumed you would have a reference copy of the shipping code.


Line 146:
{ return _InterlockedCompareExchangePointer(reinterpret_cast<void * volatile
*>(ptr), newval, expected) == expected; }

_InterlockedCompareExchangePointer is a #define (not an inline):

# define _InterlockedCompareExchangePointer(a,b,c) \
 reinterpret_cast<void*>(_InterlockedCompareExchange(reinterpret_cast<volati
le long *>(a),  reinterpret_cast<long>(b), reinterpret_cast<long>(c)))

These "long"s should be size_t.

Keith
**Please do not reply to me, reply to the list.**


Message 9 in thread

On 6/12/07, Dutton, Sam <Sam.Dutton@xxxxxxxxx> wrote:
>
> I'm compiling with Visual Studio 2002, using Qt 4.3.0.
>
> With 64-bit portability warnings turned on (/Wp64), I get the following errors:
>
> c:\Qt\4.3.0\src\corelib\arch\qatomic_windows.h(146): warning C4311: 'reinterpret_cast' : pointer truncation from 'void *' to 'long'
>
> c:\Qt\4.3.0\src\corelib\arch\qatomic_windows.h(146): warning C4312: 'reinterpret_cast' : conversion from 'long' to 'void *' of greater size
>
>
> I'd like to keep 64-bit warnings on, but…

I like to use warning level 4 /(/W4) with the MS compiler, but doing
so on a Qt project tends to generate hundreds or thousands of warnings
inside the Qt headers - which is worse than useless because it makes
it nearly impossible to see if there are any warnings about my code
amongst the spew. To eliminate these warnings (since I can't do
anything about them anyway), I put all my Qt includes inside a pragma
directive like so:

#pragma warning(push,1)
#include <QWidget>
#include <QDebug>
#pragma warning(pop)

Not sure if this will turn off the 64-bit warnings, but it's worth a try.

-- 
 [ signature omitted ] 

Message 10 in thread

what i did was patching qglobal.h ;)
add the line:
#pragma warning( disable : 4127 )

Cheers,
Peter

--
 [ signature omitted ] 

Message 11 in thread

>> 
#pragma warning(push,1)
#include <QWidget>
#include <QDebug>
#pragma warning(pop)
<<

Thanks (Andrew) for that.

Sam


 





SAM DUTTON
SENIOR SITE DEVELOPER

200 GRAY'S INN ROAD
LONDON
WC1X 8XZ
UNITED KINGDOM
T +44 (0)20 7430 4496
F 
E SAM.DUTTON@xxxxxxxxx
WWW.ITN.CO.UK

-----Original Message-----

From: Andrew Medico [mailto:a.medico@xxxxxxxxx] 
Sent: Tuesday 12 June 2007 23:27
To: qt-interest@xxxxxxxxxxxxx
Subject: Re: Visual Studio 64-bit portability warnings

On 6/12/07, Dutton, Sam <Sam.Dutton@xxxxxxxxx> wrote:
>
> I'm compiling with Visual Studio 2002, using Qt 4.3.0.
>
> With 64-bit portability warnings turned on (/Wp64), I get the
following errors:
>
> c:\Qt\4.3.0\src\corelib\arch\qatomic_windows.h(146): warning C4311:
'reinterpret_cast' : pointer truncation from 'void *' to 'long'
>
> c:\Qt\4.3.0\src\corelib\arch\qatomic_windows.h(146): warning C4312: 
> 'reinterpret_cast' : conversion from 'long' to 'void *' of greater 
> size
>
>
> I'd like to keep 64-bit warnings on, but...

I like to use warning level 4 /(/W4) with the MS compiler, but doing so
on a Qt project tends to generate hundreds or thousands of warnings
inside the Qt headers - which is worse than useless because it makes it
nearly impossible to see if there are any warnings about my code amongst
the spew. To eliminate these warnings (since I can't do anything about
them anyway), I put all my Qt includes inside a pragma directive like
so:

#pragma warning(push,1)
#include <QWidget>
#include <QDebug>
#pragma warning(pop)

Not sure if this will turn off the 64-bit warnings, but it's worth a
try.

--
 [ signature omitted ] 

Message 12 in thread

Apologies for not including the relevant code.

Here you go...

Code:
{ return _InterlockedCompareExchangePointer(reinterpret_cast<void *
volatile *>(ptr), newval, expected) == expected; }

Error:
c:\Qt\4.3.0\src\corelib\arch\qatomic_windows.h(146): warning C4312:
'reinterpret_cast' : conversion from 'long' to 'void *' of greater size

Sam


 





SAM DUTTON
SENIOR SITE DEVELOPER

200 GRAY'S INN ROAD
LONDON
WC1X 8XZ
UNITED KINGDOM
T +44 (0)20 7430 4496
F 
E SAM.DUTTON@xxxxxxxxx
WWW.ITN.CO.UK

-----Original Message-----

From: Dimitri [mailto:dimitri@xxxxxxxxxxxxx] 
Sent: Wednesday 13 June 2007 06:32
To: qt-interest@xxxxxxxxxxxxx
Subject: Re: Visual Studio 64-bit portability warnings

Hi,

> I bet he's using 4.3.0.

Actually I really need to know is what is in line 146.

My sources are directly from our version control system, files have
different headers, therefore line numbering is different. Unfortunately
I do not have the resources to install all versions of Qt on my
computer.

--
 [ signature omitted ] 

Message 13 in thread

Hi,

> Code:
> { return _InterlockedCompareExchangePointer(reinterpret_cast<void *
> volatile *>(ptr), newval, expected) == expected; }

OK, so this is function:
	q_atomic_test_and_set_ptr()

> Error:
> c:\Qt\4.3.0\src\corelib\arch\qatomic_windows.h(146): warning C4312:
> 'reinterpret_cast' : conversion from 'long' to 'void *' of greater size

As pointed out by Keith Esau, _InterlockedCompareExchangePointer() really is a 
macro which casts its arguments:
	void**, void*, void*
to:
	long*, long, long
before feeding them to the _InterlockedCompareExchange() intrinsic which 
according to MDSN:
	http://msdn2.microsoft.com/en-us/library/ttk2z1ws.aspx
indeed expects arguments of type:
	long*, long, long

I think the fix is more complicated than changing 'long' to 'size_t' as 
suggested by Keith. Rather Qt may have to use _InterlockedCompareExchange64().

Anyway, these warnings seem to be pointing to a real bug!

--
 [ signature omitted ] 

Message 14 in thread

But from the section included below, the problem only occurs when the
intrinsic functions are NOT used. The #else case is where the long arguments
need to be changed to size_t.

Keith
**Please do not reply to me, reply to the list.**

On 06-14-2007 3:33 PM, "Dimitri" wrote:

> Hi,
> 
>> Code:
>> { return _InterlockedCompareExchangePointer(reinterpret_cast<void *
>> volatile *>(ptr), newval, expected) == expected; }
> 
> OK, so this is function:
> q_atomic_test_and_set_ptr()
> 
>> Error:
>> c:\Qt\4.3.0\src\corelib\arch\qatomic_windows.h(146): warning C4312:
>> 'reinterpret_cast' : conversion from 'long' to 'void *' of greater size
> 
> As pointed out by Keith Esau, _InterlockedCompareExchangePointer() really is a
> macro which casts its arguments:
> void**, void*, void*
> to:
> long*, long, long
> before feeding them to the _InterlockedCompareExchange() intrinsic which
> according to MDSN:
> http://msdn2.microsoft.com/en-us/library/ttk2z1ws.aspx
> indeed expects arguments of type:
> long*, long, long
> 
> I think the fix is more complicated than changing 'long' to 'size_t' as
> suggested by Keith. Rather Qt may have to use _InterlockedCompareExchange64().
> 
> Anyway, these warnings seem to be pointing to a real bug!
> 
> --
> Dimitri

------ Forwarded Message

Here is the relevant section of qatomic_windows.h:

#  ifndef _M_IX86
extern "C" {
    void *_InterlockedCompareExchangePointer(void * volatile *, void *, void
*);
    void *_InterlockedExchangePointer(void * volatile *, void *);
}
#    pragma intrinsic (_InterlockedCompareExchangePointer)
#    pragma intrinsic (_InterlockedExchangePointer)
#  else
#    define _InterlockedCompareExchangePointer(a,b,c) \
        reinterpret_cast<void
*>(_InterlockedCompareExchange(reinterpret_cast<volatile long *>(a),
reinterpret_cast<long>(b), reinterpret_cast<long>(c)))
#    define _InterlockedExchangePointer(a, b) \
        reinterpret_cast<void
*>(_InterlockedExchange(reinterpret_cast<volatile long *>(a),
reinterpret_cast<long>(b)))
#  endif

inline int q_atomic_test_and_set_int(volatile int *ptr, int expected, int
newval)
{ return _InterlockedCompareExchange(reinterpret_cast<volatile long *>(ptr),
newval, expected) == expected; }

inline int q_atomic_test_and_set_ptr(volatile void *ptr, void *expected,
void 
*newval)
{ return _InterlockedCompareExchangePointer(reinterpret_cast<void * volatile
*>(ptr), newval, expected) == expected; }

 ------ End of Forwarded Message


--
 [ signature omitted ] 

Message 15 in thread

Hi,

> But from the section included below, the problem only occurs when the
> intrinsic functions are NOT used. The #else case is where the long arguments
> need to be changed to size_t.

Mmmh... Which intrinsic functions are we talking about?

I was referring to the following intrinsic functions:
	_InterlockedCompareExchange
	_InterlockedExchange
used in the following macro functions:
	_InterlockedCompareExchangePointer
	_InterlockedExchangePointer
which are all used within the "else" section.

I think you think I was referring to the following intrinsic functions:
	_InterlockedCompareExchangePointer
	_InterlockedExchangePointer
which are indeed not used within the "else" section.


--
 [ signature omitted ]