<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/154795>154795</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Clang-tidy invalid suggestion: performance-unnecessary-value-param #154755
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang-tidy
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          joker-eph
      </td>
    </tr>
</table>

<pre>
    With clang-tidy built at current head and applying it on MLIR:


```
$ clang-tidy -p build mlir/lib/Dialect/Tosa/Transforms/TosaProfileCompliance.cpp --checks=-*,performance-unnecessary-copy-initialization -fix -fix-errors
```

Yield this diff:

```
diff --git a/mlir/lib/Dialect/Tosa/Transforms/TosaProfileCompliance.cpp b/mlir/lib/Dialect/Tosa/Transforms/TosaProfileCompliance.cpp
index 20f9333e7c95..1438266472f2 100644
--- a/mlir/lib/Dialect/Tosa/Transforms/TosaProfileCompliance.cpp
+++ b/mlir/lib/Dialect/Tosa/Transforms/TosaProfileCompliance.cpp
@@ -381,7 +381,7 @@ LogicalResult TosaProfileCompliance::checkProfileOrExtension(
 
 // Find the required profiles or extensions according to the operand type
 // combination.
-  const auto opRequiredMode = maybeOpRequiredMode.value();
+  const auto &&opRequiredMode = maybeOpRequiredMode.value();
   if (opRequiredMode.size() == 0) {
     // No matched restriction found.
     return success();
```

Fails to build with:

```
FAILED: tools/mlir/lib/Dialect/Tosa/Transforms/CMakeFiles/obj.MLIRTosaTransforms.dir/TosaProfileCompliance.cpp.o 
CCACHE_CPP2=yes CCACHE_HASHDIR=yes /usr/bin/ccache /home/mamini/bin/clang++ -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Ibuild/tools/mlir/lib/Dialect/Tosa/Transforms -Imlir/lib/Dialect/Tosa/Transforms -Ibuild/tools/mlir/include -Imlir/include -Ibuild/include -Illvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -Wundef -Werror=mismatched-tags -Werror=global-constructors -O3 -DNDEBUG -std=c++17  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -MD -MT tools/mlir/lib/Dialect/Tosa/Transforms/CMakeFiles/obj.MLIRTosaTransforms.dir/TosaProfileCompliance.cpp.o -MF tools/mlir/lib/Dialect/Tosa/Transforms/CMakeFiles/obj.MLIRTosaTransforms.dir/TosaProfileCompliance.cpp.o.d -o tools/mlir/lib/Dialect/Tosa/Transforms/CMakeFiles/obj.MLIRTosaTransforms.dir/TosaProfileCompliance.cpp.o -c mlir/lib/Dialect/Tosa/Transforms/TosaProfileCompliance.cpp
mlir/lib/Dialect/Tosa/Transforms/TosaProfileCompliance.cpp:384:16: error: rvalue reference to type 'const SmallVector<...>' cannot bind to lvalue of type 'const SmallVector<...>'
  384 |   const auto &&opRequiredMode = maybeOpRequiredMode.value();
      |                ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
mlir/lib/Dialect/Tosa/Transforms/TosaProfileCompliance.cpp:447:12: note: in instantiation of function template specialization 'TosaProfileCompliance::checkProfileOrExtension<mlir::tosa::Profile>' requested here
  447 |     return checkProfileOrExtension<Profile>(op, targetEnv,
      | ^
mlir/lib/Dialect/Tosa/Transforms/TosaProfileCompliance.cpp:384:16: error: rvalue reference to type 'const SmallVector<...>' cannot bind to lvalue of type 'const SmallVector<...>'
  384 |   const auto &&opRequiredMode = maybeOpRequiredMode.value();
      |                ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
mlir/lib/Dialect/Tosa/Transforms/TosaProfileCompliance.cpp:457:12: note: in instantiation of function template specialization 'TosaProfileCompliance::checkProfileOrExtension<mlir::tosa::Extension>' requested here
  457 |     return checkProfileOrExtension<Extension>(op, targetEnv,
      |            ^
2 errors generated.
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsWE9v2zoS_zT0ZUBDpiz_OfigyHZroEmK2F2_PQU0ObLZ0qQeSbnNO-xnX5BWame3wW4fAnQXeIFiy8Phj5yZH2dG4t6rvUGckeKGFPMeb8PButln-wUdxebQ21n5NNuqcAChudnToOQT7FqlA_AAonUOTYADcgncSOBNo5-U2YMKYA3cflg9kLwk2fM1yrorKwkbXmPSJsFKOGrlCFtqtSNsOVdcowiELTfW8_jluPG1dUffyT46WyuNlT02WnEjsC-aBigVBxRfPMnnlLCSsKpBF6dFDdoagwK95-6JCts8UWVUUFyrP3hQ1gCt1bf0QdE56_y_7jwr_65QSwgH5UGqur7YeKUWB4DSvQoQd_4mdu3eCIhkpTISvwHL6mme5zgW06LfHwzzCRuNhmNWMxhk2Wg4JFlJKX0zC1Lgb87XW1pDhhkZZkDzyYCwagyE3Xy_PQ99sHsluH5A3-oAP8SKYczLxJxu7N4tvgU0XllD2IRkJaR_tiRsCUtlIgcQHP7eKocSmvMsD9YBPk_0wIWwTsZjEWyaYBt08biEpwavAIU97pRJHOxHvwMIa3wA3gYLtnnolrm1EoHkczjypx3ev5D3T1y3GPfKpiS_Obv7BQ5hI8JGfxYNAFQNhE1eAvS9-qPTi1gRLkv3424SPNt4Z-HIgzigBIc-OCXSkatta2T_WddhaJ0B34p4TF9Y8_IcLrnSPnr1nDu-qnD44VlclqsPiznJSwjWav9zvKtu-RdcxrgStrS7z_2Y1qLiRasvE9qrDO3bSJyqKqv3i8fq40dG8vkTeugk78v1-3lMlUlI2LL1EW6nD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