[PATCH] D98947: [Orc] Fix copy elision warning in RPCUtils

Stefan Gränitz via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 19 07:05:07 PDT 2021


sgraenitz created this revision.
sgraenitz added reviewers: thakis, lhames.
sgraenitz requested review of this revision.
Herald added a project: LLVM.

The `callB()` template function always moved errors on return, because in the majority of cases its return type is an `Expected<T>` and the error must be moved into the implicit ctor.
For the special case of a `void` result, however, the `ResultTraits` class is specialized and the return type is a raw `Error`. Some build bots complain, that in favor of NRVO errors should not be moved in this case.

  llvm/include/llvm/ExecutionEngine/Orc/Shared/RPCUtils.h:1513:27:
  llvm/include/llvm/ExecutionEngine/Orc/Shared/RPCUtils.h:1519:27:
  llvm/include/llvm/ExecutionEngine/Orc/Shared/RPCUtils.h:1526:29:
    warning: moving a local object in a return statement prevents copy elision [-Wpessimizing-move]

The warning is reasonable from a type-system point of view. For performance it's entirely insignificant.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D98947

Files:
  llvm/include/llvm/ExecutionEngine/Orc/Shared/RPCUtils.h


Index: llvm/include/llvm/ExecutionEngine/Orc/Shared/RPCUtils.h
===================================================================
--- llvm/include/llvm/ExecutionEngine/Orc/Shared/RPCUtils.h
+++ llvm/include/llvm/ExecutionEngine/Orc/Shared/RPCUtils.h
@@ -243,6 +243,8 @@
   static void consumeAbandoned(ErrorReturnType RetOrErr) {
     consumeError(RetOrErr.takeError());
   }
+
+  ErrorReturnType returnError(Error Err) { return std::move(Err); }
 };
 
 // ResultTraits specialization for void functions.
@@ -275,6 +277,8 @@
   static void consumeAbandoned(ErrorReturnType Err) {
     consumeError(std::move(Err));
   }
+
+  ErrorReturnType returnError(Error Err) { return Err; }
 };
 
 // ResultTraits<Error> is equivalent to ResultTraits<void>. This allows
@@ -1494,8 +1498,9 @@
   typename detail::ResultTraits<AltRetT>::ErrorReturnType
   callB(const ArgTs &...Args) {
     bool ReceivedResponse = false;
-    using ResultType = typename detail::ResultTraits<AltRetT>::ErrorReturnType;
-    auto Result = detail::ResultTraits<AltRetT>::createBlankErrorReturnValue();
+    using RTraits = detail::ResultTraits<AltRetT>;
+    using ResultType = typename RTraits::ErrorReturnType;
+    ResultType Result = RTraits::createBlankErrorReturnValue();
 
     // We have to 'Check' result (which we know is in a success state at this
     // point) so that it can be overwritten in the async handler.
@@ -1508,22 +1513,19 @@
               return Error::success();
             },
             Args...)) {
-      detail::ResultTraits<typename Func::ReturnType>::consumeAbandoned(
-          std::move(Result));
-      return std::move(Err);
+      RTraits::consumeAbandoned(std::move(Result));
+      return RTraits::returnError(std::move(Err));
     }
 
     if (auto Err = this->C.send()) {
-      detail::ResultTraits<typename Func::ReturnType>::consumeAbandoned(
-          std::move(Result));
-      return std::move(Err);
+      RTraits::consumeAbandoned(std::move(Result));
+      return RTraits::returnError(std::move(Err));
     }
 
     while (!ReceivedResponse) {
       if (auto Err = this->handleOne()) {
-        detail::ResultTraits<typename Func::ReturnType>::consumeAbandoned(
-            std::move(Result));
-        return std::move(Err);
+        RTraits::consumeAbandoned(std::move(Result));
+        return RTraits::returnError(std::move(Err));
       }
     }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98947.331861.patch
Type: text/x-patch
Size: 2381 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210319/9bea151d/attachment.bin>


More information about the llvm-commits mailing list