[LLVMbugs] [Bug 15541] New: Wrong behavior with operator new overloading when using O2 for optimization

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Mar 18 22:21:31 PDT 2013


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

            Bug ID: 15541
           Summary: Wrong behavior with operator new overloading when
                    using O2 for optimization
           Product: clang
           Version: 3.2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: terry.yinzhe at gmail.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

When having the overloaded new operator defined in other cpp or in a lib, clang
with O2 or above with optimize a new operation without assignment, and it will
not call the overloaded new at all.

This behavior is different when the overloaded new operator is defined in the
same cpp file.

The following code will reproduce the problem.

test.cpp
#include <iostream>

#define CHECK(expect, actual) std::cout << "EXPECT:" << expect <<
"\tACTUAL:"<<actual << std::endl
extern bool newCalled;

void testNewWithoutAssignment() {
    newCalled = false;
    new char;
    CHECK(1, newCalled);
}
char *p;
void testNewWithAssignment() {
    newCalled = false;
    p = new char;
    CHECK(1, newCalled);
}

int main() {
    testNewWithoutAssignment();
    testNewWithAssignment();
    return 0;
}

new.cpp
#include <exception>
#include <new>
#include <cstdlib>

bool newCalled = false;
void* operator new (size_t size)  throw (std::bad_alloc)
{
    newCalled = true;
    return malloc(size);
}

-- 
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/20130319/8422619d/attachment.html>


More information about the llvm-bugs mailing list