[llvm-bugs] [Bug 47861] New: Lifetime of temporaries inconsistently extending when optiimzations are enabled

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Oct 15 08:57:56 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=47861

            Bug ID: 47861
           Summary: Lifetime of temporaries inconsistently extending when
                    optiimzations are enabled
           Product: clang
           Version: 11.0
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: chris at chrissavoie.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

Godbolt example: https://godbolt.org/z/fssed1

The following code:
struct A {
    __attribute__((noinline))
    A(int i) : data(i) {}
    A& operator+=(int i) { data += i; return *this; }
    int data;
};

int main() {
    A const& b = A(5) += 5;
    A c(6);
    return b.data + c.data; // 16 expected
}

Will return 16 when compiled without optimizations, 11 when compiled with
optimizations (-O2 or greater).

Browsing versions on godbolt it looks like the difference appeared between
versions 6.0.0 and 7.0.0.

I realize that this is generally undefined behavior, but the differences
between optimization levels caught me off guard. I'm not sure if there's either
a way to return to the pre-7 behavior or to make the non-optimized version more
obviously incorrect.

-- 
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/20201015/e1153033/attachment.html>


More information about the llvm-bugs mailing list