[llvm-bugs] [Bug 42096] New: Inplace new-ing an array overwrites the square of the memory

via llvm-bugs llvm-bugs at lists.llvm.org
Fri May 31 11:42:49 PDT 2019


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

            Bug ID: 42096
           Summary: Inplace new-ing an array overwrites the square of the
                    memory
           Product: clang
           Version: 8.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: alisdairm at me.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

When in-place new-ing a local variable of an array of trivial type, the
generated code calls 'memset' with the square of the size of the array,
corrupting the stack.

Quick example:

#include <new>

template <typename TYPE>
void f()
{
    typedef TYPE TArray[7];

    TArray x;
    new(&x) TArray();
}

int main()
{
    f<char>();
    f<int>();
}


Sample code generation can be seen for Clang 7 and 8 via godbolt:
https://godbolt.org/z/WjhFrc

-- 
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/20190531/8c38b8fe/attachment.html>


More information about the llvm-bugs mailing list