OSDN Git Service

Assigning to a local object in a return statement prevents copy elision. NFC.
authorDavid Blaikie <dblaikie@gmail.com>
Thu, 25 Apr 2019 20:09:00 +0000 (20:09 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Thu, 25 Apr 2019 20:09:00 +0000 (20:09 +0000)
commit434bbb1a68dcc18741518154b9ff1f06731484b6
tree9d549ee44a015db9886d9f29d0cdf710fdd1cce3
parent9629553b79070c058aee0a6d60263aadf0c13473
Assigning to a local object in a return statement prevents copy elision. NFC.

I added a diagnostic along the lines of `-Wpessimizing-move` to detect `return x = y` suppressing copy elision, but I don't know if the diagnostic is really worth it. Anyway, here are the places where my diagnostic reported that copy elision would have been possible if not for the assignment.

P1155R1 in the post-San-Diego WG21 (C++ committee) mailing discusses whether WG21 should fix this pitfall by just changing the core language to permit copy elision in cases like these.

(Kona update: The bulk of P1155 is proceeding to CWG review, but specifically *not* the parts that explored the notion of permitting copy-elision in these specific cases.)

Reviewed By: dblaikie

Author: Arthur O'Dwyer

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@359236 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/CodeGen/MachineInstrBundle.h
include/llvm/Support/BranchProbability.h
lib/Support/Path.cpp
lib/Target/X86/X86MCInstLower.cpp
lib/Transforms/Instrumentation/Instrumentation.cpp