[LLVMbugs] [Bug 15959] New: Wrong constant folding

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri May 10 08:05:57 PDT 2013


http://llvm.org/bugs/show_bug.cgi?id=15959

            Bug ID: 15959
           Summary: Wrong constant folding
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangbugs at nondot.org
          Reporter: ishiura-compiler at ml.kwansei.ac.jp
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

LLVM (git) + clang (3.4) for x86_64 miscompiles the following code.

    $ cat error.c

    int main (void)
    {
      volatile short x = 1;
      static long k = 1L;
      int a = x << ( k - 1 );   // a = 1
      long t = 1L >> a ;        // t = 0
      if ( t != 0L ) { __builtin_abort(); }
      return 0;
    }

    $ clang error.c -O1
    $ ./a.out
    Aborted (core dumped)

The following code with variable k replaced by "1L" is
correctly compiled.

    $ cat noerror.c

    int main (void)
    {
      volatile short x = 1;
      int a = x << ( 1L - 1 );  // a = 1
      long t = 1L >> a ;        // t = 0
      if ( t != 0L ) { __builtin_abort(); }
      return 0;
    }

    $ clang noerror.c -O1
    $ ./a.out
    $ echo $?
    0

    $ clang -v
    clang version 3.4 (http://llvm.org/git/clang.git
dd256314cf391063329e504f0ece46ee51bbfa2a) (http://llvm.org/git/llvm.git
51dab6e3945a6d06a713869967ced3a8f9fb6294)
    Target: x86_64-unknown-linux-gnu
    Thread model: posix

-- 
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/20130510/beffb014/attachment.html>


More information about the llvm-bugs mailing list