[cfe-dev] calling convention for function pointers

Xi Wang xi.wang at gmail.com
Sat Apr 4 00:55:53 PDT 2009


The problem arises when compiling the PHP 5.3 code on x86.  It seems
that Clang does not recognize calling conventions on function
pointers.  For example,

typedef void (*__attribute__((fastcall)) foo_t)(int i);
foo_t fp = ...;
fp(42);

Clang ignores the `fastcall' attribute and produces a buggy executable.

Attached is a new patch with test code.  1) I am not sure if I used
`TargetDecl' in an appropriate way.  2) Though I tried to collect
usages in the attached test.c, some corner cases may be missing.  3)
The patch does not support member function pointers.

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?

- xi

On Fri, Apr 3, 2009 at 5:34 PM, Xi Wang <xi.wang at gmail.com> wrote:
> a quick patch and a test file attached.
>
> 1. eliminate warnings of fastcall/stdcall on function pointers.
> 2. set TargetDecl to typedef declaration.
> 3. set correct calling convention when emitting call.
>
> - xi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: call.patch
Type: application/octet-stream
Size: 3420 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20090404/1b9f81c6/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.c
Type: application/octet-stream
Size: 549 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20090404/1b9f81c6/attachment-0001.obj>


More information about the cfe-dev mailing list