This is the mail archive of the gcc@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: g++ and aliasing bools


Mark wrote:

> Agreed.  I think Joe's argument is a huge step forward; if we can just
> work that through we'll probably get somewhere.

OK, I'll try to do it once more in a clean way.

Postulates: the current c alias set mechanism is correct, and the current
c++ alias mechanism, while overly conservative, is correct

The proposed replacement is the following: an aggregate is simple_enough
if it has no baseclasses and no virtual functions and all of its members
are either non-aggregates or simple_enough.

if cxx_get_alias_set is applied to an aggregate that is not simple_enough,
it returns 0.  Otherwise it uses the C rules (c_get_alias_set).

Now, let's assume that there is a bug with this, meaning that two accesses
will falsely be reported not to alias with this new rule (sorry about the
double negative).  So, assume that we have program P in which this is
true.

As I said before, there is only one extra C++ operation that will allow
"type punning" that doesn't exist in C: casting between base classes and
derived classes.  But any derived class pointer or reference, once
constructed, will go into alias set 0.  Even if the derived class pointer
is created later, from the base pointer, the compiler will not assume that
it can use its knowledge of the base object to learn anything about the
extra members.

Further, we can replace all simple_enough aggregates with C structs:
turn member functions into functions, drop protection, insert constructor
and destructor calls as ordinary function calls.

Conclusion: if program P exists, we can convert the relevant parts of
the point where we miscompile it into a C program, and GCC will also
miscompile the C program.  (imagine passing it through, say, EDG's
or KAI's C++ to C compiler).







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