public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/14449] New: long long & unsigned calculation gives wrong result
@ 2004-03-05 16:14 joerg dot richter at pdv-fs dot de
  2004-03-05 16:44 ` [Bug target/14449] " pinskia at gcc dot gnu dot org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: joerg dot richter at pdv-fs dot de @ 2004-03-05 16:14 UTC (permalink / raw)
  To: gcc-bugs

This program:

-----8<--------------
#include <stdio.h>

int main()
{
  unsigned int i = 2147483648u;
  long long k = ((long long)i) * 10;
  printf( "%lld\n", k );
  long long m = i;
  m = m * 10;
  printf( "%lld\n", m );
}

-----8<--------------

gives following output
-64424509440
21474836480

But I would expect (like on i686-pc-linux-gnu)
21474836480
21474836480

Confirmed with 
GCC 3.3.3
GCC 3.2.1
GCC 2.9-aix51-020209

g++ -v prints
Reading specs from /pdv/.tools/pkg/gcc/3.3.3/bin/../lib/gcc-lib/powerpc-ibm-
aix5.1.0.0/3.3.3/specs
Configured with: ../gcc-3.3.3/configure --prefix=/tools/pkg/gcc/3.3.3 --with-
ld=/bin/ld --with-as=/bin/as --enable-languages=c,c++
Thread model: aix
gcc version 3.3.3

-- 
           Summary: long long & unsigned calculation gives wrong result
           Product: gcc
           Version: 3.3.3
            Status: UNCONFIRMED
          Severity: critical
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: joerg dot richter at pdv-fs dot de
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: powerpc-ibm-aix5.1.0.0
  GCC host triplet: powerpc-ibm-aix5.1.0.0
GCC target triplet: powerpc-ibm-aix5.1.0.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14449


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug target/14449] long long & unsigned calculation gives wrong result
  2004-03-05 16:14 [Bug c++/14449] New: long long & unsigned calculation gives wrong result joerg dot richter at pdv-fs dot de
@ 2004-03-05 16:44 ` pinskia at gcc dot gnu dot org
  2004-03-05 23:08 ` dje at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-03-05 16:44 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|critical                    |normal
          Component|c++                         |target
           Keywords|                            |wrong-code


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14449


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug target/14449] long long & unsigned calculation gives wrong result
  2004-03-05 16:14 [Bug c++/14449] New: long long & unsigned calculation gives wrong result joerg dot richter at pdv-fs dot de
  2004-03-05 16:44 ` [Bug target/14449] " pinskia at gcc dot gnu dot org
@ 2004-03-05 23:08 ` dje at gcc dot gnu dot org
  2004-03-06  0:59 ` pinskia at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: dje at gcc dot gnu dot org @ 2004-03-05 23:08 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From dje at gcc dot gnu dot org  2004-03-05 23:07 -------
I think this is programmer error with respect to conversion and precedence
rules.  For instance, if I write ((long long)i) * 10ull, it produces the other
result.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14449


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug target/14449] long long & unsigned calculation gives wrong result
  2004-03-05 16:14 [Bug c++/14449] New: long long & unsigned calculation gives wrong result joerg dot richter at pdv-fs dot de
  2004-03-05 16:44 ` [Bug target/14449] " pinskia at gcc dot gnu dot org
  2004-03-05 23:08 ` dje at gcc dot gnu dot org
@ 2004-03-06  0:59 ` pinskia at gcc dot gnu dot org
  2004-03-06  1:18 ` schwab at suse dot de
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-03-06  0:59 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-03-06 00:59 -------
Not a bug so closing.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14449


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug target/14449] long long & unsigned calculation gives wrong result
  2004-03-05 16:14 [Bug c++/14449] New: long long & unsigned calculation gives wrong result joerg dot richter at pdv-fs dot de
                   ` (2 preceding siblings ...)
  2004-03-06  0:59 ` pinskia at gcc dot gnu dot org
@ 2004-03-06  1:18 ` schwab at suse dot de
  2004-03-07  3:17 ` [Bug middle-end/14449] " dje at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: schwab at suse dot de @ 2004-03-06  1:18 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From schwab at suse dot de  2004-03-06 01:18 -------
I don't agree.  (long long)i is required to be 2147483648LL since it is in the 
range of long long, and multiplying by 10 cannot lead to overflow. 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14449


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug middle-end/14449] long long & unsigned calculation gives wrong result
  2004-03-05 16:14 [Bug c++/14449] New: long long & unsigned calculation gives wrong result joerg dot richter at pdv-fs dot de
                   ` (3 preceding siblings ...)
  2004-03-06  1:18 ` schwab at suse dot de
@ 2004-03-07  3:17 ` dje at gcc dot gnu dot org
  2004-04-07  2:48 ` pinskia at gcc dot gnu dot org
  2004-11-28 21:07 ` roger at eyesopen dot com
  6 siblings, 0 replies; 8+ messages in thread
From: dje at gcc dot gnu dot org @ 2004-03-07  3:17 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From dje at gcc dot gnu dot org  2004-03-07 03:17 -------
Using -mcpu=powerpc produces the correct result.  The problem appears to be a
bug in expr.c:expand_expr_real() for MULT_EXPR case when umul_widen_optab does
not exist and smul_widen_optab does exist.  For the example, umulsidi3 does not
exist for POWER and common mode, so mulsidi3 is chosen, but the result is not
adjusted correctly (not adjusted at all) to account for unsigned..

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|target                      |middle-end


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14449


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug middle-end/14449] long long & unsigned calculation gives wrong result
  2004-03-05 16:14 [Bug c++/14449] New: long long & unsigned calculation gives wrong result joerg dot richter at pdv-fs dot de
                   ` (4 preceding siblings ...)
  2004-03-07  3:17 ` [Bug middle-end/14449] " dje at gcc dot gnu dot org
@ 2004-04-07  2:48 ` pinskia at gcc dot gnu dot org
  2004-11-28 21:07 ` roger at eyesopen dot com
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-04-07  2:48 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-04-07 02:48 -------
Was already confirmed.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
   Last reconfirmed|0000-00-00 00:00:00         |2004-04-07 02:48:51
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14449


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug middle-end/14449] long long & unsigned calculation gives wrong result
  2004-03-05 16:14 [Bug c++/14449] New: long long & unsigned calculation gives wrong result joerg dot richter at pdv-fs dot de
                   ` (5 preceding siblings ...)
  2004-04-07  2:48 ` pinskia at gcc dot gnu dot org
@ 2004-11-28 21:07 ` roger at eyesopen dot com
  6 siblings, 0 replies; 8+ messages in thread
From: roger at eyesopen dot com @ 2004-11-28 21:07 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From roger at eyesopen dot com  2004-11-28 21:07 -------
This bug is a duplicate of PR target/9348 that I fixed on mainline back in
February.  Although this isn't technically a regression, I'm currently
bootstrapping a regression testing a backport to the 3.4 branch for
consideration by the release manager.

*** This bug has been marked as a duplicate of 9348 ***

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE
   Target Milestone|---                         |4.0.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14449


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2004-11-28 21:07 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-05 16:14 [Bug c++/14449] New: long long & unsigned calculation gives wrong result joerg dot richter at pdv-fs dot de
2004-03-05 16:44 ` [Bug target/14449] " pinskia at gcc dot gnu dot org
2004-03-05 23:08 ` dje at gcc dot gnu dot org
2004-03-06  0:59 ` pinskia at gcc dot gnu dot org
2004-03-06  1:18 ` schwab at suse dot de
2004-03-07  3:17 ` [Bug middle-end/14449] " dje at gcc dot gnu dot org
2004-04-07  2:48 ` pinskia at gcc dot gnu dot org
2004-11-28 21:07 ` roger at eyesopen dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).