Skip to contentSkip to conversation

perf clang: Do not use 'return std::move(something)'

tip:perf/urgent tip-bot for Arnaldo Carvalho de Melo 1 participant 1 message Feb 9, 2019 perf events

lore
Share & tools
lore
#0 lore raw
Commit-ID:  d34cecfb6b2bdc35713180ba4fcfd912a2f3e9bf
Gitweb:     https://git.kernel.org/tip/d34cecfb6b2bdc35713180ba4fcfd912a2f3e9bf
Author:     Arnaldo Carvalho de Melo <[email protected]>
AuthorDate: Mon, 4 Feb 2019 11:04:20 -0300
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 4 Feb 2019 11:32:34 -0300

perf clang: Do not use 'return std::move(something)'

It prevents copy elision, generating this warning when building with fedora:rawhide's clang:

clang version 7.0.1 (Fedora 7.0.1-2.fc30)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/9 Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/9 Selected GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/9 Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64

  $ make -C tools/perf CC=clang LIBCLANGLLVM=1
  <SNIP>
  util/c++/clang.cpp: In function 'std::unique_ptr<llvm::SmallVectorImpl<char> > perf::getBPFObjectFromModule(llvm::Module*)':
  util/c++/clang.cpp:163:18: error: moving a local object in a return statement prevents copy elision [-Werror=pessimizing-move]
    163 |  return std::move(Buffer);
        |         ~~~~~~~~~^~~~~~~~
  util/c++/clang.cpp:163:18: note: remove 'std::move' call
  cc1plus: all warnings being treated as errors
  <SNIP>

References:

http://www.cplusplus.com/forum/general/186411/#msg908572
https://en.cppreference.com/w/cpp/language/return#Notes
https://en.cppreference.com/w/cpp/language/copy_elision

---
 tools/perf/util/c++/clang.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/c++/clang.cpp +1 -1
index 89512504551b..39c0004f2886 100644
@@ -160,7 +160,7 @@ getBPFObjectFromModule(llvm::Module *Module)
 	}
 	PM.run(*Module);
 
-	return std::move(Buffer);
+	return Buffer;
 }
 
 }