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

Justin Stitt via cfe-commits cfe-commits at lists.llvm.org
Wed May 29 11:56:12 PDT 2024


JustinStitt wrote:

Hi, gentle ping. 

@efriedma-quic, do you still have concerns with the current implementation (as an attribute attached to typedefs)? After limiting `wraps` to C and adding warnings to let users know when the attribute may be stripped, I think it's in a good spot.

```c
typedef int __attribute__((wraps)) wrap_int;

extern void foo(int b);

int main(void) {
  wrap_int a;
  foo(a); // wraps.c:12:7: warning: 'wraps' attribute may be implicitly discarded \
          // when converted to 'int' [-Wimplicitly-discarded-wraps-attribute]

}
```

This feature is obviously niche and requires opting in with actual source modifications, this is not something people will use accidentally. However, Eli, I hear your concerns about some of the non-obvious ways attributes can get lost. I've tried to remedy this with some warnings (as seen above) but, of course, the semantics of attribute persistence are what they are. Eli, if you think this is not good enough then I will try and redesign the feature as an extended type. Although, I reckon the C type system has just as many quirks and foot-guns as the Clang attribute system.

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


More information about the cfe-commits mailing list