[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 23:54:14 PDT 2024


efriedma-quic wrote:

> No. But I am confused, isn't this just shadowing a global variable with a lesser-scoped one. Are they the same? What behavior do we want here?

This is declaring, then defining, a global variable; sorry if that wasn't clear.

Probably should be an error?  It'll be confusing no matter what we do.

> However, after making the patch and testing it I am not sure what we want. Do we want to cancel implicit promotions for less-than-ints that possess the wraps attribute (doesn't sound spec compliant)? Or, should wrapping things still undergo promotion but now wrap at different bounds than what their original type specified?

I assume for your usage, you want the result of the arithmetic to be the same whether or not the compiler supports the "wraps" attribute, which constrains your choices.

> More on this, I don't see how changing implementation from attribute-based to type-based resolves any of these design decisions. Neither approach is necessarily easier to implement or to understand for developers, if the right decisions are made in terms of behavior then the attribute approach can be just as useful and predictable.

If you had a distinct canonical type, you would have had to make explicit decisions about a bunch of these things... and the rest would be stable independent of details of non-canonical type propagation.

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


More information about the cfe-commits mailing list