This is the mail archive of the gcc-prs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: c++/9881: Incorrect address calculation for static class member


The following reply was made to PR c++/9881; it has been noted by GNATS.

From: "Peter A. Buhr" <pabuhr at plg2 dot math dot uwaterloo dot ca>
To: bangerth at ticam dot utexas dot edu
Cc: asharji at uwaterloo dot ca, gcc-bugs at gcc dot gnu dot org, gcc-gnats at gcc dot gnu dot org
Subject: Re: c++/9881: Incorrect address calculation for static class member
Date: Fri, 28 Feb 2003 08:49:50 -0500 (EST)

 Sorry, for the delay in responding, but Thursday evening is my guitar lesson so
 I had to head home early to prepare.
 
    Well, all the questions you raise boil down to the question: what is an 
    address constant expression. Apparently, the compiler chooses to consider 
    the initializer in line X to be one, while it doesn't for line Y. I cannot 
    answer the question further than what I did in my previous mail, apart 
    from the fact that line X has not cast (or, rather: a cast from one type 
    to itself), while line Y has a (reinterpret_)cast from type module to 
    incompatible type bar.
 
 It seems to me that a cast to a pointer should always have the same meaning.
 That is, when reinterpreting the bits, the meaning of those bits cannot imply a
 static context in one case and a dynamic in another. That seems too bizarre.
 
 So what is the next step? My code use to work with gcc 3.2 and now fails with
 gcc 3.3. My understanding is that gcc3.3 is scheduled for release very soon and
 I would like my code to work with it. What law firm do I need to hire to press
 my case as it seems the issue is an open question for the current version of
 g++. What if I get a note from Bjarne saying which way it's suppose to go?
 
    Just as an aside, independent of the validity of the PR in itself: why are 
    you making it so particularly hard for the compiler to decide this? You 
    are setting module::b to &module::storage; there is simple syntax to 
    achieve this goal than the one you use, no? :-)
 
 The program I submitted is the simplest case I could construct to illustrate
 (what I perceive) as an issue (lawyer speak). The real program is an extensive
 thread-library for C++, called uC++:
 
    http://plg.uwaterloo.ca/~usystem/uC++.html
 
 When the thread library is booting up, I need to initialize, by hand, a few
 fields in a static data-structure, which ultimately gets initialized by its
 constructor. That is, during the boot sequence there are mutually recursive
 reference issues that can best be resolved by temporarily making one data
 structure *appear* initialized so the first step can complete and then actually
 initializing the data structure in the second step. To do this, I need to
 statically insert an address and a non-zero value into 2 fields of the data
 structure. Now I can't declare an instance of the data structure because that
 triggers a call to its constructor, so I have to statically allocate a block of
 storage that is the size of the data structure, pretend the storage is the data
 structure, hit the storage with the necessary values, use those values at the
 start of the boot sequence so it looks initialized, and then run the
 constructor on the storage (new(storage) foo) to get the storage initialized.
 (You asked for this.)
 
 The fundamental reason for the mutually recursive references is that a thread
 library has to replace malloc/free to make them thread safe (no I do not and
 will not use pthreads). Now malloc is called during _start, while booting the
 C++ runtime, but my malloc thinks the thread library is running and accesses
 the data structure that I statically initialize. I could use an initialization
 flag that is checked for each malloc, but it is possible to eliminate the check
 if the boot sequence can be tricked. After the C++ runtime is started, my
 library can start and properly initialize the data structure.  Essentially,
 when boot strapping a system, it is necessary to perform some of these
 "unusual" operations. There are similar, but much more complex, issues when
 boot strapping an OS.
 
 However, the bottom-line is that I should not need to justify a legitimate use
 for some feature in the language. (What a programmer wishes to do in the
 privacy their own code is their business.) The feature is there for me to use,
 and should work correctly (modulo the current outstanding legal question). But
 I do not mind answering this question for inquiring minds. (Which is how you
 asked the question.)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]