[cfe-dev] [LLVMdev] php crash

Xi Wang xi.wang at gmail.com
Fri Apr 3 14:34:44 PDT 2009


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

On Fri, Apr 3, 2009 at 3:23 PM, Xi Wang <xi.wang at gmail.com> wrote:
> I tried the version you used, too.  the resulting executable was still broken.
>
> I guess the reason is due to fastcall on function pointers, which
> Clang does not recognize.  Consider the following snippet.
>
> #include <stdio.h>
>
> void __attribute__((fastcall)) f(int i)
> {
>    printf("%d\n", i);
> }
>
> typedef void (*__attribute__((fastcall)) f_t)(int i);
> //typedef void __attribute__((fastcall)) (*f_t)(int i);
>
> int main()
> {
>    f(42);
>    f_t fp = f;
>    fp(42);
> }
>
> Clang does not catch the attribute on f_t; instead it produces a
> warning "'fastcall' attribute only applies to function types".  so the
> function pointer might be miscompiled.
>
> stdcall should cause the similar problem as well.
>
> On x64 there is no use of fastcall or stdcall.  so Clang produces a
> correct php executable.
>
> - xi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: call.patch
Type: application/octet-stream
Size: 2908 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20090403/59e1362d/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.c
Type: application/octet-stream
Size: 195 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20090403/59e1362d/attachment-0001.obj>


More information about the cfe-dev mailing list