Skip to content

Commit f8aa497

Browse files
committed
[libunwind] Provide placement new definition
While Clang automatically generates the code for placement new, g++ doesn't do that so we need to provide our own definition. Differential Revision: https://reviews.llvm.org/D57455 llvm-svn: 352966
1 parent 59d65be commit f8aa497

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

libunwind/src/Unwind-seh.cpp

+9-6
Original file line numberDiff line numberDiff line change
@@ -442,20 +442,23 @@ _Unwind_GetRegionStart(struct _Unwind_Context *context) {
442442
static int
443443
_unw_init_seh(unw_cursor_t *cursor, CONTEXT *context) {
444444
#ifdef _LIBUNWIND_TARGET_X86_64
445-
new ((void *)cursor) UnwindCursor<LocalAddressSpace, Registers_x86_64>(
446-
context, LocalAddressSpace::sThisAddressSpace);
445+
new (reinterpret_cast<UnwindCursor<LocalAddressSpace, Registers_x86_64> *>(cursor))
446+
UnwindCursor<LocalAddressSpace, Registers_x86_64>(
447+
context, LocalAddressSpace::sThisAddressSpace);
447448
auto *co = reinterpret_cast<AbstractUnwindCursor *>(cursor);
448449
co->setInfoBasedOnIPRegister();
449450
return UNW_ESUCCESS;
450451
#elif defined(_LIBUNWIND_TARGET_ARM)
451-
new ((void *)cursor) UnwindCursor<LocalAddressSpace, Registers_arm>(
452-
context, LocalAddressSpace::sThisAddressSpace);
452+
new (reinterpret_cast<UnwindCursor<LocalAddressSpace, Registers_arm> *>(cursor))
453+
UnwindCursor<LocalAddressSpace, Registers_arm>(
454+
context, LocalAddressSpace::sThisAddressSpace);
453455
auto *co = reinterpret_cast<AbstractUnwindCursor *>(cursor);
454456
co->setInfoBasedOnIPRegister();
455457
return UNW_ESUCCESS;
456458
#elif defined(_LIBUNWIND_TARGET_AARCH64)
457-
new ((void *)cursor) UnwindCursor<LocalAddressSpace, Registers_arm64>(
458-
context, LocalAddressSpace::sThisAddressSpace);
459+
new (reinterpret_cast<UnwindCursor<LocalAddressSpace, Registers_arm64> *>(cursor))
460+
UnwindCursor<LocalAddressSpace, Registers_arm64>(
461+
context, LocalAddressSpace::sThisAddressSpace);
459462
auto *co = reinterpret_cast<AbstractUnwindCursor *>(cursor);
460463
co->setInfoBasedOnIPRegister();
461464
return UNW_ESUCCESS;

libunwind/src/UnwindCursor.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,10 @@ class UnwindCursor : public AbstractUnwindCursor{
892892
virtual void saveVFPAsX();
893893
#endif
894894

895+
// libunwind does not and should not depend on C++ library which means that we
896+
// need our own defition of inline placement new.
897+
static void *operator new(size_t, UnwindCursor<A, R> *p) { return p; }
898+
895899
private:
896900

897901
#if defined(_LIBUNWIND_ARM_EHABI)

libunwind/src/libunwind.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ _LIBUNWIND_EXPORT int unw_init_local(unw_cursor_t *cursor,
7171
# error Architecture not supported
7272
#endif
7373
// Use "placement new" to allocate UnwindCursor in the cursor buffer.
74-
new ((void *)cursor) UnwindCursor<LocalAddressSpace, REGISTER_KIND>(
75-
context, LocalAddressSpace::sThisAddressSpace);
74+
new (reinterpret_cast<UnwindCursor<LocalAddressSpace, REGISTER_KIND> *>(cursor))
75+
UnwindCursor<LocalAddressSpace, REGISTER_KIND>(
76+
context, LocalAddressSpace::sThisAddressSpace);
7677
#undef REGISTER_KIND
7778
AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor;
7879
co->setInfoBasedOnIPRegister();

0 commit comments

Comments
 (0)