This is the mail archive of the 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: [PATCH] improve C++ code by changing fold-const.c

> On Fri, 21 May 2004, Andrew Pinski wrote:
> > Patch1 removes the conversion operator but does not helps C++ code
> > as for some reason when the reference is taken there is a different
> > type for the struct which the reference points to than what the pointer
> > points to.
> I still don't understand what problem this is fixing!  Could you
> atleast provide a compile-only testcase that benefits from this
> transformation, so I can figure out for myself how your patch helps?

This is fixing the problem of the pointer types are mismatched in the sense
that the front-end created a pointer type which is different in where it is
stored in memory but logically equivent to other pointer type by that it points
to the same type.

Here is a C example of where this can happen
#include <stdio.h>

static char* funk() {
  return "Hello World.\n";

static void funky(char*(*func)()) {
  printf("%s", func());

void main() {

Note that before this patch there is a cast in there which causes the function
call to be outputted as an indirect call at first and then converted by combine
to be an direct call (because of your 2004-03-12 patch).  Now with my patch the
call to funk is converted into direct call as there is no cast in there.

Why the pointer types are located location in memory is beond me.  But for C++
since pointer and references are two different tree types you need to check for
that too, instead of just POINTER_TYPE.  Also since sometimes the C++ front-end
produces more than one tree referening to the same typ which was the reason for
using types_compatible_p in the first place.

In the sense I am not removing the conversion operator at all because there was
none in the first place (except for the fact that the pointer types are different
but not what they point to).

Andrew Pinski

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