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]

Re: gcc 4.2 more strict check for "function called through a non-compatible type"


Andrew Haley wrote:
> Yuri Pudgorodsky writes:
>  > 
>  > > We can say something like:
>  > >
>  > > "In GNU C, you may cast a function pointer of one type to a function
>  > > pointer of another type.  If you use a function pointer to call a
>  > > function, and the dynamic type of the function pointed to by the
>  > > function pointer is not the same as indicated by the static type of the
>  > > function pointer, then the results of the call are unspecified.  In
>  > > general, if the types are not too different 
> 
> s/not too different/compatible/
> 
> "not too different" has no meaning, whereas "compatible" is defined in
> Section 6.2.7.

But, at least in C++, the official meaning of compatible is not the
meaning we want.  For example, "int *" and "long *" are not compatible
-- but, in this context, we want to say that this will work.

> We need to do this because we use type-based alias analysis in gcc.

Yes, I remember adding that feature. :-) :-)

> If we permit incompatible
> types to be casted in function calls, we make a hole in alias
> analysis.

Yes, users who lie will lose.  The only thing we're trying to do here is
behave a bit more gracefully.  Introducing a call to __builtin_trap is
pretty brutal; instead, we want to say "we can't promise this is going
to work, but if you want to try, go ahead..."

-- 
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713


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