Fix `for` to propagate source locations in more cases.

Thanks to Tobias Hammer for the patch.

Closes PR 14343.
Fix TR optimizer tests for new source locations.