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

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

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;

 

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

 

Hi Daniel,

It looks like 18.0.3 has addressed the problem (see attached screenshot).

Please let us know if the issue still persists.

vahoang@orcsle147:/tmp$ icc -V
Intel(R) C Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 18.0.3.222 Build 20180410
Copyright (C) 1985-2018 Intel Corporation.  All rights reserved.

 

 

Screenshot of 18.0.0 vs. 18.0.3

Attachments: 

AttachmentSize
Downloadimage/jpeg icpc18.0.0vs-icpc18.0.3.JPG36.32 KB

Leave a Comment

Please sign in to add a comment. Not a member? Join today