This is an archive of the discontinued LLVM Phabricator instance.

[flang] Fix copy elision assumption.
ClosedPublic

Authored by Meinersbur on Oct 4 2020, 3:39 AM.

Details

Summary

Like D88794, the Restorer depends on copy elision to happen. Without copy elision, the function ScopedSet calls the move constructor before its dtor. The dtor will prematurely restore the reference to the original value.

Inhibit recreating the restorer object completely to avoid the implicit creation of a second restorer object that would try to move the same object. The factory class ScopedSet is changed to use unnamed return value optimization which is mandatory in C++17.

Diff Detail

Event Timeline

Meinersbur created this revision.Oct 4 2020, 3:39 AM
Herald added a project: Restricted Project. · View Herald Transcript
Meinersbur requested review of this revision.Oct 4 2020, 3:39 AM

A much smaller work-around: extend the sole constructor of Restorer to accept a reference and a value, and then modify ScopedSet to construct its result as part of the return statement. Restorer doesn't need move construction or move assignment for its clients.

Meinersbur updated this revision to Diff 303612.Nov 6 2020, 8:37 PM

Implement @klausler's suggestion.

Meinersbur edited the summary of this revision. (Show Details)Nov 6 2020, 8:50 PM
klausler accepted this revision.Nov 11 2020, 2:01 PM
klausler added inline comments.
flang/include/flang/Common/restorer.h
25

Here, and below: we're using lower-case names in flang/ for variables.

This revision is now accepted and ready to land.Nov 11 2020, 2:01 PM
This revision was automatically updated to reflect the committed changes.