Quantcast
Channel: Intel® Software - Intel® C++ Compiler
Viewing all articles
Browse latest Browse all 1175

C++14 operator delete[](void*, std::size_t) variant, incorrect size passed

$
0
0

Not sure if this is the correct place to report what seems to be a compiler bug, but here goes:

While icc have embraced the C++14 variants of operator delete, it seems to pass an incorrect value for the size parameter.

Reproduction case as an example on Compiler Explorer, where the incorrect assembly is also observable: https://godbolt.org/g/pPWktV

The second parameter, "the std::size_t size argument must equal the size argument passed to the allocation function that returned ptr." -18.6.1.2 Array forms [new.delete.array], item 12. Right now the compiler seems to pass the size of a single object instead of the size of the entire allocation.

This was initially discovered using the Scudo Hardened Allocator: https://llvm.org/docs/ScudoHardenedAllocator.html

Feel free to ask for additional information.

Cheers,
Daniel

x64-64 icc 18.0.0,  -O3 -std=c++14
#include <cstdint>

struct A {
    A() {
        m_single = new uint16_t;       // Calls operator new(2)
        m_array = new uint16_t[16384]; // Calls operator new[](32768)
    }
    ~A() {
        delete m_single;  // Calls (C++14) operator delete(m_single, 2)
        delete[] m_array; // Incorrectly calls (C++14) operator delete[](m_array, 2)
                          // Should call (C++14) operator delete[](m_array, 32768) or operator delete[](m_array)
    }

    uint16_t *m_single;
    uint16_t *m_array;
};

A a;

 


Viewing all articles
Browse latest Browse all 1175

Trending Articles