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

           Summary: clang gives different results than gcc wrt array
                    element modification evaluation order
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
        AssignedTo: [email protected]
        ReportedBy: [email protected]
                CC: [email protected]


With this code:

%%%
static int bar[1] = { 1 };

static int churn(void)
{
        return (bar[0]++);
}

static int seed(void)
{
        bar[0] += churn();
        return (bar[0]);
}
%%%

With GCC the first call to seed() will return 2.  With Clang the first call to
seed() will return 3.

If the += is expanded in seed like:

%%%
static int seed(void)
{
    bar[0] = bar[0] + churn();
    return (bar[0]);
}
%%%

Both GCC and Clang will return 2.  It isn't clear to me if the behavior of the
former is undefined, but neither GCC nor Clang warns that it might be if it is.
 (The latter could more obviously be undefined if a function were called with
bar[0] and churn()'s return value, but I don't know whether that's the case
with arithmetic operators.)  Clang and GCC yield the same results if bar is not
an array.

-- 
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.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to