But if it wasn't, I'd be too ashamed to go forth and complain to the
compiler vendor :-)

> Not surprisingly, ANSI C says the behaviour is undefined when you do> this. (6.2.4(2,5))

And my question was specifically about ANSI C, i.e. where the compiler
can assume that conforming code is being provided.

> IMHO, a reasonable criterion for optimizations is that they should> not change the behavior of any program that compiles without error,> but I believe all the standard requires is that it not change any> behavior that is defined by the language.

And I'm quite happy with the standard and put my question in its
context.

> > and since t is initially assigned to tmp, and it isn't legal for t> > to proceed past tmp + 10, assigning to *t can't be changing s.>> There is no way the rules of the language could prevent t from> proceeding past tmp + 10, because the type system has already> forgotten, by the time t = tmp; has been executed, that t points into> array tmp.

You're mixing compile-time and run-time. I'm only interested in
compile-time. At that point, the compiler can tell that assigning to
*t won't modify s.

> Just call the original foo with a string longer than 10. Something> will get stepped on

I have no interest in what may happen if the programmer breaks his
contract with the compiler expressed through the standard and his code.

Getting back on track, would static single assignment, SSA, be a method
that the compiler may use to track and determine that an assignment to
*t won't modify s? I've only come across the term from lurking on
comp.compilers.

And the other outstanding question: Is there a compiler in existence
that would recognise strlen(s) is invariant to the loop.