This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/25979] New: incorrect codegen for conditional


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]