Question about aliases

2012-11-06 Thread Alex Markin
Hello.

I've been watching the sources of aliasing in gcc and found one
comment, that seemed to me a bit strange. In file `gcc/alias.c' in
function `get_alias_set':

   /* From the former common C and C++ langhook implementation:

  Unfortunately, there is no canonical form of a pointer type.
  In particular, if we have `typedef int I', then `int *', and
  `I *' are different types.  So, we have to pick a canonical
  representative.  We do this below.

  Technically, this approach is actually more conservative that
  it needs to be.  In particular, `const int *' and `int *'
  should be in different alias sets, according to the C and C++
  standard, since their types are not the same, and so,
  technically, an `int **' and `const int **' cannot point at
  the same thing.

Please, can you explain the following:

According to the standard

 A typedef declaration does not introduce a new type, only a synonym for the 
 type so specified.

So, as I understand in this case `I *' and `int *' should be equal types?


Also, according to the issue 6.5 (7), we cat access to an object value
with expression that has

 a qualified version of a type compatible with the effective type of the object

So, `const int *' can legally point to the `int *' but not in reverse
order, and that's why `const int *' and `int *' should be in different
alias sets?


Alex.


Re: Question about aliases

2012-11-06 Thread Jonathan Wakely
On 6 November 2012 09:23, Alex Markin wrote:
 Also, according to the issue 6.5 (7), we cat access to an object value
 with expression that has

 a qualified version of a type compatible with the effective type of the 
 object

 So, `const int *' can legally point to the `int *' but not in reverse
 order,

A `const int*' can point to the same object as an `int*' points to, it
can't point to the `int*' itself (as you wrote).

Accessing a non-const `int' through a const int*' would be a case
where the effective type of the object [int] is accessing through a
qualified version of the type [const int],

If the effective type is `const int' then an `int*' cannot point to
it, because `int' is not `const int' and is not a qualified version of
`const int'.

But that's to do with what a `const int*' and `int*' can point to.
That relates to the alias sets of `int' and `const int' which is not
the same as `int*' and `const int*'

 and that's why `const int *' and `int *' should be in different
 alias sets?

No, they are in different alias sets because a `const int**' and an
`int**' cannot point to the same object. See
http://c-faq.com/ansi/constmismatch.html