4 ms·
> Main directly calls this_is_not_directly_called_by_main in this implementation. This happens because: [...] LLVM assumes that bar() will have executed by the
by dataflow 4y ago
> Main directly calls this_is_not_directly_called_by_main in this implementation. This happens because: [...] LLVM assumes that bar() will have executed by the time main() runs.
I think this reasoning is slightly incorrect, although I don't blame the author as this is a very common misconception. I believe the correct reasoning might be as follows:
1. The compiler sees the pointer is dereferenced.
2. The compiler infers the pointer was not NULL.
3. The compiler determines a set of candidates for its target (which may be the universal set).
4. If it finds only one candidate, it just substitutes the target.
The critical thing to notice here is that the compiler doesn't need to care about the reachability of that candidate. It's making a conservative over-approximation, after all. You can witness the effect of this by formulating an impossible condition inside bar() that the compiler completely ignores: see [1]. Note the pointer assignment cannot have been implied by "bar() will have executed", as the execution of bar() could never lead to that assignment anyway!
[1] https://godbolt.org/z/W19javzqW https://godbolt.org/z/W19javzqW