This is the mail archive of the gcc-bugs@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]

Re: neat bug in alias analysis



Egads.  Well, it's obvious what the bug is; the front-end makes
different type nodes for `NODE *' and `struct node *'.  And
c_get_alias_set assumes that things that are not related by their
TYPE_MAIN_VARIANT are different.

My opinion is that these pointer types should actually be the same.
In other words, my proposed fix is that:

  o build_pointer_type (similarly build_reference_type), should not
    just check TYPE_POINTER_TO but also check the TYPE_POINTER_TO for
    similarly-qualified types on the TYPE_MAIN_VARIANT/TYPE_NEXT_VARIANT
    list.

But, even that won't work, since we often create different versions of
the same type, that are not relaed along the TYPE_MAIN_VARIANT list.
For example, if we create the function type `void (*)(int)' twice in
local scope we never but the type in the type hash-table since the
type's not on the permanent obstack, and so we just end up with two
copies.  So, in addition to the above fix we could:

  o build all types on the permanent obstack.

My guess is that these combined fixes are actually a win.  Why?  Well,
we're going to use less memory if we can avoid building multiple
copies of pointer types.  We're also going to use less memory if we
can share types allocated in local scopes.  And, not that many types
are actually allocated in local scopes anyhow, as it is.  And, memory
management becomes much simpler.  We no longer can get types that get
trompled, and leak detection reduces to looking for situations where
we have two copies of the same type.  And, type-comparison (a
long-time hot-spot in the C++ front-end) will go faster since more
tests will simply be for pointer-equality, rather than requiring
recursion on the types.  Also, in C++, we sometimes copy things to the
permanent obstack anyhow.  Finally, to do file-at-a-time processing,
you need all types on the permanent obstack anyhow so that you can
have them at the end of the file.

But, even that won't work in C, where `enum' and `int' are the
compatible types, but not the same.  (In C++, you know that `int*' and
`enum*' don't alias, but in C, they can.)  The way to fix this is to
have the C front-end assign alias sets to `enum*' types immediately,
rather than lazily letting c_get_alias_set do it, as we do now.

Jeff, Richard, what do you think?  I'm embarassed by this bug, and I'd
like to work on a fix as quickly as possible.  Any objections to this
plan?

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com


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