[clang] [Clang] add wraps and no_wraps attributes (PR #115094)

Justin Stitt via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 8 15:32:17 PST 2024


================
@@ -4852,6 +4862,10 @@ BinaryOperator::BinaryOperator(const ASTContext &Ctx, Expr *lhs, Expr *rhs,
   if (hasStoredFPFeatures())
     setStoredFPFeatures(FPFeatures);
   setDependence(computeDependence(this));
+  if (hasWrappingOperand(Ctx))
----------------
JustinStitt wrote:

Implementation-wise, it is OK for both attributes to exist on the same type.

`hasWrapsAttr()` cautiously checks for `no_wraps` before claiming we have `wraps`.
```c
bool QualType::hasWrapsAttr() const {
  return !isNull() && getTypePtr()->hasAttr(attr::Wraps) &&
         !getTypePtr()->hasAttr(attr::NoWraps);
}

```

But yeah you're right, this is confusing because if you look at an ast dump you'll see both attributes applied to the type and it may not be obvious which has precedence. I'll add a diagnostic and a sane default of keeping the `no_wraps` and dropping `wraps` for cases like this.

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


More information about the cfe-commits mailing list