Reland (again) D80966 [codeview] Put !heapallocsite on calls to operator new
authorArthur Eubanks <aeubanks@google.com>
Tue, 9 Jun 2020 02:07:59 +0000 (19:07 -0700)
committerArthur Eubanks <aeubanks@google.com>
Tue, 9 Jun 2020 16:27:32 +0000 (09:27 -0700)
commitce7d3e1c5531fce828722379cfbd58cb5d4dfab9
treedf85db57218b1f7ddabef8e60ff0a1a7b5fdc476
parent406ac49fb05e04e874623a3e955276a134dc82ea
Reland (again) D80966 [codeview] Put !heapallocsite on calls to operator new

Check that getDebugInfo() is not null, as in the first revision, before
calling getDebugInfo()->addHeapAllocSiteMetadata().
Else would cause a crash with a new expression in a default arg.

---

Clang marks calls to operator new as heap allocation sites, but the
operator declared at global scope returns a void pointer. There is no
explicit cast in the code, so the compiler has to write down the
allocated type itself.

Also generalize a cast to use CallBase, so that we mark heap alloc sites
when exceptions are enabled.

Differential Revision: https://reviews.llvm.org/D80966
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/CGDebugInfo.cpp
clang/lib/CodeGen/CGDebugInfo.h
clang/lib/CodeGen/CGExprCXX.cpp
clang/lib/CodeGen/CGExprScalar.cpp
clang/test/CodeGen/debug-info-codeview-heapallocsite.c
clang/test/CodeGenCXX/debug-info-codeview-heapallocsite.cpp [new file with mode: 0644]