From 2597d07f15a1a3d6af793437f79b5bc972faeb36 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Fri, 5 Feb 2016 22:32:52 +0000 Subject: [PATCH] More workarounds for undefined behavior exposed when compiling in C++14 with -fsized-deallocation. Disable sized deallocation for all objects derived from TrailingObjects, as we expect the storage allocated for these objects to be larger than the size of their dynamic type. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@259942 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/TrailingObjects.h | 8 +++++++- lib/IR/AttributeImpl.h | 4 ++++ unittests/Support/TrailingObjectsTest.cpp | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/include/llvm/Support/TrailingObjects.h b/include/llvm/Support/TrailingObjects.h index 6c721f267be..8719702e5e6 100644 --- a/include/llvm/Support/TrailingObjects.h +++ b/include/llvm/Support/TrailingObjects.h @@ -79,6 +79,11 @@ public: /// The base class for TrailingObjects* classes. class TrailingObjectsBase { +public: + /// 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); } + protected: /// OverloadToken's purpose is to allow specifying function overloads /// for different types, without actually taking the types as @@ -290,7 +295,8 @@ class TrailingObjects : private trailing_objects_internal::TrailingObjectsImpl< } public: - // make this (privately inherited) class public. + // Make these (privately inherited) members public. + using ParentType::operator delete; using ParentType::OverloadToken; /// Returns a pointer to the trailing object array of the given type diff --git a/lib/IR/AttributeImpl.h b/lib/IR/AttributeImpl.h index ca7ae5cbb29..f23e9585cf0 100644 --- a/lib/IR/AttributeImpl.h +++ b/lib/IR/AttributeImpl.h @@ -171,6 +171,8 @@ class AttributeSetNode final void operator=(const AttributeSetNode &) = delete; AttributeSetNode(const AttributeSetNode &) = delete; public: + using TrailingObjects::operator delete; + static AttributeSetNode *get(LLVMContext &C, ArrayRef Attrs); bool hasAttribute(Attribute::AttrKind Kind) const { @@ -266,6 +268,8 @@ public: } } + using TrailingObjects::operator delete; + /// \brief Get the context that created this AttributeSetImpl. LLVMContext &getContext() { return Context; } diff --git a/unittests/Support/TrailingObjectsTest.cpp b/unittests/Support/TrailingObjectsTest.cpp index 170cbc372b8..92cdd6d3824 100644 --- a/unittests/Support/TrailingObjectsTest.cpp +++ b/unittests/Support/TrailingObjectsTest.cpp @@ -34,6 +34,7 @@ public: void *Mem = ::operator new(totalSizeToAlloc(NumShorts)); return new (Mem) Class1(ShortArray, NumShorts); } + using TrailingObjects::operator delete; short get(unsigned Num) const { return getTrailingObjects()[Num]; } @@ -78,6 +79,7 @@ public: *C->getTrailingObjects() = D; return C; } + using TrailingObjects::operator delete; short getShort() const { if (!HasShort) -- 2.11.0