================
@@ -10069,6 +10069,17 @@ static std::optional<IntRange> 
TryGetExprRange(ASTContext &C, const Expr *E,
     case UO_AddrOf: // should be impossible
       return IntRange::forValueOfType(C, GetExprType(E));
 
+    case UO_Not: {
+      std::optional<IntRange> SubRange = TryGetExprRange(
+          C, UO->getSubExpr(), MaxWidth, InConstantContext, Approximate);
+      if (!SubRange)
+        return std::nullopt;
+
+      // The width increments by 1 if the sub-expression cannot be negative
+      // since it now can be.
+      return IntRange(SubRange->Width + (int)SubRange->NonNegative, false);
----------------
zygoloid wrote:

Does this do the right thing for `~` applied to an unsigned integer? In that 
case I think we know nothing useful about the range beyond the range of the 
type, because `IntRange` always treats 0 as being representable, which means 
that `UINTn_MAX` is always a possible value of the result.

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

Reply via email to