I have read that Fortran can optimise numerical loops more aggressively than C because the compiler may assume that dummy arguments do not overlap. I have a routine subroutine add_twice(a, b) that executes a = a + b twice, and calling it as call add_twice(x, x) with x = 1.0 gives 4.0 in a debug build and 3.0 with optimisation.
Is that a compiler bug or my mistake? What exactly is the rule, and how do I legally call a routine when input and output really are the same variable?




