findDominatingStoreToReturn in CGCall.cpp didn't check if a candidate store instruction used the ReturnValue as pointer operand or value operand. This led to wrong code gen - in later stages (load-store elision code) the found store and its operand would be erased, causing ReturnValue to become a <badref>.
The patch adds a check that makes sure that ReturnValue is a pointer operand of store instruction. Regression test is also added.
This fixes PR24386.