News for hackers. Stuff that matters.
Re:New things in clang land (5.0.0) by oconnor663 on Thursday December 07, 2017 @11:21AM (#15871365)
> If it can be proven that it will always be called, the compiler is free to assume that the program will never be run, and optimize the whole program down to nothing.

Does that happen when the compiler assumes you'll never take branches that lead to UB, and then finds a path through your branches that more or less does nothing? Or can it happen even if you're not branching at all?

Also, say my program is

    int main() {
        printf("hello world\n");
        do_some_UB();
    }
Is the compiler really allowed to produce a program that doesn't print?
Re:New things in clang land (5.0.0) by masklinn on Thursday December 07, 2017 @05:57PM (#15875181)
> Does that happen when the compiler assumes you'll never take branches that lead to UB, and then finds a path through your branches that more or less does nothing? Or can it happen even if you're not branching at all?

Yes and yes. How far it will propagate these backwards depends on the compiler.

> Is the compiler really allowed to produce a program that doesn't print?

Yes. A program which contains UB is illegal, there are no guarantees about any of its behaviour, including behaviour which precedes any possible actual invocation of UB, this is pointed rather clearly by the standard:

> However, if any such execution contains an undefined operation, this International Standard places no requirement on the implementation executing that program with that input (not even with regard to operations preceding the first undefined operation).

Re:New things in clang land (5.0.0) by oconnor663 on Thursday December 07, 2017 @06:11PM (#15875251)
Good heavens! :)
Re:New things in clang land (5.0.0) by Joky on Thursday December 07, 2017 @12:21PM (#15871862)
Yes the compiler can remove the printf.