[clang] [analyzer] Improve solver (PR #112583)

DonĂ¡t Nagy via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 17 04:55:43 PDT 2024


================
@@ -2883,22 +2883,16 @@ const llvm::APSInt *RangeConstraintManager::getSymVal(ProgramStateRef St,
 
 const llvm::APSInt *RangeConstraintManager::getSymMinVal(ProgramStateRef St,
                                                          SymbolRef Sym) const {
-  // TODO: Use `getRange()` like in `getSymVal()`, but that would make some
-  // of the reports of `BitwiseShiftChecker` look awkward.
-  const RangeSet *T = getConstraint(St, Sym);
-  if (!T || T->isEmpty())
-    return nullptr;
-  return &T->getMinValue();
+  auto &MutableSelf = const_cast<RangeConstraintManager &>(*this);
+  RangeSet Range = MutableSelf.getRange(St, Sym);
+  return Range.isEmpty() ? nullptr : &Range.getMinValue();
 }
 
 const llvm::APSInt *RangeConstraintManager::getSymMaxVal(ProgramStateRef St,
                                                          SymbolRef Sym) const {
-  // TODO: Use `getRange()` like in `getSymVal()`, but that would make some
-  // of the reports of `BitwiseShiftChecker` look awkward.
-  const RangeSet *T = getConstraint(St, Sym);
-  if (!T || T->isEmpty())
-    return nullptr;
-  return &T->getMaxValue();
+  auto &MutableSelf = const_cast<RangeConstraintManager &>(*this);
+  RangeSet Range = MutableSelf.getRange(St, Sym);
----------------
NagyDonat wrote:

Now that I think about it, why is `getRange` not a `const` method?

As far as I see, it returns a `RangeSet` by value and its typical usage looks like
```cpp
RangeSet New = getRange(St, Sym);
New = F.deletePoint(New, Point);
                                 
return setRange(St, Sym, New);
```
and while I didn't review its (complex, visitor-based) definition, semantically I don't think that it should modify anything.


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


More information about the cfe-commits mailing list