This is an archive of the discontinued LLVM Phabricator instance.

[flang] Store KindMapping by value in FirOpBuilder
ClosedPublic

Authored by tblah on Jun 1 2023, 4:49 AM.

Details

Summary

Previously only a constant reference was stored in the FirOpBuilder.
However, a lot of code was merged using

FirOpBuilder builder{rewriter, getKindMapping(mod)};

This is incorrect because the KindMapping returned will go out of scope
as soon as FirOpBuilder's constructor had run. This led to an infinite
loop running some tests using HLFIR (because the stack space containing
the kind mapping was re-used and corrupted).

One solution would have just been to fix the incorrect call sites,
however, as a large number of these had already made it past review, I
decided to instead change FirOpBuilder to store its own copy of the
KindMapping. This is not costly because nearly every time we construct a
KindMapping is exclusively to construct a FirOpBuilder. To make this
common pattern simpler, I added a new constructor to FirOpBuilder which
calls getKindMapping().

Diff Detail

Event Timeline

tblah created this revision.Jun 1 2023, 4:49 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJun 1 2023, 4:49 AM
tblah requested review of this revision.Jun 1 2023, 4:49 AM
tblah edited the summary of this revision. (Show Details)Jun 1 2023, 4:49 AM
tblah updated this revision to Diff 527368.Jun 1 2023, 4:52 AM

Changes: clang-format

vzakhari added inline comments.Jun 1 2023, 1:20 PM
flang/include/flang/Optimizer/Builder/FIRBuilder.h
59

The copy construction was cheap before this change, so it did not make sense to have a move constructor. Does it make sense to add it now?

tblah updated this revision to Diff 527791.Jun 2 2023, 2:57 AM

Thanks for review

Changes: add a move constructor to FirOpBuilder

vzakhari accepted this revision.Jun 2 2023, 8:59 AM

Thank you!

This revision is now accepted and ready to land.Jun 2 2023, 8:59 AM
This revision was automatically updated to reflect the committed changes.