ASan alloc-dealloc-mismatch and placement new

For a C++ program like

#include <new>
int main() {
    char * p1 = new char[sizeof (int)];
    int * p2 = new(p1) int;
    delete p2;
}

compiling it with -fsanitize=address will somewhat unhelpfully report an "AddressSanitizer: alloc-dealloc-mismatch (operator new vs operator delete)" failure.

Is there a good way to work around that (in the program's source code), short of using the generic ASan facilities of suppressing or blacklisting code, or using ASAN_OPTIONS=alloc_dealloc_mismatch=0 to disable the check completely?

For a C++ program like

#include <new>

int main() {
    char * p1 = new char[sizeof (int)];
    int * p2 = new(p1) int;
    delete p2;
}

compiling it with -fsanitize=address will somewhat unhelpfully report an
"AddressSanitizer: alloc-dealloc-mismatch (operator new vs operator
delete)" failure.

Is there a good way to work around that

Why not use "delete p1"?

    For a C++ program like

        #include <new>
        int main() {
          char * p1 = new char[sizeof (int)];
          int * p2 = new(p1) int;
          delete p2;
        }

    compiling it with -fsanitize=address will somewhat unhelpfully
    report an "AddressSanitizer: alloc-dealloc-mismatch (operator new
    vs operator delete)" failure.

    Is there a good way to work around that

Why not use "delete p1"?

Because in the real program, p2 is then passed off to some API that takes ownership, and internally calls delete. And both real and fake int* are handed off to that API, and I don't even control that API's implementation, so it can't be changed to a delete of the char array there. Also, the real program uses a class type with non-trivial destructor instead of int. (I probably should have been more careful when crafting this stripped-down example.)

(But the more I think about it, the less I'm sure the code is even legal...)

It's not legal. This is not an AddressSanitizer false positive. The form
and type of the allocation must match the deallocation.

-- James