[flang-commits] [PATCH] D88797: [flang] Fix copy elision assumption.

Michael Kruse via Phabricator via flang-commits flang-commits at lists.llvm.org
Mon Dec 14 12:08:44 PST 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG2aa43358060c: [flang] Fix copy elision assumption. (authored by Meinersbur).

Changed prior to commit:
  https://reviews.llvm.org/D88797?vs=303612&id=311668#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88797/new/

https://reviews.llvm.org/D88797

Files:
  flang/include/flang/Common/restorer.h
  flang/lib/Semantics/check-declarations.cpp


Index: flang/lib/Semantics/check-declarations.cpp
===================================================================
--- flang/lib/Semantics/check-declarations.cpp
+++ flang/lib/Semantics/check-declarations.cpp
@@ -1498,7 +1498,7 @@
 
 void CheckHelper::Check(const Scope &scope) {
   scope_ = &scope;
-  common::Restorer<const Symbol *> restorer{innermostSymbol_};
+  common::Restorer<const Symbol *> restorer{innermostSymbol_, innermostSymbol_};
   if (const Symbol * symbol{scope.symbol()}) {
     innermostSymbol_ = symbol;
   }
Index: flang/include/flang/Common/restorer.h
===================================================================
--- flang/include/flang/Common/restorer.h
+++ flang/include/flang/Common/restorer.h
@@ -22,9 +22,16 @@
 namespace Fortran::common {
 template <typename A> class Restorer {
 public:
-  explicit Restorer(A &p) : p_{p}, original_{std::move(p)} {}
+  explicit Restorer(A &p, A original) : p_{p}, original_{std::move(original)} {}
   ~Restorer() { p_ = std::move(original_); }
 
+  // Inhibit any recreation of this restorer that would result in two restorers
+  // trying to restore the same reference.
+  Restorer(const Restorer &) = delete;
+  Restorer(Restorer &&that) = delete;
+  const Restorer &operator=(const Restorer &) = delete;
+  const Restorer &operator=(Restorer &&that) = delete;
+
 private:
   A &p_;
   A original_;
@@ -32,15 +39,15 @@
 
 template <typename A, typename B>
 common::IfNoLvalue<Restorer<A>, B> ScopedSet(A &to, B &&from) {
-  Restorer<A> result{to};
+  A original{std::move(to)};
   to = std::move(from);
-  return result;
+  return Restorer<A>{to, std::move(original)};
 }
 template <typename A, typename B>
 common::IfNoLvalue<Restorer<A>, B> ScopedSet(A &to, const B &from) {
-  Restorer<A> result{to};
+  A original{std::move(to)};
   to = from;
-  return result;
+  return Restorer<A>{to, std::move(original)};
 }
 } // namespace Fortran::common
 #endif // FORTRAN_COMMON_RESTORER_H_


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88797.311668.patch
Type: text/x-patch
Size: 1964 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20201214/bc427cec/attachment.bin>


More information about the flang-commits mailing list