[llvm-bugs] [Bug 38532] New: Wrong compilation bug - probably compiler assumes variables are independent

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Aug 12 03:24:01 PDT 2018


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

            Bug ID: 38532
           Summary: Wrong compilation bug - probably compiler assumes
                    variables are independent
           Product: clang
           Version: 6.0
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: smile.wave at gmail.com
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org

During the C++ program development at work, I think I have discovered a bug in
compilation. I will describe it shortly, please tell me how to provide you more
information.

function main() {
    float x[512] = 1.0;
    uint32_t* x_uint = reinterpret_cast<uint32_t*>(x);
    do_magic_1(x, x_uint);
    do_magic_2(x, x_uint);
    do_magic_3(x, x_uint);    
}

/** This function does not work as expected */  
function do_magic_1(float* x, uint32_t* x_uint) {
    /* the rest of the code */  
}

/** This function works as expected */
function do_magic_2(float* x, uint32_t* x_uint) {
    x_uint = reinterpret_cast<uint32_t*>(x);
    /* the rest of the code */
}

/** This function works as expected */  
function do_magic_3(float* x, uint32_t* x_uint) {
    /* the rest of the code */
    std::cout <<  x_uint[0] << std::endl;
    /* the rest of the code */ 
}


I use the same pointers for x and x_uint, because I developed a function with
the same trick as "Fast inverse square root", which assumes floating point in
IEEE 754 format, and performs boolean (not, xor) operations on it. I compile
with -O3 flag.

-- 
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/20180812/96b7e0a4/attachment.html>


More information about the llvm-bugs mailing list