[llvm] r260180 - Re-commit r259942 (reverted in r260053) with a different workaround for the MSVC bug.

Richard Smith via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 8 17:03:42 PST 2016


Author: rsmith
Date: Mon Feb  8 19:03:42 2016
New Revision: 260180

URL: http://llvm.org/viewvc/llvm-project?rev=260180&view=rev
Log:
Re-commit r259942 (reverted in r260053) with a different workaround for the MSVC bug.

This fixes undefined behavior in C++14 due to the size of the object being
deleted being different from sizeof(dynamic type) when it is allocated with
trailing objects.

MSVC seems to have several bugs around using-declarations changing the access
of a member inherited from a base class, so use forwarding functions instead of
using-declarations to make TrailingObjects::operator delete accessible where
desired.

Modified:
    llvm/trunk/include/llvm/Support/TrailingObjects.h
    llvm/trunk/lib/IR/AttributeImpl.h
    llvm/trunk/unittests/Support/TrailingObjectsTest.cpp

Modified: llvm/trunk/include/llvm/Support/TrailingObjects.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/TrailingObjects.h?rev=260180&r1=260179&r2=260180&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/TrailingObjects.h (original)
+++ llvm/trunk/include/llvm/Support/TrailingObjects.h Mon Feb  8 19:03:42 2016
@@ -290,9 +290,13 @@ class TrailingObjects : private trailing
   }
 
 public:
-  // make this (privately inherited) class public.
+  // Make this (privately inherited) member public.
   using ParentType::OverloadToken;
 
+  /// Disable sized deallocation for all objects with trailing object storage;
+  /// the inferred size will typically not be correct.
+  void operator delete(void *P) { return ::operator delete(P); }
+
   /// Returns a pointer to the trailing object array of the given type
   /// (which must be one of those specified in the class template). The
   /// array may have zero or more elements in it.

Modified: llvm/trunk/lib/IR/AttributeImpl.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/AttributeImpl.h?rev=260180&r1=260179&r2=260180&view=diff
==============================================================================
--- llvm/trunk/lib/IR/AttributeImpl.h (original)
+++ llvm/trunk/lib/IR/AttributeImpl.h Mon Feb  8 19:03:42 2016
@@ -171,6 +171,8 @@ class AttributeSetNode final
   void operator=(const AttributeSetNode &) = delete;
   AttributeSetNode(const AttributeSetNode &) = delete;
 public:
+  void operator delete(void *p) { TrailingObjects::operator delete(p); }
+
   static AttributeSetNode *get(LLVMContext &C, ArrayRef<Attribute> Attrs);
 
   bool hasAttribute(Attribute::AttrKind Kind) const {
@@ -266,6 +268,8 @@ public:
     }
   }
 
+  void operator delete(void *p) { TrailingObjects::operator delete(p); }
+
   /// \brief Get the context that created this AttributeSetImpl.
   LLVMContext &getContext() { return Context; }
 

Modified: llvm/trunk/unittests/Support/TrailingObjectsTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/TrailingObjectsTest.cpp?rev=260180&r1=260179&r2=260180&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/TrailingObjectsTest.cpp (original)
+++ llvm/trunk/unittests/Support/TrailingObjectsTest.cpp Mon Feb  8 19:03:42 2016
@@ -34,6 +34,7 @@ public:
     void *Mem = ::operator new(totalSizeToAlloc<short>(NumShorts));
     return new (Mem) Class1(ShortArray, NumShorts);
   }
+  void operator delete(void *p) { TrailingObjects::operator delete(p); }
 
   short get(unsigned Num) const { return getTrailingObjects<short>()[Num]; }
 
@@ -78,6 +79,7 @@ public:
       *C->getTrailingObjects<double>() = D;
     return C;
   }
+  void operator delete(void *p) { TrailingObjects::operator delete(p); }
 
   short getShort() const {
     if (!HasShort)




More information about the llvm-commits mailing list