[PATCH] Fix bug in cpuid.h

Reid Kleckner rnk at google.com
Mon Jul 21 17:39:31 PDT 2014


This is http://llvm.org/PR20311.  IMO a better fix is to use the "=SD"
constraint on %1, since ebx isn't really clobbered here.

Also, we should probably be checking for PIC defines.

Also, the bug in __cpu_count should be fixed.


On Mon, Jul 21, 2014 at 3:45 PM, Akira Hatanaka <ahatanak at gmail.com> wrote:

> The attached patch fixes a bug where the __ebx output is clobbered.
> Currently, clang generates the following code when cpuid.c in the test case
> is compiled:
>
> $ clang cpuid.c -O3 -S -o -
>
> ## InlineAsm Start
>
> pushl  %ebx      # save %ebx before cpuid clobbers it.
>
> cpuid
>
> mov    %ebx,%ebx # move the __ebx output to %ebx.
>
> popl   %ebx      # pop saved %ebx. Clobbers __ebx output.
>
> ## InlineAsm End
>
> This happens because register '"ebx" is chosen for operand %1 which has
> constraint "=r". The attached patch adds %ebx to the clobber list to
> prevent this from happening.
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140721/c74bd52c/attachment.html>


More information about the cfe-commits mailing list