[LLVMbugs] [Bug 12098] New: possible wrong code bug

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Feb 27 08:57:51 PST 2012


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

             Bug #: 12098
           Summary: possible wrong code bug
           Product: new-bugs
           Version: 3.0
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: regehr at cs.utah.edu
                CC: chenyang at cs.utah.edu, llvmbugs at cs.uiuc.edu
    Classification: Unclassified


This one is pretty interesting.  One could argue that it contains undefined
behavior due to multiple unsequenced updates to an object, but only if you
consider f1 and f2 to be the same object for purposes of this rule.  

We've internally argued about this case for some time.  The C99 standard does
not provide an entirely clear answer. 

I can't tell if this is a dup of PR11977, apologies if so.


regehr at john-home:~/z/reduce/0$ clang -w -O1 small.c ; ./a.out 
-1
regehr at john-home:~/z/reduce/0$ clang -w -O2 small.c ; ./a.out 
0
regehr at john-home:~/z/reduce/0$ cat small.c
int printf (const char *, ...);
#pragma pack(1)
struct S0
{
    int:8;
    int f1:31;
    int f2:1;
};
struct S0 a = { };

void fn1 (struct S0 p2)
{
}

void fn2 ()
{
    fn1 (a);
}

int main ()
{
    (a.f2 = 1) | (a.f1 = 0);
    printf ("%d\n", a.f2);
    return 0;
}
regehr at john-home:~/z/reduce/0$ clang -v
clang version 3.1 (trunk 151509)
Target: x86_64-unknown-linux-gnu
Thread model: posix

-- 
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