DenisGZM wrote:
> ~printf is a checkpoint; LLVM won't erase it or anything before it.~ Edit to
> clarify: LLVM treats calls to IO functions like printf as if they were
> observable checkpoints.
>
> Nothing in the spec requires preserving the `x += 42`.
Well, as I read the proposal, it may seem that such behavior is expected not
only for IO functions:
> The capability of establishing such a “checkpoint”, where subsequent program
> behavior, even if undefined, does not affect the preceding behavior, would be
> useful in general for purposes of stability and debugging.
Here is another example, please have a look:
```c
// Partial program correctness.
extern int x;
int here_b_ub() {
// missing return triggers UB.
}
__attribute__((noinline)) void goto_error() {
__builtin_printf(" error \n");
return;
}
int main() {
x = 0;
__builtin_printf(" start \n");
x += 42;
// Without this checkpoint the cmp below is elided
// and call became unconditional.
if ( x > 100 ) {
goto_error();
}
// __builtin_observable_checkpoint ();
here_b_ub ();
}
```
UB removes check and forces to call `goto_error`, and so print "error"
unconditionally. I don’t think this fits the proposal, but maybe I’m missing
something. I'd like to discuss
https://github.com/llvm/llvm-project/pull/237335
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits