This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [cs] Robustify in the presence of PCH n snarf-n-barf
- From: Geoff Keating <geoffk at geoffk dot org>
- To: mrs at apple dot com
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Fri, 31 Oct 2003 14:08:50 -0800
- Subject: Re: [cs] Robustify in the presence of PCH n snarf-n-barf
- References: <7801465F-0B34-11D8-B2B9-003065A77310@apple.com>
> 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>