[llvm] e7ed5c9 - Revert "Revert "Support: Use std::unique_ptr for SignpostEmitter::Impl, NFC""

Duncan P. N. Exon Smith via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 8 16:54:23 PDT 2021


Author: Duncan P. N. Exon Smith
Date: 2021-04-08T16:50:39-07:00
New Revision: e7ed5c920db3f537a85d962c1c918a1bb6de99fd

URL: https://github.com/llvm/llvm-project/commit/e7ed5c920db3f537a85d962c1c918a1bb6de99fd
DIFF: https://github.com/llvm/llvm-project/commit/e7ed5c920db3f537a85d962c1c918a1bb6de99fd.diff

LOG: Revert "Revert "Support: Use std::unique_ptr for SignpostEmitter::Impl, NFC""

This reverts commit 078072285d3fbdaa94f9a91140eb5c1223b548af, reapplying
022ccedde8877e877b45e49641544b5e4fff0b42.

I figured out why this was failing in other environments: it's not a
problem with std::unique_ptr, but that SignpostEmitterImpl only has a
forward declaration. Adding an empty definition should do the trick.

Original commit message:

    Replace some manual memory management with std::unique_ptr.

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

Added: 
    

Modified: 
    llvm/include/llvm/Support/Signposts.h
    llvm/lib/Support/Signposts.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Support/Signposts.h b/llvm/include/llvm/Support/Signposts.h
index 22b04893394e..d31f3c1e6eb5 100644
--- a/llvm/include/llvm/Support/Signposts.h
+++ b/llvm/include/llvm/Support/Signposts.h
@@ -18,6 +18,7 @@
 #define LLVM_SUPPORT_SIGNPOSTS_H
 
 #include "llvm/ADT/StringRef.h"
+#include <memory>
 
 namespace llvm {
 class SignpostEmitterImpl;
@@ -25,8 +26,7 @@ class SignpostEmitterImpl;
 /// Manages the emission of signposts into the recording method supported by
 /// the OS.
 class SignpostEmitter {
-  /// Not using std::unique_ptr since some hosts need a definition.
-  SignpostEmitterImpl *Impl;
+  std::unique_ptr<SignpostEmitterImpl> Impl;
 
 public:
   SignpostEmitter();

diff  --git a/llvm/lib/Support/Signposts.cpp b/llvm/lib/Support/Signposts.cpp
index b277bb02e03a..9d1fdeddba7c 100644
--- a/llvm/lib/Support/Signposts.cpp
+++ b/llvm/lib/Support/Signposts.cpp
@@ -96,21 +96,18 @@ class SignpostEmitterImpl {
 #define HAVE_ANY_SIGNPOST_IMPL 1
 #else
 #define HAVE_ANY_SIGNPOST_IMPL 0
+
+/// Definition necessary for use of std::unique_ptr.
+class SignpostEmitterImpl {};
 #endif
 
 SignpostEmitter::SignpostEmitter() {
 #if HAVE_ANY_SIGNPOST_IMPL
-  Impl = new SignpostEmitterImpl();
-#else  // if HAVE_ANY_SIGNPOST_IMPL
-  Impl = nullptr;
+  Impl = std::make_unique<SignpostEmitterImpl>();
 #endif // if !HAVE_ANY_SIGNPOST_IMPL
 }
 
-SignpostEmitter::~SignpostEmitter() {
-#if HAVE_ANY_SIGNPOST_IMPL
-  delete Impl;
-#endif // if HAVE_ANY_SIGNPOST_IMPL
-}
+SignpostEmitter::~SignpostEmitter() = default;
 
 bool SignpostEmitter::isEnabled() const {
 #if HAVE_ANY_SIGNPOST_IMPL


        


More information about the llvm-commits mailing list