[gnu.g++.bug] bug report -- fatal signal received

baud@GATECH.EDU (Kurt Baudendistel) (09/27/88)

BUG REPORT 11

BEHAVIOR:

fatal signal 4 received.

COMPILER VERSION: GNU C++ compiler driver, version 1.25.0

INPUT FILES:

Fix16Complex.cc
Fix16Complex.h
Fix.h

COMMAND LINE: g++ -v -g -c Fix16Complex.cc 

g++ version 1.25.0
-cpp+ -v -I . -I ./include -I /dsp/mcclellan/baud/c++/include -I /usr/local/lib/g++-include -undef -D__GNU__ -D__GNUG__ -Dvax -Dunix Fix16Complex.cc /tmp/cc002528.cpp
GNU CPP version 1.25.0
 /usr/local/lib/gcc-c++ /tmp/cc002528.cpp -quiet -dumpbase Fix16Complex.cc -noreg -version -G -o /tmp/cc002528.s
In function Fix16Complex::Fix16Complex (struct Fix16, struct Fix16 (=  0 )):
./Fix16Complex.h:73: warning: function with large aggregate parameter cannot be inline
In function operator == (struct Fix16Complex &, struct Fix16):
./Fix16Complex.h:96: warning: function with large aggregate parameter cannot be inline
In function operator != (struct Fix16Complex &, struct Fix16):
./Fix16Complex.h:106: warning: function with large aggregate parameter cannot be inline
Failed assertion (((type)->common.code) != RECORD_TYPE || !((type)->classtype.type_flags.gets_init_ref_attr)) at line 1803 of `typecheck.c'.
g++: Program c++ got fatal signal 4.

FILE NAMES:

tm.h = tm-vax.h
md = vax.md

MACHINE: vax 11/780 with BRL UNIX (4.2 BSD)

SOURCE FILES:
----------------------------------------------------------------------------
/*
*  Fix16Complex.cc : prototypable complex class library source
*/

#include <Fix16Complex.h>

// error handling

void default_Fix16Complex_error_handler(char* msg)
{
  cerr << "Fatal Fix16Complex arithmetic error. " << msg << "\n";
  exit(1);
}

one_arg_error_handler_t 
  Fix16Complex_error_handler = default_Fix16Complex_error_handler;

one_arg_error_handler_t set_Fix16Complex_error_handler(one_arg_error_handler_t f)
{
  one_arg_error_handler_t old = Fix16Complex_error_handler;
  Fix16Complex_error_handler = f;
  return old;
}

void Fix16Complex::error(char* msg)
{
  (*Fix16Complex_error_handler)(msg);
}


Fix16Complex operator / (Fix16Complex& x, Fix16Complex& y)
{
  Fix16 den = norm(y);
  if (den == 0.0)
    x.error ("Attempted division by zero.");
  return Fix16Complex((x.re * y.re + x.im * y.im) / den, 
                 (x.im * y.re - x.re * y.im) / den);
}

Fix16Complex& Fix16Complex::operator /= (Fix16Complex& y)
{
  Fix16 den = norm(y);
  if (den == 0.0)
    error ("Attempted division by zero.");
  Fix16 r = (re * y.re + im * y.im) / den;
  Fix16 i = (im * y.re - re * y.im) / den;
  re = r;
  im = i;
  return *this;
}

ostream& operator << (ostream& s, Fix16Complex& x)
{
  return s << "(" << x.re << ", " << x.im << ")" ;
}

istream& operator >> (istream& s, Fix16Complex& x)
{
  char ch;
  s >> WS;
  s.get(ch);
  if (ch == '(')
  {
    s >> x.re;
    s >> WS;
    s.get(ch);
    if (ch == ',')
    {
      s >> x.im;
      s >> WS;
      s.get(ch);
    }
    else
      x.im = 0;
    if (ch != ')')
      s.error();
  }
  else
  {
    s.unget(ch);
    s >> x.re;
    x.im = 0;
  }
  return s;
}
 
----------------------------------------------------------------------------
//
// Fix16Complex.h : prototypable complex class
//

#ifndef _Fix16Complex_h
#define _Fix16Complex_h 1

#include <stream.h>
#include <std.h>
#include <Fix.h>

class Fix16Complex
{
  Fix16              re;
  Fix16              im;

public:
                   Fix16Complex();
                   Fix16Complex(Fix16Complex& c);
                   Fix16Complex(Fix16 r, Fix16 i = 0.0);

                   ~Fix16Complex();

  Fix16Complex&      operator =  (Fix16Complex& y);

  friend int       operator == (Fix16Complex& x, Fix16Complex& y);
  friend int       operator == (Fix16Complex& x, Fix16 y);

  friend int       operator != (Fix16Complex& x, Fix16Complex& y);
  friend int       operator != (Fix16Complex& x, Fix16 y);

  Fix16Complex       operator +  ();
  Fix16Complex       operator -  ();
  Fix16Complex       operator ~  ();

  friend Fix16Complex   operator +  (Fix16Complex& x, Fix16Complex& y);
  friend Fix16Complex   operator -  (Fix16Complex& x, Fix16Complex& y);
  friend Fix16Complex   operator *  (Fix16Complex& x, Fix16Complex& y);
  friend Fix16Complex   operator /  (Fix16Complex& x, Fix16Complex& y);

  Fix16Complex&         operator += (Fix16Complex& y); 
  Fix16Complex&         operator -= (Fix16Complex& y); 
  Fix16Complex&         operator *= (Fix16Complex& y); 
  Fix16Complex&         operator /= (Fix16Complex& y); 

  friend Fix16&   real(Fix16Complex& x);
  friend Fix16&   imag(Fix16Complex& x);
  friend Fix16    norm(Fix16Complex& x);

  friend istream&  operator >> (istream& s, Fix16Complex& x);
  friend ostream&  operator << (ostream& s, Fix16Complex& x);

  void             error(char* msg);
};

// error handlers

extern  void default_Fix16Complex_error_handler(char*);
extern  one_arg_error_handler_t Fix16Complex_error_handler;

extern  one_arg_error_handler_t 
        set_Fix16Complex_error_handler(one_arg_error_handler_t f);

//#ifdef __OPTIMIZE__

inline Fix16Complex:: Fix16Complex() {}
inline Fix16Complex::~Fix16Complex() {}

inline Fix16Complex::Fix16Complex(Fix16 r, Fix16 i = 0.0)
{
  re = r;
  im = i;
}

inline Fix16Complex::Fix16Complex(Fix16Complex& x)
{
  re = x.re;
  im = x.im;
}

inline Fix16Complex& Fix16Complex::operator = (Fix16Complex& x)
{
  re = x.re;
  im = x.im;
  return *this;
}

inline int operator == (Fix16Complex& x, Fix16Complex& y)
{
  return x.re == y.re && x.im == y.im;
}

inline int operator == (Fix16Complex& x, Fix16 y)
{
  return x.im == 0.0 && x.re == y;
}

inline int operator != (Fix16Complex& x, Fix16Complex& y)
{
  return x.re != y.re || x.im != y.im;
}

inline int operator != (Fix16Complex& x, Fix16 y)
{
  return x.im != 0.0 || x.re != y;
}

inline Fix16Complex Fix16Complex::operator + ()
{
  return *this;
}

inline Fix16Complex Fix16Complex::operator - ()
{
  return Fix16Complex(-re, -im);
}

inline Fix16Complex Fix16Complex::operator ~ ()
{
  return Fix16Complex(re, -im);
}

inline Fix16Complex operator + (Fix16Complex& x, Fix16Complex& y)
{
  return Fix16Complex(x.re + y.re, x.im + y.im);
}

inline Fix16Complex operator - (Fix16Complex& x, Fix16Complex& y)
{
  return Fix16Complex(x.re - y.re, x.im - y.im);
}

inline Fix16Complex operator * (Fix16Complex& x, Fix16Complex& y)
{
  return Fix16Complex(x.re * y.re - x.im * y.im, x.re * y.im + x.im * y.re);
}

inline Fix16Complex& Fix16Complex::operator += (Fix16Complex& y)
{
  re += y.re;
  im += y.im;
  return *this;
}

inline Fix16Complex& Fix16Complex::operator -= (Fix16Complex& y)
{
  re -= y.re;
  im -= y.im;
  return *this;
}

inline Fix16Complex& Fix16Complex::operator *= (Fix16Complex& y)
{
  Fix16 r = re * y.re - im * y.im;
  im = re * y.im + im * y.re;
  re = r;
  return *this;
}

inline Fix16& real(Fix16Complex& x)
{
  return x.re;
}

inline Fix16& imag(Fix16Complex& x)
{
  return x.im;
}

inline Fix16 norm(Fix16Complex& x)
{
  return (x.re * x.re + x.im * x.im);
}

//#endif

#endif
----------------------------------------------------------------------------
// This may look like C code, but it is really -*- C++ -*-
/* 
Copyright (C) 1988 Free Software Foundation
    written by Kurt Baudendistel (gt-eedsp!baud@gatech.edu)
    adapted for libg++ by Doug Lea (dl@rocky.oswego.edu)

This file is part of GNU CC.

GNU CC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.  No author or distributor
accepts responsibility to anyone for the consequences of using it
or for whether it serves any particular purpose or works at all,
unless he says so in writing.  Refer to the GNU CC General Public
License for full details.

Everyone is granted permission to copy, modify and redistribute
GNU CC, but only under the conditions described in the
GNU CC General Public License.   A copy of this license is
supposed to have been given to you along with GNU CC so you
can know your rights and responsibilities.  It should be in a
file named COPYING.  Among other things, the copyright notice
and this notice must be preserved on all copies.  
*/

#ifndef _Fix_h
#define _Fix_h 1

#include <stream.h>
#include <std.h>

// constant definitions

#define Fix16_fs 	((double)((unsigned)(1 << 15)))

#define Fix16_msb	(1 << 15)
#define Fix16_m_max	((1 << 15) - 1)
#define Fix16_m_min	((short)(1 << 15))

#define Fix16_mult	Fix16_fs
#define Fix16_div	(1./Fix16_fs)
#define Fix16_max	(1. - .5/Fix16_fs)
#define Fix16_min	(-1.)


#define Fix32_fs 	((double)((unsigned long)(1 << 31)))

#define Fix32_msb	((unsigned long)(1 << 31))
#define Fix32_m_max	((1 << 31) - 1)
#define Fix32_m_min	((long)(1 << 31))

#define Fix32_mult	Fix32_fs
#define Fix32_div	(1./Fix32_fs)
#define Fix32_max	(1. - .5/Fix32_fs)
#define Fix32_min	(-1.)


//
// Fix16    class: 16-bit Fixed point data type
//
//	consists of a 16-bit mantissa (sign bit & 15 data bits).
//

class Fix16 
{ 
  friend class          Fix32;

  short                 m;

  short                 round(double d);
  short                 assign(double d);
                        Fix16(short i);
                        Fix16(int i);

  double operator       double();

public:
                        Fix16();
                        Fix16(Fix16&  f);
                        Fix16(double d);
                        Fix16(Fix32& f);

                        ~Fix16();

  Fix16&                operator=(Fix16&  f);
  Fix16&                operator=(double d);
  Fix16&                operator=(Fix32& f);

  friend short&         mantissa(Fix16&  f);
  friend double         value(Fix16&  f);

  Fix16                 operator +  ();
  Fix16                 operator -  ();

  friend Fix16          operator +  (Fix16&  f, Fix16&  g);
  friend Fix16          operator -  (Fix16&  f, Fix16&  g);
  friend Fix32          operator *  (Fix16&  f, Fix16&  g);
  friend Fix16          operator /  (Fix16&  f, Fix16&  g);
  friend Fix16          operator << (Fix16&  f, int b);
  friend Fix16          operator >> (Fix16&  f, int b);

  Fix16&                operator += (Fix16&  f);
  Fix16&                operator -= (Fix16&  f);
  Fix16&                operator *= (Fix16& );
  Fix16&                operator /= (Fix16&  f);
  
  Fix16&                operator <<=(int b);
  Fix16&                operator >>=(int b);

  friend int            operator == (Fix16&  f, Fix16&  g);
  friend int            operator != (Fix16&  f, Fix16&  g);
  friend int            operator >= (Fix16&  f, Fix16&  g);
  friend int            operator <= (Fix16&  f, Fix16&  g);
  friend int            operator >  (Fix16&  f, Fix16&  g);
  friend int            operator <  (Fix16&  f, Fix16&  g);

  friend istream&       operator >> (istream& s, Fix16&  f);
  friend ostream&       operator << (ostream& s, Fix16&  f);

  void                  overflow(short&);
  void                  saturation_error(short&);
};

 
//
// Fix32 class: 32-bit Fixed point data type
//
//	consists of a 32-bit mantissa (sign bit & 31 data bits).
//

class Fix32 
{ 
  friend class         Fix16;

  long                 m;

  long                 round(double d);
  long                 assign(double d);
                       Fix32(long i);
  double               operator double();

public:
                       Fix32();
                       Fix32(Fix32& f);
                       Fix32(Fix16&  f);
                       Fix32(double d);
                       ~Fix32();

  Fix32&               operator =  (Fix32& f);
  Fix32&               operator =  (Fix16&  f);
  Fix32&               operator =  (double d);

  friend long&         mantissa(Fix32& f);
  friend double        value(Fix32& f);

  friend long          round(Fix32& f);

  Fix32                operator +  ();
  Fix32                operator -  ();

  friend Fix32         operator +  (Fix32& f, Fix32& g);
  friend Fix32         operator -  (Fix32& f, Fix32& g);
  friend Fix32         operator *  (Fix32& f, Fix32& g);
  friend Fix32         operator /  (Fix32& f, Fix32& g);
  friend Fix32         operator << (Fix32& f, int b);
  friend Fix32         operator >> (Fix32& f, int b);

  Fix32&               operator += (Fix32& f);
  Fix32&               operator -= (Fix32& f);
  Fix32&               operator *= (Fix32& f);
  Fix32&               operator /= (Fix32& f);
  Fix32&               operator <<=(int b);
  Fix32&               operator >>=(int b);

  friend int           operator == (Fix32& f, Fix32& g);
  friend int           operator != (Fix32& f, Fix32& g);
  friend int           operator >= (Fix32& f, Fix32& g);
  friend int           operator <= (Fix32& f, Fix32& g);
  friend int           operator >  (Fix32& f, Fix32& g);
  friend int           operator <  (Fix32& f, Fix32& g);

  friend istream&      operator >> (istream& s, Fix32& f);
  friend ostream&      operator << (ostream& s, Fix32& f);

  void                 overflow(long& i);
  void                 saturation_error(long& i);
};

inline Fix16::~Fix16() {}

inline short Fix16::round(double d)
{ 
  return (d >= 0)? d + 0.5 : d - 0.5; 
}

inline Fix16::Fix16(short i)		
{ 
  m = i; 
}

inline Fix16::Fix16(int i)	    
{ 
  m = i; 
}

inline double Fix16::operator double() 
{ 
  return  Fix16_div * m; 
}

inline Fix16::Fix16()     			
{ 
  m = 0; 
}

inline Fix16::Fix16(Fix16&  f)		
{ 
  m = f.m; 
}

inline Fix16::Fix16(double d)		
{
  m = assign(d);
}

inline Fix16::Fix16(Fix32& f)		
{ 
  m = f.m >> 16; 
}

inline Fix16&  Fix16::operator=(Fix16&  f)	
{ 
  m = f.m; 
  return *this; 
}

inline Fix16&  Fix16::operator=(double d) 
{ 
  m = assign(d); 
  return *this; 
}

inline Fix16&  Fix16::operator=(Fix32& f)
{ 
  m = f.m >> 16; 
  return *this; 
}

inline short& mantissa(Fix16&  f)	
{ 
  return f.m; 
}

inline double value(Fix16&  f)		
{ 
  return double(f); 
}

inline Fix16 Fix16::operator+() 		
{ 
  return m; 
}

inline Fix16 Fix16::operator-() 		
{ 
  return -m; 
}

inline Fix16 operator+(Fix16&  f, Fix16&  g) 
{
  short sum = f.m + g.m;
  if ( (f.m ^ sum) & (g.m ^ sum) & Fix16_msb )
    f.overflow(sum);
  return sum;
}

inline Fix16 operator-(Fix16&  f, Fix16&  g) 
{
  short sum = f.m - g.m;
  if ( (f.m ^ sum) & (-g.m ^ sum) & Fix16_msb )
    f.overflow(sum);
  return sum;
}

inline Fix32 operator*(Fix16&  f, Fix16&  g)
{ 
  return long(f.m) * long(g.m) << 1; 
}

inline Fix16 operator<<(Fix16& a, int b) 	
{ 
  return a.m << b; 
}

inline Fix16 operator>>(Fix16& a, int b) 	
{ 
  return a.m >> b; 
}

inline  Fix16&  Fix16:: operator+=(Fix16&  f)
{ 
  return *this = *this + f; 
}

inline Fix16&  Fix16:: operator-=(Fix16&  f) 	
{ 
  return *this = *this - f; 
}

inline Fix16& Fix16::operator*=(Fix16& f) 	
{ 
  return *this = *this * f; 
}

inline Fix16&  Fix16:: operator/=(Fix16&  f) 	
{ 
  return *this = *this / f; 
}

inline Fix16&  Fix16:: operator<<=(int b)	
{ 
  return *this = *this << b;
}

inline Fix16&  Fix16:: operator>>=(int b)	
{ 
  return *this = *this >> b;
}

inline int operator==(Fix16&  f, Fix16&  g)	
{ 
  return f.m == g.m;
}

inline int operator!=(Fix16&  f, Fix16&  g)	
{ 
  return f.m != g.m;
}

inline int operator>=(Fix16&  f, Fix16&  g)	
{ 
  return f.m >= g.m;
}

inline int operator<=(Fix16&  f, Fix16&  g)	
{ 
  return f.m <= g.m;
}

inline int operator>(Fix16&  f, Fix16&  g)	
{ 
  return f.m > g.m;
}

inline int operator<(Fix16&  f, Fix16&  g)	
{ 
  return f.m < g.m;
}

inline istream&  operator>>(istream& s, Fix16&  f)
{ 
  double d;
  s >> d; 
  f = d; 
  return s; 
}

inline ostream&  operator<<(ostream& s, Fix16&  f)
{ 
  return s << double(f);
}

inline Fix32::~Fix32() {}

inline long Fix32::round(double d)
{ 
  return (d >= 0)? d + 0.5 : d - 0.5;
}

inline Fix32::Fix32(long i)		
{ 
  m = i;
}

inline double Fix32:: operator double()		
{ 
  return Fix32_div * m;
}

inline Fix32::Fix32()			    
{ 
  m = 0;
}

inline Fix32::Fix32(Fix32& f)		
{ 
  m = f.m;
}

inline Fix32::Fix32(Fix16&  f)    
{ 
  m = long(f.m) << 16;
}

inline Fix32::Fix32(double d)		
{ 
  m = assign(d);
}

inline Fix32& Fix32::operator=(Fix32& f)	
{ 
  m = f.m;
  return *this; 
}

inline Fix32& Fix32::operator=(Fix16&  f)	
{ 
  m = long(f.m) << 16;
  return *this;
}

inline Fix32& Fix32::operator=(double d)	
{ 
  m = assign(d);
  return *this; 
}

inline long& mantissa(Fix32& f)	
{ 
  return f.m;
}

inline double value(Fix32& f)		
{ 
  return double(f);
}

inline Fix32 Fix32::operator+() 		
{ 
  return m;
}

inline Fix32 Fix32::operator-() 		
{ 
  return -m;
}

inline Fix32 operator+(Fix32& f, Fix32& g) 
{
  long sum = f.m + g.m;
  if ( (f.m ^ sum) & (g.m ^ sum) & Fix32_msb )
    f.overflow(sum);
  return sum;
}

inline Fix32 operator-(Fix32& f, Fix32& g) 
{
  long sum = f.m - g.m;
  if ( (f.m ^ sum) & (-g.m ^ sum) & Fix32_msb )
    f.overflow(sum);
  return sum;
}

inline Fix32 operator<<(Fix32& a, int b) 	
{ 
  return a.m << b;
}

inline Fix32 operator>>(Fix32& a, int b) 	
{ 
  return a.m >> b;
}

inline Fix32& Fix32::operator+=(Fix32& f) 	
{ 
  return *this = *this + f;
}

inline Fix32& Fix32::operator-=(Fix32& f) 	
{ 
  return *this = *this - f;
}

inline Fix32& Fix32::operator*=(Fix32& f) 	
{ 
  return *this = *this * f;
}

inline Fix32& Fix32::operator/=(Fix32& f) 	
{ 
  return *this = *this / f;
}


inline Fix32& Fix32::operator<<=(int b)	
{ 
  return *this = *this << b;
}

inline Fix32& Fix32::operator>>=(int b)	
{ 
  return *this = *this >> b;
}

inline int operator==(Fix32& f, Fix32& g)	
{ 
  return f.m == g.m;
}

inline int operator!=(Fix32& f, Fix32& g)	
{ 
  return f.m != g.m;
}

inline int operator>=(Fix32& f, Fix32& g)	
{ 
  return f.m >= g.m;
}

inline int operator<=(Fix32& f, Fix32& g)	
{ 
  return f.m <= g.m;
}

inline int operator>(Fix32& f, Fix32& g)	
{ 
  return f.m > g.m;
}

inline int operator<(Fix32& f, Fix32& g)	
{ 
  return f.m < g.m;
}

inline istream& operator>>(istream& s, Fix32& f)
{ 
  double d;
  s >> d; 
  f = d; 
  return s; 
}

inline ostream& operator<<(ostream& s, Fix32& f)
{ 
  return s << double(f);
}


// active error handler declarations

typedef void (*Fix16_peh)(short&);
typedef void (*Fix32_peh)(long&);

extern Fix16_peh Fix16_overflow_handler;
extern Fix32_peh Fix32_overflow_handler;

extern Fix16_peh Fix16_saturation_error_handler;
extern Fix32_peh Fix32_saturation_error_handler;


// error handler declarations

overload set_overflow_handler;
extern Fix16_peh set_overflow_handler(Fix16_peh);
extern Fix32_peh set_overflow_handler(Fix32_peh);
extern void set_overflow_handler(Fix16_peh, Fix32_peh);

overload set_saturation_error_handler;
extern Fix16_peh set_saturation_error_handler(Fix16_peh);
extern Fix32_peh set_saturation_error_handler(Fix32_peh);
extern void set_saturation_error_handler(Fix16_peh, Fix32_peh);

extern void
  Fix16_ignore(short&),
  Fix16_overflow_saturate(short&),
  Fix16_overflow_warning_saturate(short&),
  Fix16_warning(short&),
  Fix16_abort(short&);

extern void
  Fix32_ignore(long&),
  Fix32_overflow_saturate(long&),
  Fix32_overflow_warning_saturate(long&),
  Fix32_warning(long&),
  Fix32_abort(long&);


#endif
----------------------------------------------------------------------------