================
@@ -402,108 +487,93 @@ static std::optional<int64_t> 
getConcreteValue(std::optional<NonLoc> SV) {
   return SV ? getConcreteValue(*SV) : std::nullopt;
 }
 
-/// Try to divide `Val1` and `Val2` (in place) by `Divisor` and return true if
-/// it can be performed (`Divisor` is nonzero and there is no remainder). The
-/// values `Val1` and `Val2` may be nullopt and in that case the corresponding
-/// division is considered to be successful.
-static bool tryDividePair(std::optional<int64_t> &Val1,
-                          std::optional<int64_t> &Val2, int64_t Divisor) {
-  if (!Divisor)
-    return false;
-  const bool Val1HasRemainder = Val1 && *Val1 % Divisor;
-  const bool Val2HasRemainder = Val2 && *Val2 % Divisor;
-  if (Val1HasRemainder || Val2HasRemainder)
-    return false;
-  if (Val1)
-    *Val1 /= Divisor;
-  if (Val2)
-    *Val2 /= Divisor;
-  return true;
+static const char *getAdjective(const bounds::CheckResult &R) {
+  return (R.mayUnderflow()
+              ? (R.mayOverflow() ? "a negative or overflowing" : "a negative")
+              : (R.mayOverflow() ? "an overflowing" : "a valid"));
 }
 
-static Messages getNonTaintMsgs(const ASTContext &ACtx,
-                                const MemSpaceRegion *Space,
-                                const SubRegion *Region, NonLoc Offset,
-                                std::optional<NonLoc> Extent, SVal Location,
-                                BadOffsetKind Problem) {
-  std::string RegName = getRegionName(Space, Region);
-  const auto *EReg = Location.getAsRegion()->getAs<ElementRegion>();
-  assert(EReg && "this checker only handles element access");
-  QualType ElemType = EReg->getElementType();
+static const char *getPreposition(const bounds::CheckResult &R) {
+  return (R.mayUnderflow() ? (R.mayOverflow() ? "around" : "preceding")
+                           : (R.mayOverflow() ? "after the end of" : 
"within"));
+}
 
-  std::optional<int64_t> OffsetN = getConcreteValue(Offset);
-  std::optional<int64_t> ExtentN = getConcreteValue(Extent);
+static BugDescription describeInvalidAccess(bounds::CheckResult Res,
+                                            StringRef RegName, SizeUnit SU) {
+  std::optional<int64_t> OffsetN = getConcreteValue(Res.getOffset());
+  std::optional<int64_t> ExtentN = getConcreteValue(Res.getExtentIfRelevant());
 
-  int64_t ElemSize = ACtx.getTypeSizeInChars(ElemType).getQuantity();
+  if (SU.canExpress(OffsetN) && SU.canExpress(ExtentN)) {
+    if (OffsetN)
+      *OffsetN /= SU.asCharUnits();
+    if (ExtentN)
+      *ExtentN /= SU.asCharUnits();
+  } else {
+    // Fall back to reporting the offsets in bytes.
+    SU = SizeUnit::bytes();
+  }
 
-  bool UseByteOffsets = !tryDividePair(OffsetN, ExtentN, ElemSize);
-  const char *OffsetOrIndex = UseByteOffsets ? "byte offset" : "index";
+  const char *OffsetOrIndex = SU.isBytes() ? "byte offset" : "index";
----------------
NagyDonat wrote:

Done in 
https://github.com/llvm/llvm-project/pull/210774/commits/e0cc1186cce93b7254028c7c6fefcc2a58a716d6

https://github.com/llvm/llvm-project/pull/210774
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to