News for hackers. Stuff that matters.
Re:Tell HN: C Experts Panel – Ask us anything about C by cwzwarich on Tuesday April 14, 2020 @02:00PM (#22869234)
> This is a common misconception (or poor way of phrasing it, sorry). Compiler implementers don't go looking for instances of undefined behavior in a program with the goal of optimizing it in some way. There is little value in optimizing invalid code. The opposite is the case.

Compilers do deliberately look to optimize loops with signed counters by exploiting UB to assume that they will never wrap.

Re:Tell HN: C Experts Panel – Ask us anything about C by qznc on Tuesday April 14, 2020 @02:29PM (#22869636)
I'd say both statements are correct.

Compiler implementers are happy when they don't have to care about some edge case because then the code is simpler. Thus, only for unsigned counters there is the extra logic to compile them correctly.

That is my interpretation of "The opposite is the case". Writing a compiler is easier with lots of undefined behavior.

Re:Tell HN: C Experts Panel – Ask us anything about C by ender341341 on Tuesday April 14, 2020 @09:35PM (#22873561)
But that's backwards, the compiler writers are writing special cases to erase checks in the signed case. Doing the 'dumb' thing and mindlessly going through the written check is simpler which is why that's what compilers did for decades as de facto standard on x86.
Re:Tell HN: C Experts Panel – Ask us anything about C by qznc on Wednesday April 15, 2020 @08:39AM (#22877000)
The dump thing is a non optimizing compiler. GCC and LLVM contain many optimization phases. It is probably some normal optimization which is only "wrong" in the context of loop conditions.
Re:Tell HN: C Experts Panel – Ask us anything about C by Leherenn on Tuesday April 14, 2020 @04:31PM (#22871085)
Well yes, they assume they never wrap because that is not allowed by the language, by definition. UB are the results of broken preconditions at the language level.