This is the mail archive of the gcc@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]

Re: unassigned high priority bugs


On Thu, Jun 07, 2001 at 05:51:25PM +0100, Nathan Sidwell wrote:
> 2758 gcc 3.0 20010506 generates wrong code with -O2
> 	alphaev56-unknown-linux, I don't have access to one to even 
> 	investigate this

This is some sort of strict-aliasing problem.  That is, the test case
passes with -fno-strict-aliasing.  Since there is no untoward casting
in the source, the compiler is screwing up in assigning the alias sets.

Oh, and here's a reduced test case.


r~
typedef unsigned int uint;

struct QShared
{
    QShared() { count = 1; }
    void ref() { count++; }
    bool deref() { return !--count; }
    uint count;
};

template <class T>
class QValueListNode
{
public:
    QValueListNode( const T& t ) : data( t ) { }
    QValueListNode() { }
    QValueListNode<T>* next;
    QValueListNode<T>* prev;
    T data;
};

template<class T>
class QValueListIterator
{
 public:
    typedef QValueListNode<T>* NodePtr;
    NodePtr node;

    QValueListIterator() : node( 0 ) {}
    QValueListIterator( NodePtr p ) : node( p ) {}
    QValueListIterator( const QValueListIterator<T>& it ) : node( it.node ) {}

    bool operator==( const QValueListIterator<T>& it ) const
	{ return node == it.node; }
    bool operator!=( const QValueListIterator<T>& it ) const
	{ return node != it.node; }
    const T& operator*() const { return node->data; }
    T& operator*() { return node->data; }

    QValueListIterator<T>& operator++() {
        node = node->next;
        return *this;
    }

    QValueListIterator<T> operator++(int) {
        QValueListIterator<T> tmp = *this;
        node = node->next;
        return tmp;
    }
};

template <class T>
class QValueListPrivate : public QShared
{
public:
    typedef QValueListIterator<T> Iterator;
    typedef QValueListNode<T> Node;
    typedef QValueListNode<T>* NodePtr;

    QValueListPrivate() { node = new Node; node->next = node->prev = node; nodes = 0; }
    QValueListPrivate( const QValueListPrivate<T>& _p ) : QShared() {
        node = new Node; node->next = node->prev = node; nodes = 0;
        Iterator b( _p.node->next );
        Iterator e( _p.node );
        Iterator i( node );
        while( b != e )
            insert( i, *b++ );
    }

    void derefAndDelete()
    {
        if ( deref() )
            delete this;
    }

    ~QValueListPrivate() {
        NodePtr p = node->next;
        while( p != node ) {
            NodePtr x = p->next;
            delete p;
            p = x;
        }
        delete node;
    }

    Iterator insert( Iterator it, const T& x ) {
        NodePtr p = new Node( x );
        p->next = it.node;
        p->prev = it.node->prev;
        it.node->prev->next = p;
        it.node->prev = p;
        nodes++;
        return p;
    }

    NodePtr node;
    uint nodes;
};

template <class T>
class QValueList
{
public:
    typedef QValueListIterator<T> Iterator;
    typedef T ValueType;

    QValueList() { sh = new QValueListPrivate<T>; }
    QValueList( const QValueList<T>& l ) { sh = l.sh; sh->ref(); }
    ~QValueList() { sh->derefAndDelete(); }

    Iterator begin() { detach(); return Iterator( sh->node->next ); }
    Iterator end() { detach(); return Iterator( sh->node ); }

    Iterator append( const T& x ) { detach(); return sh->insert( end(), x ); }
    QValueList<T>& operator<< ( const T& x )
    {
        append( x );
        return *this;
    }

protected:
    void detach() { if ( sh->count > 1 ) { sh->deref(); sh = new QValueListPrivate<T>( *sh ); } }

    QValueListPrivate<T>* sh;
};

class QSplitter
{
public:
    QSplitter() {}
    ~QSplitter() {}

    void setSizes(QValueList<int>);

private:
    int dummy;
};


void QSplitter::setSizes( QValueList<int> list )
{
    QValueList<int>::Iterator it = list.begin();
    while (it != list.end() ) {
        dummy = *it;
        ++it;
    }
}

int main(void) {
    QSplitter *s1 = new QSplitter();

    QValueList<int> sizes;
    sizes << 50 << 50;
    s1->setSizes(sizes);

    return 0;
}

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