This is an archive of the discontinued LLVM Phabricator instance.

[flang] move getKindMapping() calls out of FIROpBuilder ctor calls
ClosedPublic

Authored by jeanPerier on Jul 11 2022, 8:41 AM.

Details

Summary

FirOpBuilder takes a fir::KindMapping reference. When the getKindMapping()
call is made inside the ctor call, the lifetime of this reference may
be as short as the ctor call (at least with when building flang in
release mode with clang 8). This can cause segfaults when later using
the FirOpBuilder.

Ensure the kindMap passed to the FirOpBuilder ctor is the same as the
FirOpBuilder.

Diff Detail

Event Timeline

jeanPerier created this revision.Jul 11 2022, 8:41 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 11 2022, 8:41 AM
jeanPerier requested review of this revision.Jul 11 2022, 8:41 AM
clementval accepted this revision.Jul 11 2022, 8:49 AM

LGTM.

Just a nit (FirOpBuilder -> fir::FirOpBuilder).

flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp
225
This revision is now accepted and ready to land.Jul 11 2022, 8:49 AM
PeteSteinfeld requested changes to this revision.Jul 11 2022, 9:37 AM

These changes look good. But it looks like there are another two instances of this problem in .../flang/lib/Optimizer/CodeGen/TargetRewrite.cpp. Did you take a look at that file?

This revision now requires changes to proceed.Jul 11 2022, 9:37 AM

Also move two calls in TargetRewrite.cpp.

These changes look good. But it looks like there are another two instances of this problem in .../flang/lib/Optimizer/CodeGen/TargetRewrite.cpp. Did you take a look at that file?

Good Catch, thanks Pete ! I also updated them (the last call in fir::CodeGenSpecifics::get is what it should be, the KinMapping is moved there, not taken by reference).

PeteSteinfeld accepted this revision.Jul 11 2022, 1:46 PM

Thanks for figuring this out.

All builds and tests correctly and looks good.

This revision is now accepted and ready to land.Jul 11 2022, 1:46 PM