[all-commits] [llvm/llvm-project] 247db2: [Clang] Reject overflow behavior types on _Atomic ...

Justin Stitt via All-commits all-commits at lists.llvm.org
Tue Sep 15 12:25:11 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 247db2420326c288690592088596db9435098261
      https://github.com/llvm/llvm-project/commit/247db2420326c288690592088596db9435098261
  Author: Justin Stitt <justinstitt at google.com>
  Date:   2026-09-15 (Tue, 15 Sep 2026)

  Changed paths:
    M clang/docs/OverflowBehaviorTypes.md
    M clang/include/clang/Basic/DiagnosticSemaKinds.td
    M clang/lib/Sema/SemaType.cpp
    A clang/test/Sema/overflow-behavior-atomic.c

  Log Message:
  -----------
  [Clang] Reject overflow behavior types on _Atomic (#222179)

atomic read-modify-write operations aren't instrumented for overflow. `counter++` on an `_Atomic` object lowers to a single `atomicrmw`, and this is true for plain atomic types under `-fsanitize=signed-integer-overflow` too.

That's a problem for `__ob_trap`, which is supposed to be checked no matter what the global flags say:

```c
  typedef int __ob_trap trapping_int;
  _Atomic trapping_int counter;
  int x = counter + 1; // checked
  counter++;           // not checked
```

A guarantee that only holds for some expressions is worse than none, so reject the combination outriht. Let's also reject `__ob_wrap` too so the rule doesn't depend on the behavior kind... wrap has minimal use here anyways.

Applying an OBT specifier over an atomic type was already an error, though it unhelpfully reported `_Atomic(int)` as a non-integer type even though it is. Applying `_Atomic` over an existing OBT was accepted, which is where the unchecked read-modify-write came from... this was a bug that is now fixed because we are no longer trying to apply OBT on top of `_Atomic`. This is all made more clear by better diagnostics too :)

We can relax this later if someone needs it. I think instrumenting checked atomic rmws would mean lowering to a cmpxchg/CAS loop.

Assisted-by: claude
Signed-off-by: Justin Stitt <justinstitt at google.com>



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list