This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Segmentation fault building libg++ without named returns
- To: gcc-bugs at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Subject: Segmentation fault building libg++ without named returns
- From: "John David Anglin" <dave at hiauly1 dot hia dot nrc dot ca>
- Date: Fri, 8 Sep 2000 18:09:19 -0400 (EDT)
Because named returns have recently been depreciated, five libg++ tests
fail due to warnings with respect to named returns. I created a patch
to eliminate the use of named returns by libg++ (patch enclosed). However,
in testing under i686 linux, the following error occurs:
/home/dave/gnu/gcc-2.96/objdir/gcc/g++ -B/home/dave/gnu/gcc-2.96/objdir/gcc/ -nostdinc++ -isystem /home/dave/gnu/gcc-2.96/libstdc++ -isystem /home/dave/gnu/gcc-2.96/libstdc++/std -isystem /home/dave/gnu/gcc-2.96/libstdc++/stl -isystem /home/dave/gnu/gcc-2.96/libio -isystem /home/dave/gnu/gcc-2.96/objdir/i686-pc-linux-gnu/libio -L/home/dave/gnu/gcc-2.96/objdir/i686-pc-linux-gnu/libstdc++ -B/usr/local/i686-pc-linux-gnu/bin/ -B/usr/local/i686-pc-linux-gnu/lib/ -isystem /usr/local/i686-pc-linux-gnu/include -c -g -O3 -fvtable-thunks -D_GNU_SOURCE -fno-implicit-templates -nostdinc++ -I. -I../../libio -I../../../../libg++/src -I../../../../libg++/src/../../libio -I../../../../libg++/src/../../libstdc++ -I../../../../libg++/src/../src -ffloat-store ../../../../libg++/src/Intdouble.cc
In file included from ../../../../libg++/src/Intdouble.cc:22:
../../../../libg++/src/Integer.h:816: Internal error: Segmentation fault.
Please submit a full bug report.
See <URL:http://www.gnu.org/software/gcc/bugs.html> for instructions.
make[1]: *** [Intdouble.o] Error 1
make[1]: Leaving directory `/home/dave/gnu/gcc-2.96/objdir/i686-pc-linux-gnu/libg++/src'
make: *** [src/libgxx.list] Error 2
This is the function that causes the seg fault:
inline Integer operator & (const Integer& x, const Integer& y)
{
Integer r; and(x, y, r); return r;
}
It is probably the `and' that is the problem. The friend declarations for
and, or and xor are in `#if 0's. Removing them results in really strange
error messages:
../../../../libg++/src/Integer.h:167: friend declaration requires `void'
../../../../libg++/src/Integer.h:167: invalid type `void' declared `friend'
../../../../libg++/src/Integer.h:167: parse error before "and"
Dave
--
J. David Anglin dave.anglin@nrc.ca
National Research Council of Canada (613) 990-0752 (FAX: 952-6605)
This doesn't work because of the problems noted above.
2000-09-08 J. David Anglin <dave@hiauly1.hia.nrc.ca>
* BitSet.cc, BitString.cc, BitString.h, Integer.cc, Integer.h,
Rational.cc, Rational.h, String.cc, String.h: Don't use named returns.
--- libg++-2.8.1.3-20000816/libg++/src/BitSet.cc Thu Dec 17 09:34:11 1998
+++ libg++-2.8.1.3-20000908/libg++/src/BitSet.cc Fri Sep 8 16:17:10 2000
@@ -924,62 +924,6 @@
return r;
}
-#if defined(__GNUG__) && !defined(_G_NO_NRV)
-
-BitSet atoBitSet(const char* s, char f, char t, char star) return r
-{
- unsigned int sl = strlen(s);
- if (sl != 0)
- {
- r.rep = BitSetresize(r.rep, sl / BITSETBITS + 1);
- _BS_word* rs = r.rep->s;
- _BS_word a = 0;
- _BS_word m = 1;
- char lastch = 0;
- unsigned int i = 0;
- unsigned int l = 1;
- for(;;)
- {
- char ch = s[i];
- if (ch == t)
- a |= m;
- else if (ch == star)
- {
- if ((r.rep->virt = (lastch == t)))
- *rs = a | ~(m - 1);
- else
- *rs = a;
- break;
- }
- else if (ch != f)
- {
- *rs = a;
- break;
- }
- lastch = ch;
- if (++i == sl)
- {
- *rs = a;
- break;
- }
- else if (i % BITSETBITS == 0)
- {
- *rs++ = a;
- a = 0;
- m = 1;
- ++l;
- }
- else
- m <<= 1;
- }
- r.rep->len = l;
- trim(r.rep);
- }
- return;
-}
-
-#else
-
BitSet atoBitSet(const char* s, char f, char t, char star)
{
BitSet r;
@@ -1033,8 +977,6 @@
return r;
}
-#endif
-
ostream& operator << (ostream& s, const BitSet& x)
{
if (s.opfx())
--- libg++-2.8.1.3-20000816/libg++/src/BitString.cc Thu May 25 00:31:32 2000
+++ libg++-2.8.1.3-20000908/libg++/src/BitString.cc Fri Sep 8 16:30:11 2000
@@ -1258,23 +1258,10 @@
return _substr(first, rep->len - first);
}
-#if defined(__GNUG__) && !defined(_G_NO_NRV)
-#define RETURN(r) return
-#define RETURNS(r) return r;
-#define RETURN_OBJECT(TYPE, NAME) /* nothing */
-#define USE_UNSIGNED 1 /* probably correct */
-#else /* _G_NO_NRV */
-#define RETURN(r) return r
-#define RETURNS(r) /* nothing */
-#define RETURN_OBJECT(TYPE, NAME) TYPE NAME;
-#define USE_UNSIGNED 0 /* probably old bug */
-#endif
-
BitString
common_prefix (const BitString& x, const BitString& y, _G_int32_t startpos)
- RETURNS(r)
{
- RETURN_OBJECT(BitString, r);
+ BitString r;
_G_uint32_t xl = x.rep->len;
_G_uint32_t yl = y.rep->len;
@@ -1288,7 +1275,7 @@
startx = starty = startpos;
if (startx >= xl || starty >= yl)
- RETURN(r);
+ return r;
const _BS_word* xs = &(x.rep->s[BitStr_index(startx)]);
_BS_word a = *xs++;
@@ -1310,15 +1297,14 @@
b = *ys++;
}
r.rep = BStr_alloc(0, x.rep->s, startx, xp, xp - startx);
- RETURN(r);
+ return r;
}
BitString
common_suffix (const BitString& x, const BitString& y, _G_int32_t startpos)
- RETURNS(r)
{
- RETURN_OBJECT(BitString, r);
+ BitString r;
_G_uint32_t xl = x.rep->len;
_G_uint32_t yl = y.rep->len;
@@ -1332,7 +1318,7 @@
startx = starty = startpos;
if (startx >= xl || starty >= yl)
- RETURN(r);
+ return r;
const _BS_word* xs = &(x.rep->s[BitStr_index(startx)]);
_BS_word a = *xs--;
@@ -1354,13 +1340,12 @@
b = *ys--;
}
r.rep = BStr_alloc(0, x.rep->s, xp+1, startx+1, startx - xp);
- RETURN(r);
+ return r;
}
BitString reverse (const BitString& x)
- RETURNS(r)
{
- RETURN_OBJECT(BitString, r);
+ BitString r;
_G_uint32_t yl = x.rep->len;
BitStrRep* y = BStr_resize(0, yl);
if (yl > 0)
@@ -1390,14 +1375,13 @@
}
}
r.rep = y;
- RETURN(r);
+ return r;
}
BitString
atoBitString (const char* s, char f, char t)
- RETURNS(res)
{
- RETURN_OBJECT(BitString, res);
+ BitString res;
_G_uint32_t sl = strlen(s);
BitStrRep* r = BStr_resize(0, sl);
if (sl != 0)
@@ -1435,14 +1419,13 @@
r = BStr_resize(r, rl);
}
res.rep = r;
- RETURN(res);
+ return res;
}
BitPattern
atoBitPattern (const char* s, char f,char t,char x)
- RETURNS(r)
{
- RETURN_OBJECT(BitPattern, r);
+ BitPattern r;
_G_uint32_t sl = strlen(s);
if (sl != 0)
{
@@ -1494,7 +1477,7 @@
r.pattern.rep = BStr_resize(r.pattern.rep, rl);
r.mask.rep = BStr_resize(r.mask.rep, rl);
}
- RETURN(r);
+ return r;
}
extern AllocRing _libgxx_fmtq;
--- libg++-2.8.1.3-20000816/libg++/src/BitString.h Thu May 25 00:31:32 2000
+++ libg++-2.8.1.3-20000908/libg++/src/BitString.h Fri Sep 8 16:10:10 2000
@@ -499,55 +499,6 @@
::complement(*this, *this);
}
-#if defined(__GNUG__) && !defined(_G_NO_NRV)
-
-inline BitString operator & (const BitString& x, const BitString& y) return r
-{
- and_f(x, y, r);
-}
-
-inline BitString operator | (const BitString& x, const BitString& y) return r
-{
- or_f(x, y, r);
-}
-
-inline BitString operator ^ (const BitString& x, const BitString& y) return r
-{
- xor_f(x, y, r);
-}
-
-inline BitString operator << (const BitString& x, _G_int32_t y) return r
-{
- lshift(x, y, r);
-}
-
-inline BitString operator >> (const BitString& x, _G_int32_t y) return r
-{
- rshift(x, y, r);
-}
-
-inline BitString operator - (const BitString& x, const BitString& y) return r
-{
- diff(x, y, r);
-}
-
-inline BitString operator + (const BitString& x, const BitString& y) return r
-{
- cat(x, y, r);
-}
-
-inline BitString operator + (const BitString& x, _G_uint32_t y) return r
-{
- cat(x, y, r);
-}
-
-inline BitString operator ~ (const BitString& x) return r
-{
- complement(x, r);
-}
-
-#else /* NO_NRV */
-
inline BitString operator & (const BitString& x, const BitString& y)
{
BitString r; and(x, y, r); return r;
@@ -593,8 +544,6 @@
BitString r; complement(x, r); return r;
}
-#endif
-
// status, matching
inline _G_int32_t BitString::length() const
--- libg++-2.8.1.3-20000816/libg++/src/Integer.cc Thu May 25 00:31:32 2000
+++ libg++-2.8.1.3-20000908/libg++/src/Integer.cc Fri Sep 8 16:32:53 2000
@@ -1907,41 +1907,6 @@
return dest;
}
-#if defined(__GNUG__) && !defined(_G_NO_NRV)
-
-Integer sqrt(const Integer& x) return r(x)
-{
- int s = sign(x);
- if (s < 0) x.error("Attempted square root of negative Integer");
- if (s != 0)
- {
- r >>= (lg(x) / 2); // get close
- Integer q;
- div(x, r, q);
- while (q < r)
- {
- r += q;
- r >>= 1;
- div(x, r, q);
- }
- }
- return;
-}
-
-Integer lcm(const Integer& x, const Integer& y) return r
-{
- if (!x.initialized() || !y.initialized())
- x.error("operation on uninitialized Integer");
- Integer g;
- if (sign(x) == 0 || sign(y) == 0)
- g = 1;
- else
- g = gcd(x, y);
- div(x, g, r);
- mul(r, y, r);
-}
-
-#else
Integer sqrt(const Integer& x)
{
Integer r(x);
@@ -1977,10 +1942,6 @@
return r;
}
-#endif
-
-
-
IntRep* atoIntRep(const char* s, int base)
{
int sl = strlen(s);
--- libg++-2.8.1.3-20000816/libg++/src/Integer.h Thu May 25 00:31:32 2000
+++ libg++-2.8.1.3-20000908/libg++/src/Integer.h Fri Sep 8 16:14:13 2000
@@ -761,187 +761,6 @@
// constructive operations
-#if defined(__GNUG__) && !defined(_G_NO_NRV)
-
-inline Integer operator + (const Integer& x, const Integer& y) return r
-{
- add(x, y, r);
-}
-
-inline Integer operator + (const Integer& x, long y) return r
-{
- add(x, y, r);
-}
-
-inline Integer operator + (long x, const Integer& y) return r
-{
- add(x, y, r);
-}
-
-inline Integer operator - (const Integer& x, const Integer& y) return r
-{
- sub(x, y, r);
-}
-
-inline Integer operator - (const Integer& x, long y) return r
-{
- sub(x, y, r);
-}
-
-inline Integer operator - (long x, const Integer& y) return r
-{
- sub(x, y, r);
-}
-
-inline Integer operator * (const Integer& x, const Integer& y) return r
-{
- mul(x, y, r);
-}
-
-inline Integer operator * (const Integer& x, long y) return r
-{
- mul(x, y, r);
-}
-
-inline Integer operator * (long x, const Integer& y) return r
-{
- mul(x, y, r);
-}
-
-inline Integer sqr(const Integer& x) return r
-{
- mul(x, x, r);
-}
-
-inline Integer operator & (const Integer& x, const Integer& y) return r
-{
- r.rep = bitop(x.rep, y.rep, r.rep, '&');
-}
-
-inline Integer operator & (const Integer& x, long y) return r
-{
- r.rep = bitop(x.rep, y, r.rep, '&');
-}
-
-inline Integer operator & (long x, const Integer& y) return r
-{
- r.rep = bitop(y.rep, x, r.rep, '&');
-}
-
-inline Integer operator | (const Integer& x, const Integer& y) return r
-{
- r.rep = bitop(x.rep, y.rep, r.rep, '|');
-}
-
-inline Integer operator | (const Integer& x, long y) return r
-{
- r.rep = bitop(x.rep, y, r.rep, '|');
-}
-
-inline Integer operator | (long x, const Integer& y) return r
-{
- r.rep = bitop(y.rep, x, r.rep, '|');
-}
-
-inline Integer operator ^ (const Integer& x, const Integer& y) return r
-{
- r.rep = bitop(x.rep, y.rep, r.rep, '^');
-}
-
-inline Integer operator ^ (const Integer& x, long y) return r
-{
- r.rep = bitop (x.rep, y, r.rep, '^');
-}
-
-inline Integer operator ^ (long x, const Integer& y) return r
-{
- r.rep = bitop (y.rep, x, r.rep, '^');
-}
-
-inline Integer operator / (const Integer& x, const Integer& y) return r
-{
- div(x, y, r);
-}
-
-inline Integer operator / (const Integer& x, long y) return r
-{
- div(x, y, r);
-}
-
-inline Integer operator % (const Integer& x, const Integer& y) return r
-{
- mod(x, y, r);
-}
-
-inline Integer operator % (const Integer& x, long y) return r
-{
- mod(x, y, r);
-}
-
-inline Integer operator << (const Integer& x, const Integer& y) return r
-{
- lshift(x, y, r);
-}
-
-inline Integer operator << (const Integer& x, long y) return r
-{
- lshift(x, y, r);
-}
-
-inline Integer operator >> (const Integer& x, const Integer& y) return r;
-{
- rshift(x, y, r);
-}
-
-inline Integer operator >> (const Integer& x, long y) return r
-{
- rshift(x, y, r);
-}
-
-inline Integer pow(const Integer& x, long y) return r
-{
- pow(x, y, r);
-}
-
-inline Integer Ipow(long x, long y) return r(x)
-{
- pow(r, y, r);
-}
-
-inline Integer pow(const Integer& x, const Integer& y) return r
-{
- pow(x, y, r);
-}
-
-
-
-inline Integer abs(const Integer& x) return r
-{
- abs(x, r);
-}
-
-inline Integer operator - (const Integer& x) return r
-{
- negate(x, r);
-}
-
-inline Integer operator ~ (const Integer& x) return r
-{
- complement(x, r);
-}
-
-inline Integer atoI(const char* s, int base) return r
-{
- r.rep = atoIntRep(s, base);
-}
-
-inline Integer gcd(const Integer& x, const Integer& y) return r
-{
- r.rep = gcd(x.rep, y.rep);
-}
-
-#else /* NO_NRV */
-
inline Integer operator + (const Integer& x, const Integer& y)
{
Integer r; add(x, y, r); return r;
@@ -1119,8 +938,6 @@
Integer r; r.rep = gcd(x.rep, y.rep); return r;
}
-#endif /* NO_NRV */
-
inline Integer& Integer::operator %= (const Integer& y)
{
*this = *this % y; // mod(*this, y, *this) doesn't work.
--- libg++-2.8.1.3-20000816/libg++/src/Rational.cc Sat Jun 24 12:45:36 1995
+++ libg++-2.8.1.3-20000908/libg++/src/Rational.cc Fri Sep 8 16:35:23 2000
@@ -193,78 +193,6 @@
return pow(x, yy);
}
-#if defined(__GNUG__) && !defined(_G_NO_NRV)
-
-Rational operator - (const Rational& x) return r(x)
-{
- r.negate();
-}
-
-Rational abs(const Rational& x) return r(x)
-{
- if (sign(r.num) < 0) r.negate();
-}
-
-
-Rational sqr(const Rational& x) return r
-{
- mul(x.num, x.num, r.num);
- mul(x.den, x.den, r.den);
- r.normalize();
-}
-
-Integer floor(const Rational& x) return q
-{
- Integer r;
- divide(x.num, x.den, q, r);
- if (sign(x.num) < 0 && sign(r) != 0) --q;
-}
-
-Integer ceil(const Rational& x) return q
-{
- Integer r;
- divide(x.num, x.den, q, r);
- if (sign(x.num) >= 0 && sign(r) != 0) ++q;
-}
-
-Integer round(const Rational& x) return q
-{
- Integer r;
- divide(x.num, x.den, q, r);
- r <<= 1;
- if (ucompare(r, x.den) >= 0)
- {
- if (sign(x.num) >= 0)
- ++q;
- else
- --q;
- }
-}
-
-// power: no need to normalize since num & den already relatively prime
-
-Rational pow(const Rational& x, long y) return r
-{
- if (y >= 0)
- {
- pow(x.num, y, r.num);
- pow(x.den, y, r.den);
- }
- else
- {
- y = -y;
- pow(x.num, y, r.den);
- pow(x.den, y, r.num);
- if (sign(r.den) < 0)
- {
- r.num.negate();
- r.den.negate();
- }
- }
-}
-
-#else
-
Rational operator - (const Rational& x)
{
Rational r(x); r.negate(); return r;
@@ -343,8 +271,6 @@
return r;
}
-#endif
-
ostream& operator << (ostream& s, const Rational& y)
{
if (y.denominator() == 1L)
--- libg++-2.8.1.3-20000816/libg++/src/Rational.h Sat Jun 24 12:45:37 1995
+++ libg++-2.8.1.3-20000908/libg++/src/Rational.h Fri Sep 8 16:11:56 2000
@@ -242,30 +242,6 @@
}
#endif
-#if defined(__GNUG__) && !defined(_G_NO_NRV)
-
-inline Rational operator + (const Rational& x, const Rational& y) return r
-{
- add(x, y, r);
-}
-
-inline Rational operator - (const Rational& x, const Rational& y) return r
-{
- sub(x, y, r);
-}
-
-inline Rational operator * (const Rational& x, const Rational& y) return r
-{
- mul(x, y, r);
-}
-
-inline Rational operator / (const Rational& x, const Rational& y) return r
-{
- div(x, y, r);
-}
-
-#else /* NO_NRV */
-
inline Rational operator + (const Rational& x, const Rational& y)
{
Rational r; add(x, y, r); return r;
@@ -285,6 +261,5 @@
{
Rational r; div(x, y, r); return r;
}
-#endif
#endif
--- libg++-2.8.1.3-20000816/libg++/src/String.cc Thu Dec 17 09:34:11 1998
+++ libg++-2.8.1.3-20000908/libg++/src/String.cc Fri Sep 8 16:38:56 2000
@@ -966,19 +966,9 @@
}
-#if defined(__GNUG__) && !defined(_G_NO_NRV)
-#define RETURN(r) return
-#define RETURNS(r) return r;
-#define RETURN_OBJECT(TYPE, NAME) /* nothing */
-#else /* _G_NO_NRV */
-#define RETURN(r) return r
-#define RETURNS(r) /* nothing */
-#define RETURN_OBJECT(TYPE, NAME) TYPE NAME;
-#endif
-
-String join(String src[], int n, const String& separator) RETURNS(x)
+String join(String src[], int n, const String& separator)
{
- RETURN_OBJECT(String,x)
+ String x;
String sep = separator;
int xlen = 0;
int i;
@@ -998,7 +988,7 @@
j += sep.length();
}
ncopy0(src[i].chars(), &(x.rep->s[j]), src[i].length());
- RETURN(x);
+ return x;
}
/*
@@ -1078,58 +1068,6 @@
return dest;
}
-#if defined(__GNUG__) && !defined(_G_NO_NRV)
-
-String replicate(char c, int n) return w;
-{
- w.rep = Sresize(w.rep, n);
- char* p = w.rep->s;
- while (n-- > 0) *p++ = c;
- *p = 0;
-}
-
-String replicate(const String& y, int n) return w
-{
- int len = y.length();
- w.rep = Sresize(w.rep, n * len);
- char* p = w.rep->s;
- while (n-- > 0)
- {
- ncopy(y.chars(), p, len);
- p += len;
- }
- *p = 0;
-}
-
-String common_prefix(const String& x, const String& y, int startpos) return r;
-{
- const char* xchars = x.chars();
- const char* ychars = y.chars();
- const char* xs = &(xchars[startpos]);
- const char* ss = xs;
- const char* topx = &(xchars[x.length()]);
- const char* ys = &(ychars[startpos]);
- const char* topy = &(ychars[y.length()]);
- int l;
- for (l = 0; xs < topx && ys < topy && *xs++ == *ys++; ++l);
- r.rep = Salloc(r.rep, ss, l, l);
-}
-
-String common_suffix(const String& x, const String& y, int startpos) return r;
-{
- const char* xchars = x.chars();
- const char* ychars = y.chars();
- const char* xs = &(xchars[x.length() + startpos]);
- const char* botx = xchars;
- const char* ys = &(ychars[y.length() + startpos]);
- const char* boty = ychars;
- int l;
- for (l = 0; xs >= botx && ys >= boty && *xs == *ys ; --xs, --ys, ++l);
- r.rep = Salloc(r.rep, ++xs, l, l);
-}
-
-#else
-
String replicate(char c, int n)
{
String w;
@@ -1186,8 +1124,6 @@
return r;
}
-#endif
-
// IO
istream& operator>>(istream& s, String& x)
--- libg++-2.8.1.3-20000816/libg++/src/String.h Sat Jun 24 12:45:38 1995
+++ libg++-2.8.1.3-20000908/libg++/src/String.h Fri Sep 8 16:15:43 2000
@@ -696,80 +696,6 @@
// constructive concatenation
-#if defined(__GNUG__) && !defined(_G_NO_NRV)
-
-inline String operator + (const String& x, const String& y) return r;
-{
- cat(x, y, r);
-}
-
-inline String operator + (const String& x, const SubString& y) return r;
-{
- cat(x, y, r);
-}
-
-inline String operator + (const String& x, const char* y) return r;
-{
- cat(x, y, r);
-}
-
-inline String operator + (const String& x, char y) return r;
-{
- cat(x, y, r);
-}
-
-inline String operator + (const SubString& x, const String& y) return r;
-{
- cat(x, y, r);
-}
-
-inline String operator + (const SubString& x, const SubString& y) return r;
-{
- cat(x, y, r);
-}
-
-inline String operator + (const SubString& x, const char* y) return r;
-{
- cat(x, y, r);
-}
-
-inline String operator + (const SubString& x, char y) return r;
-{
- cat(x, y, r);
-}
-
-inline String operator + (const char* x, const String& y) return r;
-{
- cat(x, y, r);
-}
-
-inline String operator + (const char* x, const SubString& y) return r;
-{
- cat(x, y, r);
-}
-
-inline String reverse(const String& x) return r;
-{
- r.rep = Sreverse(x.rep, r.rep);
-}
-
-inline String upcase(const String& x) return r;
-{
- r.rep = Supcase(x.rep, r.rep);
-}
-
-inline String downcase(const String& x) return r;
-{
- r.rep = Sdowncase(x.rep, r.rep);
-}
-
-inline String capitalize(const String& x) return r;
-{
- r.rep = Scapitalize(x.rep, r.rep);
-}
-
-#else /* NO_NRV */
-
inline String operator + (const String& x, const String& y)
{
String r; cat(x, y, r); return r;
@@ -840,8 +766,6 @@
String r; r.rep = Scapitalize(x.rep, r.rep); return r;
}
-#endif
-
// prepend
inline void String::prepend(const String& y)