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.
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?