[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

Justin Stitt via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 14 14:10:35 PDT 2024


JustinStitt wrote:

A good example of a Linux kernel contributor running into an overflow that should really have its type marked as wrapping : https://lore.kernel.org/all/Zrzk8hilADAj+QTg@gmail.com/

They could use this feature to mark the suspected field `percpu_ref->percpu_ref_data->count` as wrapping:

```c
struct percpu_ref_data {
	atomic_long_t		count __attribute__((wraps));
        ...
};

// or mark the type `atomic_long_t` as wrapping
typedef atomic_t __attribute__((wraps)) atomic_long_t;
```

Reviewers, can I get a sense of where we are at with this feature? It lets developers better express the behavior of arithmetic in their code.

https://github.com/llvm/llvm-project/pull/86618


More information about the cfe-commits mailing list