gordon%stats.ucl.ac.uk@NSS.CS.UCL.AC.UK (Gordon Joly and Paul Otto) (03/21/89)
G++ dumps core after reporting an unimplemented construct. The
following listing was done on a SUN-3/75 running SunOS 3.4, g++ and
libg++ 1.34.0 with config.g++ sun3 on a SUN-3/160 with gcc 1.34.
Script started on Tue Mar 21 14:46:33 1989
io% g++ -v
g++ version 1.34.0
io% g++ -c fib.bug1.cc
fib.bug1.cc:13: sorry, not implemented: initialization of local static object needing constructor
In function struct Integer fib (int):
fib.bug1.cc:17: Segmentation violation
Program c++ got fatal signal 11.
io% ls -l
total 1482
- -rw------- 1 otto 313 Mar 21 08:53 Makefile
- -rw------- 1 otto 0 Mar 21 14:51 bug1
- -rw-r--r-- 1 otto 1491770 Mar 21 14:53 core
- -rw------- 1 otto 507 Mar 21 14:51 fib.bug1.cc
- -rw------- 1 otto 507 Mar 21 09:05 fib.cc
- -rw------- 1 otto 375 Mar 21 09:04 runfib.cc
- -rw------- 1 otto 3223 Mar 21 09:01 table.cc
- -rw------- 1 otto 1638 Mar 21 09:02 table.h
io% cat fib.bug1.cc
//
// Example for B11b - of use of tables.
//
// A memo-ising function - using doubly recursive fibonacci as example
//
// G. P. Otto, 1987
#include "table.h"
Integer
fib(int n)
{
static table fibresults; // table of known results
Integer res = fibresults.lookup(n); // lookup answer
if (!fibresults.lastlookupOK){ // if not yet known
res = (n < 2)? 1 : (fib(n-1) + fib(n-2)); // calculate it
fibresults.insert(n,res); // and note the result
}
return(res);
}
// PS didn't use "dispose"!
io% cat table.h
//
// a simple "table" class, written for B11b by G. P. Otto, 1987
//
// In this version, the public interface lacks any way of traversing
// the table, so if you don't know what you're looking for, you can't
// find it.
//
// The data-type for "keytype" is almost arbitrary, but you must be able
// to check equality. (Actually assume that "==" works for keys.)
// IMPORTANT: the hash function needs to be re-designed for some different
// types & frequencies of keys. (See table.cc)
//
// NEED: declarations for "keytype" & "datumtype" data-types
typedef int keytype;
#include <Integer.h>
typedef Integer datumtype;
struct cell { // structure to hold data on a linked list
keytype key;
datumtype datum;
cell *next; // pointer to next cell
};
static const int hash_tab_size = 97;
// hash table size - usually best to make it a prime
class table {
cell * list[hash_tab_size]; // each list holds the data whose
// keys hash to that array index
public:
table(); // create an empty table
~table(); // destroy a table, reclaiming
// space & tidying up as necessary
void insert(keytype, datumtype);
// "table[key] = ..."
// overwrite previous entry if
// there is one with same key.
// error message if full.
datumtype lookup(keytype); // "... = table[key]"
// errors (such as no item with
// specified key, are handled by
// "lastlookupOK", below.
int lastlookupOK; // true if last "lookup" succeeded,
// false otherwise
void dispose(keytype); // delete (key, data) pair from table.
// No-op if there isn't such a pair.
// Wot! No traversal?
};
io% ^D
script done on Tue Mar 21 14:49:10 1989
------- End of Forwarded Messagetiemann@YAHI.STANFORD.EDU (Michael Tiemann) (04/08/89)
This patch fixes a bug which kills the compiler in Gordon's memoizing
fib function. Replace old code in cplus-cvt.c with this code:
static tree
build_type_conversion_1 (xtype, basetype, expr, typename, for_sure)
tree xtype, basetype;
tree expr;
tree typename;
int for_sure;
{
tree first_arg = expr;
tree rval;
if (for_sure == 0 && ! lvalue_p (expr))
first_arg = build (NOP_EXPR, TYPE_POINTER_TO (basetype), integer_zero_node);
rval = build_method_call (first_arg, typename, NULL_TREE, 1, for_sure);
if (rval == error_mark_node)
{
if (for_sure == 0)
return NULL_TREE;
return error_mark_node;
}
if (first_arg != expr)
{
expr = build_up_reference (build_reference_type (TREE_TYPE (expr), expr));
TREE_VALUE (TREE_OPERAND (rval, 1)) = build_unary_op (ADDR_EXPR, expr, 0);
}
return convert (xtype, rval);
}
Michael