[PATCH] Fallback to operator new for MSVC compatibility

Aaron Ballman aaron at aaronballman.com
Tue May 28 12:26:55 PDT 2013


MSVC has a "neat trick" where it automatically falls back onto
operator new when a placement operator new[] is called for which there
is no valid declaration.  Eg)

struct arbitrary_t {} arbitrary;
void *operator new(unsigned int size, arbitrary_t);

void f() {
  int *p = new(arbitrary) int[4];
  int *p2 = new(arbitrary) int;
}

MSVC will emit code to call operator new even though operator new[]
does not exist.
...
push 16 ; 00000010H
call ??2 at YAPAXIUarbitrary_t@@@Z ; operator new
...
push 4
call ??2 at YAPAXIUarbitrary_t@@@Z ; operator new
...

This patch emulates the MSVC behavior when compiling in
ms-compatibility mode and tests both the semantic requirements as well
as the codegen requirements.  It addresses PR13164, which points out
that this is holding back usage for the WDK because it does not
implement the array version of nothrow'ing new.

~Aaron
-------------- next part --------------
A non-text attachment was scrubbed...
Name: operator_new.patch
Type: application/octet-stream
Size: 2308 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130528/f31f65df/attachment.obj>


More information about the cfe-commits mailing list