|
|
|
|
|
by comex
2497 days ago
|
|
> However, the programmer failed to inform the compiler that the call to ereport(ERROR,...) does not return. This implies that the division will always execute. 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... |
|