[LLVMbugs] [Bug 9032] New: clang gives different results than gcc wrt array element modification evaluation order

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sun Jan 23 14:41:26 PST 2011


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: unassignedclangbugs at nondot.org
        ReportedBy: juli at clockworksquid.com
                CC: llvmbugs at cs.uiuc.edu


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.



More information about the llvm-bugs mailing list