https://llvm.org/bugs/show_bug.cgi?id=23522

            Bug ID: 23522
           Summary: Optimized assembly raises div-by-zero exception though
                    C source code takes pains to avoid it
           Product: clang
           Version: unspecified
          Hardware: Macintosh
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]
    Classification: Unclassified

Created attachment 14326
  --> https://llvm.org/bugs/attachment.cgi?id=14326&action=edit
Program showing clang optimization bug

The attached C program takes care to avoid division by zero when presented with
a = b = 0.0. It works correctly when compiled without optimization (using -O0).
When compiler optimization level -O1 or above is used, the assembly generated:

        movsd   -16(%rbp), %xmm0
        mulsd   %xmm0, %xmm0
        movsd   -24(%rbp), %xmm1
        mulsd   %xmm1, %xmm1
        addsd   %xmm0, %xmm1
        movsd   LCPI0_0(%rip), %xmm0
        divsd   %xmm1, %xmm0
        cmpltsd LCPI0_1(%rip), %xmm1
        movapd  %xmm1, %xmm2
        andnpd  %xmm0, %xmm2
        movsd   LCPI0_2(%rip), %xmm0
        andpd   %xmm1, %xmm0
        orpd    %xmm2, %xmm0
        sqrtsd  %xmm0, %xmm0

performs a floating-point division before checking for zero denominator and
hence raises a div-by-zero exception:

clang -O1 optbug.c
./a.out
Input a, b: 0 0
Floating exception

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to