>
> I believe I understand your general objection.  I don't feel strongly
> about the current behaviour, except that if it has to change then it
> must be a documented extension.   
>
> I don't think we can meaningfully order the space of "undefined
> behaviour" and single out some as are "more undefined behaviour than
> others". 
>
> -- Gaby
>   

Let me summarize what has been done in order for someone
to decide what should be done.

Since gcc 3.3.x inliner ICE'd on some function calls built from
incompatible function pointer cast. That was not a "compatible type"
as defined in standard, but some implementation-dependent
types - for example on x86 it is return type casted from double to int.

The ICE was fixed in a way when all calls through function pointer
cast incompatible as defined in standard are warned and turned
into runtime-trap. That means not only ICE'd examples, but
safe 'char *' to 'void *' conversions now aborts at runtime.

There was another fix for the same problem, by simply not inlining
such calls. But that patch was more intrusive and did not pass
frozen 3.3/mainline state for that time.

However the fix is incomplete - it has been disabled for objective-c because
its runtime depends on ability to call casted fptrs, at least in "safe"
variants.
Secondly, there still exists ability to build problematic function calls
by "double cast to void" - e.g. "(int(*)(int) (void(*)(void) foo"
construction
somehow slips the check. It ICE's on 3.3.x / 3.4.x on problematic
types and (surprise!) not ICE's but generates not-inlined call in 4.1.

For gcc-4.2, behavior has been changed again - double cast to void
trick is not accepted anymore - warn/trap is generated. But for
objective-c, all checks are still bypassed and it is possible to ICE.

Now the interesting part, what to do for 4.2:

1) Leave it as is: behavior has been changed again (undocumented),
ICE's for objective-c front-end.

- has natural drawback of surprise for people switching from previous
compiler versions

2) Enable checks for objective-c since its front-end no longer generates
casted calls, document behavior changes, suggest people not to cast
incompatible function types at all or at least do it via union.

- need someone to check real-world effect on objective-c
- may become broken in future when inliner will become smart enough
to inline casted via assignment or via union calls.

3) Fix ICE in  another way - by explicitly disable inlining of casted calls.
Remove warn/trap checks, restore natural undefined behavior -
than cast really changes types in platform-dependent incompatiple way.

- surely most costly to implement
- looks right to me since trap for platform-dependent working cast sounds
worse than ICE for platform-dependent broken cast :)


So, what should be done here?

Reply via email to