This is the mail archive of the gcc-patches@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: [cs] Robustify in the presence of PCH n snarf-n-barf


> Date: Thu, 30 Oct 2003 15:54:58 -0800
> Cc: gcc-patches@gcc.gnu.org
> From: Mike Stump <mrs@apple.com>

> On Thursday, October 30, 2003, at 01:14 PM, Geoff Keating wrote:
> > This change is wrong, please make sure it never gets into mainline GCC.
> 
> Please explain how one can have two pointers to the same piece of GCed 
> data that have different static types on them?

The GC system is not designed to allow this.  You would have to revise
its design.

> In C++, this would be:
> 
> class Base {
> } *base;
> 
> class Derived : public base {
> } *derived;
> 
> int main() {
> 	base = derived = new Derived;
> }
> 
> In C, this would be:
> 
> tree base;
> tree_decl derived;
> 
> int main() {
> 	base = derived = make_decl ();
> 	return 0;
> }

You'll notice that this is not actually valid C.

> Per and I are experimenting with tightening up the compiler to include 
> more static typing, so that we can have the compiler's static type 
> system diagnose type errors instead of depending upon DECL_CHECK as 
> much.  This aids readability, give type violations sooner, and has 
> other good benefits.

Yes, I approve of this.  I don't see why you need this change to be
permanent to do it, though; indeed, I would expect that once
everything is fully statically typed, this check would work just fine
as it is currently.

> The C++ runtime system has the exact same code as your PCH code, but, 
> it does all the required runtime conversions, unlike your code.  Please 
> explain why your code isn't just plain wrong.

Um, because C++ does lots of other stuff to handle this sort of thing,
including extensive checking both at compile time and (if you use
dynamic_cast) at runtime?

The purpose of this consistency check is to catch cases where
someone's done something like

rtx a;
tree x = (tree) a;

by mistake, for instance by changing the type of a tree without
clearing out all its fields.  If you can design a check that allows
the cases that are safe, but disallows the cases that aren't, then
that would be OK; but don't just disable the check altogether.

-- 
- Geoffrey Keating <geoffk@geoffk.org>


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