JustinStitt wrote:

> Regarding there not being a `no-wraps` attribute. What happens with code like 
> this? Is the attribute lost / casted away during the addition?
> 
> ```
> wrapping_int a = INT_MAX;
> a = (int) a + 1;
> ```

Good question, the attribute is cast away (intentionally so). Additionally, 
sanitizers will warn of the overflow since the addition no longer contains a 
wraps-annotated type/variable. The result of the addition is the same 
regardless: `-2147483648`


> Does it affect converting a number too large to fit in the target type?
> 
> ```
> wrapping_int a = INT_MAX;
> wrapping_short b = a;
> short c = a;
> ```

No, this attribute really doesn't modify any arithmetic. It just tells the 
sanitizer not to instrument.

```c
  wrapping_int a = INT_MAX;
  wrapping_short b = a;
  short c = a;
  printf("%d\n%hd\n%hd\n", a, b, c);

/*
 * 2147483647
 * -1
 * -1
*/
```


https://github.com/llvm/llvm-project/pull/86618
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to