On 11/02/2013 07:52 PM, Ian Lance Taylor wrote:
On Sat, Nov 2, 2013 at 11:31 AM, Mischa Baars <mjbaars1...@gmail.com> wrote:
Here's the examples again, now each bug in a separate file. Hope it helps...

Just compile with 'make' and run the executable. The source code is
documented, so any questions you might have will probably be answered by
reading the comments.
Thanks for reporting issues with the compiler.  This code is short
enough that it would be simpler to just include the code inline in
your e-mail message.  For a case this short we don't need a makefile;
just put the command line showing the problem in e-mail.

Unfortunately your test case was not very clear.  I think you are
wondering why these two declarations

        uint64_t x = 1 << 31;
        uint64_t y = (uint64_t) 1 << 31;

do not produce the same values in x and y.  That is not a bug in GCC.
It's how the C language works.

In the first line, an integral constant without a suffix has type int.
Left shifting that int value by 31 still gives you a value of type
int.  On a system where int is 32 bits, converting a value of type to
a value of type uint64_t sign extends the int.
I understand, however it seems more logical to use the destination type to determine the type of the first and second operand.

Are you completely sure this is the desired behaviour?

In the second line, the value is already type uint64_t, and so left
shifting it and then assigning it to a variable of type uint64_t does
not do any sign extension.

Ian

Reply via email to