public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: libstdc++/7106: vector<bool>::operator[] wrong on 64bit systems
@ 2002-06-24 7:46 paolo
0 siblings, 0 replies; 4+ messages in thread
From: paolo @ 2002-06-24 7:46 UTC (permalink / raw)
To: gcc-bugs, gcc-prs, nobody, paolo, wolfgang.bangerth
Synopsis: vector<bool>::operator[] wrong on 64bit systems
Responsible-Changed-From-To: unassigned->paolo
Responsible-Changed-By: paolo
Responsible-Changed-When: Mon Jun 24 07:37:45 2002
Responsible-Changed-Why:
.
State-Changed-From-To: open->feedback
State-Changed-By: paolo
State-Changed-When: Mon Jun 24 07:37:45 2002
State-Changed-Why:
Hi. Could you please check a current 3.1.1 or 3.2 snapshot?
I don't have a 64 bit system at hand but I strongly suspect
that the problem is already fixed thanks to the following
patch:
http://gcc.gnu.org/ml/gcc-patches/2002-05/msg02641.html
Ciao, Paolo.
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=7106
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: libstdc++/7106: vector<bool>::operator[] wrong on 64bit systems
@ 2002-06-24 7:59 paolo
0 siblings, 0 replies; 4+ messages in thread
From: paolo @ 2002-06-24 7:59 UTC (permalink / raw)
To: gcc-bugs, gcc-prs, paolo, wolfgang.bangerth
Synopsis: vector<bool>::operator[] wrong on 64bit systems
State-Changed-From-To: feedback->closed
State-Changed-By: paolo
State-Changed-When: Mon Jun 24 07:57:39 2002
State-Changed-Why:
On submitter's request.
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=7106
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: libstdc++/7106: vector<bool>::operator[] wrong on 64bit systems
@ 2002-06-24 7:51 Wolfgang Bangerth
0 siblings, 0 replies; 4+ messages in thread
From: Wolfgang Bangerth @ 2002-06-24 7:51 UTC (permalink / raw)
To: paolo; +Cc: gcc-prs
The following reply was made to PR libstdc++/7106; it has been noted by GNATS.
From: Wolfgang Bangerth <bangerth@math.ethz.ch>
To: paolo@gcc.gnu.org, <gcc-bugs@gcc.gnu.org>, <gcc-prs@gcc.gnu.org>,
<nobody@gcc.gnu.org>, <paolo@gcc.gnu.org>,
<wolfgang.bangerth@iwr.uni-heidelberg.de>, <gcc-gnats@gcc.gnu.org>
Cc:
Subject: Re: libstdc++/7106: vector<bool>::operator[] wrong on 64bit systems
Date: Mon, 24 Jun 2002 16:41:50 +0200 (CEST)
> Hi. Could you please check a current 3.1.1 or 3.2 snapshot?
> I don't have a 64 bit system at hand but I strongly suspect
> that the problem is already fixed thanks to the following
> patch:
> http://gcc.gnu.org/ml/gcc-patches/2002-05/msg02641.html
Thanks, that is exactly the same patch I had. So it works. Should have
looked before :-(
Thanks
Wolfgang
-------------------------------------------------------------------------
Wolfgang Bangerth email: bangerth@math.ethz.ch
www: http://www.math.ethz.ch/~bangerth/
^ permalink raw reply [flat|nested] 4+ messages in thread
* libstdc++/7106: vector<bool>::operator[] wrong on 64bit systems
@ 2002-06-24 7:36 wolfgang.bangerth
0 siblings, 0 replies; 4+ messages in thread
From: wolfgang.bangerth @ 2002-06-24 7:36 UTC (permalink / raw)
To: gcc-gnats
>Number: 7106
>Category: libstdc++
>Synopsis: vector<bool>::operator[] wrong on 64bit systems
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Mon Jun 24 06:56:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: Wolfgang Bangerth
>Release: unknown-1.0
>Organization:
>Environment:
SparcV9 (64bit), sparc-sun-solaris2.9
>Description:
Using vector<bool>::operator[] goes wrong when on a 64bit
system: somehow computing the bit index does not take into
account that sizeof(int)==32 but sizeof(int*)==64. Rather, 32 bit is assume, leading the equality of the 32nd with the 0th bit, 33rd with the first, and so on. I'd think that the fix is trivial, when one knows where to look, but I got lost in the header file and all the class local typedefs, sorry.
The attached program demonstrates the problem: it initializes a vector of 40 elements, prints it (all zero, ok), the sets the zeroth element and prints it again. The output is
examples/step-1> ./a.out
0000000000000000000000000000000000000000
1000000000000000000000000000000010000000
Note thet spurious second "1" in the second line.
This is the program:
----------------------------------------------
#include <vector>
#include <iostream>
void print (std::vector<bool> &v) {
for (unsigned int i=0; i<v.size(); ++i)
std::cout << v[i];
std::cout << std::endl;
};
int main ()
{
const unsigned int N = 40;
std::vector<bool> v (N, false);
print (v);
v[0] = true;
print (v);
};
---------------------------------------
Compile it with
g++ -m64 x.cc
on sparcv9.
There are more oddities:
- first, the _Bit_reference structure exports its members
publicly. I guess, there's a "private" missing at the
start of the class. The same applies to a number of other
classes in the file.
- Well, I dug further into the header file: the reason the
original problem is happening is this: put the following
two lines into the program above (this uses the fact that
members are not private :-):
std::cout << v[0]._M_p << ' ' << v[0]._M_mask
<< std::endl;
std::cout << v[32]._M_p << ' ' << v[32]._M_mask
<< std::endl;
Clearly the masks for the two elements should be
different. Nevertheless, this is the output on my system:
0x100103180 1
0x100103180 1
Ah, I think I now got it: the data is stored as unsigned longs, but in _Bit_iterator::operator* a reference is
created with pointer base and bit offset 1U<<_M_offset.
This should likely read 1UL, no?
There are two places in the file where 1U appears, one in the const, and in the non-const bit iterator. If I change them both, the test succeeds. So I guess this is also the right fix.
Regards
Wolfgang
>How-To-Repeat:
>Fix:
read the above.
>Release-Note:
>Audit-Trail:
>Unformatted:
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2002-06-24 14:57 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-06-24 7:46 libstdc++/7106: vector<bool>::operator[] wrong on 64bit systems paolo
-- strict thread matches above, loose matches on Subject: below --
2002-06-24 7:59 paolo
2002-06-24 7:51 Wolfgang Bangerth
2002-06-24 7:36 wolfgang.bangerth
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).