[LLVMbugs] [Bug 10342] New: apparent wrong code bug at -O0

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Jul 12 14:41:29 PDT 2011


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

           Summary: apparent wrong code bug at -O0
           Product: new-bugs
           Version: trunk
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: regehr at cs.utah.edu
                CC: llvmbugs at cs.uiuc.edu


I believe the correct result of the program below is "0" because the unsigned
bit field is promoted to signed int before comparison.

In fact, Clang prints 0 if the comma operator is removed.  I think that
clinches it.

[regehr at gamow ~]$ clang -v 
clang version 3.0 (trunk 134918)
Target: x86_64-unknown-linux-gnu
Thread model: posix
[regehr at gamow ~]$ clang -O0 small.c
small.c:11:17: warning: expression result unused [-Wunused-value]
  int y = x >= (0, s.f1);
                ^
1 warning generated.
[regehr at gamow ~]$ ./a.out 
1
[regehr at gamow ~]$ cat small.c
#include <stdio.h>

struct S0 {
  unsigned f1:1;
};

struct S0 s;

int main (void) {
  int x = -3;
  int y = x >= (0, s.f1);
  printf ("%d\n", y);
  return 0;
}

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list