[cfe-dev] calling convention for function pointers
Xi Wang
xi.wang at gmail.com
Sat Apr 4 09:16:01 PDT 2009
On Sat, Apr 4, 2009 at 5:51 AM, Eli Friedman <eli.friedman at gmail.com> wrote:
> The current approach used for calling conventions isn't really
> correct; we really ought to follow gcc and make the calling convention
> part of the type. Otherwise, we can't handle the general case like
> the following without some extremely ugly code; for example, take the
> following:
> __attribute((fastcall)) int a(int), b(int); void c(int x) { (cond ? a : b)(x); }
I am not sure if the code could be accepted by gcc.
> Not that this patch is necessarily unacceptable as a stopgap...
>
>> p.s. Currently Clang does not check incompatible pointer casts with
>> such attributes (e.g., from fastcall to cdecl). Should it report a
>> warning or something?
>
> Are you talking about the assignment case, or explicit casts? The
> assignment case would be covered by encoding the convention into the
> type, and using it in compatibility checking. For explicit casts, I
> don't think warning is a particularly good idea; the are legitimate
> uses for such casts.
I meant something like:
void __attribute((fastcall)) foo(int x);
void (*bar)(int) = foo;
- xi
More information about the cfe-dev
mailing list