Re:Security flaws caused by compiler optimizations
by slaymaker1907 on Wednesday August 21, 2019 @08:23PM
(#20763425)
An infinite loop with no side effects is undefined behavior.
Re:Security flaws caused by compiler optimizations
by comex on Wednesday August 21, 2019 @09:21PM
(#20763764)
I didn't say no side effects. But even an infinite loop with no side effects is well-defined if the controlling expression is a constant expression; see the link in my previous post.
Re:Security flaws caused by compiler optimizations
by dooglius on Wednesday August 21, 2019 @04:27PM
(#20761358)
That seems to be the conclusion of the mailing list thread as well, there was an initial bad gcc bug report that didn't understand the problem, seemingly no follow-up with a proper bug report.
I don’t think that’s correct. The compiler is allowed to assume that functions marked noreturn do not return, but it’s not allowed to assume that functions not marked noreturn do return. In other words, it’s not undefined behavior for a function to call abort(), enter an infinite loop, etc. instead of returning. It would be very strange if it were!
There’s a somewhat related spec clause that lets the compiler assume that certain types of loops will eventually terminate [1], but that doesn’t apply here. Therefore I think the mentioned compiler optimization is illegal. The issue was reported back in 2011; it would be interesting to see whether newer versions of GCC, or Clang, behave the same way.
[1] https://stackoverflow.com/questions/16436237/is-while1-undef...