public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/25979]  New: incorrect codegen for conditional
@ 2006-01-26 17:29 hhinnant at apple dot com
  2006-01-26 17:31 ` [Bug c++/25979] " pinskia at gcc dot gnu dot org
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ messages in thread
From: hhinnant at apple dot com @ 2006-01-26 17:29 UTC (permalink / raw)
  To: gcc-bugs

I'm not positive whether or not this is a duplicate of 25895.  I figured I'd
better enter it just in case it wasn't.  Test case:

#include <stdio.h>

struct A
{
    A() : data1_(0), data2_(0) {}
    A(int i, int j) : data1_(i), data2_(j) {}
    A operator+(int);
    friend A operator+(int, const A&);
    ~A() {}
//private:
    int data1_;
    int data2_;
};

extern bool x;

void display(const A& x)
{
    printf("%d %d\n", x.data1_, x.data2_);
}

int main()
{
    A a1(1,2);
    a1 = (x ? a1 + 3 : 3 + a1);
    display(a1);
}

bool x = false;

A
A::operator+(int i)
{
    A a;
    a = *this;
    a.data2_ = i;
    return a;
}

A
operator+(int i, const A& x)
{
    A a;
    a = x;
    a.data1_ = i;
    return a;
}

Output:

3 0

Expected output:

3 2

The gimple tree (-fdump-tree-gimple) is showing statements like:

              operator+ (&a1, 3, &a1) [return slot addr];

which shoud instead be:

             operator+ (temp, 3, &a1) [return slot addr];
             ...
             a1 = temp;

The bad codegen is sensitive to the presence or absence of special member
functions.  For example if you comment out ~A(), you get the expected output.


-- 
           Summary: incorrect codegen for conditional
           Product: gcc
           Version: 4.0.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: hhinnant at apple dot com


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


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

end of thread, other threads:[~2006-02-11  0:51 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-01-26 17:29 [Bug c++/25979] New: incorrect codegen for conditional hhinnant at apple dot com
2006-01-26 17:31 ` [Bug c++/25979] " pinskia at gcc dot gnu dot org
2006-01-26 17:36 ` pinskia at gcc dot gnu dot org
2006-01-26 17:39 ` pinskia at gcc dot gnu dot org
2006-01-26 17:43 ` [Bug c++/25979] [4.0/4.1/4.2 Regression] incorrect codegen for conditional [SVO issue] pinskia at gcc dot gnu dot org
2006-01-26 18:17 ` pinskia at gcc dot gnu dot org
2006-01-27 20:09 ` jason at gcc dot gnu dot org
2006-02-01  3:08 ` mmitchel at gcc dot gnu dot org
2006-02-03 21:56 ` jason at gcc dot gnu dot org
2006-02-03 21:57 ` jason at gcc dot gnu dot org
2006-02-03 21:59 ` jason at gcc dot gnu dot org
2006-02-04 10:34 ` [Bug c++/25979] [4.0 " steven at gcc dot gnu dot org
2006-02-09  9:54 ` jason at gcc dot gnu dot org
2006-02-10 17:32 ` jason at gcc dot gnu dot org
2006-02-11  0:19 ` jason at gcc dot gnu dot org
2006-02-11  0:51 ` pinskia at gcc dot gnu dot org

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).