This is an archive of the discontinued LLVM Phabricator instance.

[unittests/CodeGen] Remove unique_ptr from the result of createTargetMachine
ClosedPublic

Authored by Carrot on Aug 12 2022, 10:09 AM.

Details

Summary

The object contained in unique_ptr will be automatically deleted at the end of the current scope. In createMachineFunction,

auto TM = createTargetMachine();

creates a TM contained in unique_ptr, a reference of the TM is stored in a MachineFunction object, but at the end of the function, the TM is deleted, so later access to the TM(and contained STI, TRI ...) through MachineFunction object is invalid.

So we should not use unique_ptr<BogusTargetMachine> in functions createMachineFunction and createTargetMachine.

Diff Detail

Event Timeline

Carrot created this revision.Aug 12 2022, 10:09 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 12 2022, 10:09 AM
Carrot requested review of this revision.Aug 12 2022, 10:09 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 12 2022, 10:09 AM
thegameg added inline comments.Aug 16 2022, 10:03 AM
llvm/unittests/CodeGen/MFCommon.inc
120

If it's only used in one test maybe we can create a local TM instead of a static one and pass it to createMachineFunction?

Carrot added inline comments.Aug 16 2022, 12:16 PM
llvm/unittests/CodeGen/MFCommon.inc
120

grep shows there are 13 uses of createMachineFunction.

thegameg accepted this revision.Aug 16 2022, 12:39 PM
thegameg added inline comments.
llvm/unittests/CodeGen/MFCommon.inc
120

I missed that this is included in other files. This is fine then.

This revision is now accepted and ready to land.Aug 16 2022, 12:39 PM
This revision was landed with ongoing or failed builds.Aug 16 2022, 3:09 PM
This revision was automatically updated to reflect the committed changes.