[libcxx-commits] [clang] [libcxx] [llvm] [CLANG][LIBCXX][LLVM] Partial program correctness. P1494R5, P3641R0 (PR #237335)

via libcxx-commits libcxx-commits at lists.llvm.org
Sat Oct 31 03:01:38 PDT 2026


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


More information about the libcxx-commits mailing list