[llvm-bugs] [Bug 51340] New: Wrong code generated for x86 inline assembly

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Aug 4 05:22:25 PDT 2021


            Bug ID: 51340
           Summary: Wrong code generated for x86 inline assembly
           Product: clang
           Version: 12.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C
          Assignee: unassignedclangbugs at nondot.org
          Reporter: pgofman at codeweavers.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

Created attachment 25105
  --> https://bugs.llvm.org/attachment.cgi?id=25105&action=edit
Isolated test case

The bug affects wine-mono project (compiling WPF code with clang).

I am attaching an isolated test case which reproduces the issue which isolates
the miscompiled code.

When compiled with 'clang -fms-extensions -m32 ./clang_bug.c' wrongly
translates 'movss    fi.f,xmm1;'  instruction. Instead of referencing the
address on stack it uses eax as destination address where the compiler has
stored the stack address before the asm block. The eax has been overwritten by
prior instructions in the assembly. 'movss    fi.f,xmm1;' is also translated
wrong using 'ecx' where the compiler has also stored the same stack address of
'fi' variable.

The issue is not reproducible if not using union here (e. g., just defining
'fi' as float or int). It is also not reproducible when adding '-O2' to
compiler flags.

Here is the relevant asm compilation result for the wrong case:

round_func:                             # @round_func
# %bb.0:
        pushl   %ebp
        .cfi_def_cfa_offset 8
        .cfi_offset %ebp, -8
        movl    %esp, %ebp
        .cfi_def_cfa_register %ebp
        subl    $8, %esp
        movss   8(%ebp), %xmm0                  # xmm0 = mem[0],zero,zero,zero
        leal    -8(%ebp), %eax
        leal    -8(%ebp), %ecx

        movss   8(%ebp), %xmm0                  # xmm0 = mem[0],zero,zero,zero
        cvtss2si        %xmm0, %eax
        cvtsi2ss        %eax, %xmm1
        subss   %xmm0, %xmm1
        movss   round_func.negHalf, %xmm0       # xmm0 = mem[0],zero,zero,zero
        cmpless %xmm0, %xmm1
        movss   %xmm1, (%eax)
        subl    (%ecx), %eax

        addl    $8, %esp
        popl    %ebp
        .cfi_def_cfa %esp, 4
        .size   round_func, .Lfunc_end0-round_func

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210804/53c09efb/attachment.html>

More information about the llvm-bugs mailing list