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]

Casts, types, pointers, and ADDR_EXPR


I am trying to figure out why these two functions act
differently on the tree level as there is an extra cast
in h1 which I think is extraneous.
int h(int g)
{
  const int *x = &g;
  return *x;
}

const int h1(const int g)
{
  const int *x = &g;
  return *x;
}

The reason why I think the cast is extraneous is because
the following code does not produce a cast at all so why
produce one for the address one:

int h2(int g)
{
  const int x = g;
  return x;
}

Getting rid of these casts would help all other optimizations
and will lower the memory usage of gcc slightly at the same time.

Thanks,
Andrew Pinski

PS yes this is the issue I brought up by my fold patch for
ADDR_EXPR but I would like to better understand why there should be
a cast there as the types in my mind equivalent as there is no cast
from "int" to "const int".


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