[lld] r325025 - Check that Symbol types are trivially destructible

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 13 09:32:31 PST 2018


Author: sbc
Date: Tue Feb 13 09:32:31 2018
New Revision: 325025

URL: http://llvm.org/viewvc/llvm-project?rev=325025&view=rev
Log:
Check that Symbol types are trivially 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
leak memory.

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

Differential Revision: https://reviews.llvm.org/D43244

Modified:
    lld/trunk/COFF/Symbols.h
    lld/trunk/ELF/Symbols.h

Modified: lld/trunk/COFF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Symbols.h?rev=325025&r1=325024&r2=325025&view=diff
==============================================================================
--- lld/trunk/COFF/Symbols.h (original)
+++ lld/trunk/COFF/Symbols.h Tue Feb 13 09:32:31 2018
@@ -416,6 +416,8 @@ union SymbolUnion {
 
 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");

Modified: lld/trunk/ELF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=325025&r1=325024&r2=325025&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.h (original)
+++ lld/trunk/ELF/Symbols.h Tue Feb 13 09:32:31 2018
@@ -350,6 +350,8 @@ void printTraceSymbol(Symbol *Sym);
 
 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");




More information about the llvm-commits mailing list