🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.bug
Article #263

gcc-2.1 code generation problem

#263
From: Joe Linoff
Date: Tue, 14 Apr 1992 22:37
79 lines
2061 bytes
* VERSION: g++ version 2.1

* SOURCE FILE: problem.cc

    =======================================================================
    #makefile
    C++=g++
    O=problem.o

    .cc.o:
	    $(C++) -c -g $*.cc

    problem: $O
	    $(C++) -o $@ $O

    // problem.cc
    #include <iostream.h>
    /*
	This program generates a seg fault on sun4s.
    */
    class Desc {
    public:
	int data;
    };
    class DescSeq {
    public:    // formerly private
	Desc** data;
	unsigned _allocated;
	unsigned _size;
    public:
	DescSeq(unsigned sz = 4) : _allocated(sz), _size(0) { 
	    data = new Desc*[_allocated];
	}
	Desc*& operator[](unsigned i);
	DescSeq& operator+=(Desc* p) { 
	    data[_size++] = p;
	    return *this;
	}
    };
    Desc*& DescSeq::operator[](unsigned i) {
	return data[i];
    }
    void doit(char val) {
	DescSeq vars;
	vars += new Desc;

	unsigned i = 0;

	vars.data[i]->data = val == '1' ? 0: 2;  // no seg fault
	vars[i]->data = val == '1' ? 0 : 1;  // no seg fault
	vars[i]->data = val == '1' ? 0 : 2;  // SEG FAULT when val is not '1'!!!

    }
    int main() {
	doit('1');  // no seg fault 
	doit('x');  // seq fault!!
	return 0;
    }
    =======================================================================

* COMMAND ARGUMENTS:

	g++ -c -g problem.cc
	g++ -o problem problem.o

*  tm.h and md

	tm.h -> ./config/tm-sparc.h
	md -> ./config/sparc.md

* MACHINE TYPE and O/S

	SPARCstation 2
	4.1.1

* DESCRIPTION OF INCORRECT BEHAVIOR:

    The expression parser seems to get confused and generates bad code.
    The program generates a seg fault when in input val is not '1'.
Technical Details
Message-ID: <9204142237.AA21750@dharna.crosscheck>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!dharna.UUCP!joe

Show Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!dharna.UUCP!joe
From: joe@dharna.UUCP (Joe Linoff)
Subject: gcc-2.1 code generation problem
Message-ID: <9204142237.AA21750@dharna.crosscheck>
Sender: gnulists@ai.mit.edu
Organization: GNUs Not Usenet
Distribution: gnu
Date: Tue, 14 Apr 1992 22:37:55 GMT
Approved: bug-g++@prep.ai.mit.edu
Lines: 81