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

Eli Friedman via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 24 11:54:32 PDT 2024


efriedma-quic wrote:

> > If you declare a variable as both wrapping and non-wrapping, is it wrapping?
> 
> I am not sure how to do this. I am sure that with the magic of C anything is possible but I can't conceive a way to have a variable both have the attribute and not have the attribute (to be clear, there doesn't exist a `__attribute__((no-wraps))` currently)

Say you declare a global variable like the following:

```
typedef int wrapint __attribute((wraps));
extern wrapint x;
int x = 0;
```

Is "x" wrapping?

> > If you mark a `short` wrapping, is the type after promotion wrapping?
> 
> This concerns the `-fsanitize=implicit-signed-integer-truncation` sanitizer which the wraps attribute disables. So the type boundaries pre- and post-promotion are not enforced by this sanitizer for wrapping types.

There are cases that don't involve truncation:

```
typedef short wrapshort __attribute((wraps));
short x = 0x7FFF;
int y = x*x*x*x;
```

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


More information about the cfe-commits mailing list