[PATCH] D43244: Check that Symbol types are trivially destructible

Sam Clegg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 13 09:22:37 PST 2018


sbc100 created this revision.
Herald added subscribers: llvm-commits, aheejin, arichardson, emaste.
sbc100 retitled this revision from "Check that Symbol types are trvially destructible

This adds an extra level of static safety to our use of placement
new to allocate Symbol types.  It prevents the accidental addition
on a non-trivially-destructible member that could allocate and..." to "Check that Symbol types are trvially destructible".
sbc100 edited the summary of this revision.
sbc100 retitled this revision from "Check that Symbol types are trvially destructible" to "Check that Symbol types are trivially destructible".
sbc100 added reviewers: ruiu, ncw.

This adds an extra level of static safety to our use of placement
new to allocate Symbol types.  It prevents the accidental addition
of a non-trivially-destructible member that could allocate and
leak memory.

>From the spec: Storage occupied by trivially destructible objects
may be reused without calling the destructor.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D43244

Files:
  COFF/Symbols.h
  ELF/Symbols.h


Index: ELF/Symbols.h
===================================================================
--- ELF/Symbols.h
+++ ELF/Symbols.h
@@ -350,6 +350,8 @@
 
 template <typename T, typename... ArgT>
 void replaceSymbol(Symbol *S, ArgT &&... Arg) {
+  static_assert(std::is_trivially_destructible<T>(),
+                "Symbol types must be trivially destructible");
   static_assert(sizeof(T) <= sizeof(SymbolUnion), "SymbolUnion too small");
   static_assert(alignof(T) <= alignof(SymbolUnion),
                 "SymbolUnion not aligned enough");
Index: COFF/Symbols.h
===================================================================
--- COFF/Symbols.h
+++ COFF/Symbols.h
@@ -416,6 +416,8 @@
 
 template <typename T, typename... ArgT>
 void replaceSymbol(Symbol *S, ArgT &&... Arg) {
+  static_assert(std::is_trivially_destructible<T>(),
+                "Symbol types must be trivially destructible");
   static_assert(sizeof(T) <= sizeof(SymbolUnion), "Symbol too small");
   static_assert(alignof(T) <= alignof(SymbolUnion),
                 "SymbolUnion not aligned enough");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43244.134058.patch
Type: text/x-patch
Size: 1074 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180213/baa7dd90/attachment.bin>


More information about the llvm-commits mailing list