-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[analyzer][NFC] Migrate nonloc::ConcreteInt to use APSIntPtr (2/4) #120436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h" | ||
#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicExtent.h" | ||
#include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h" | ||
#include "llvm/ADT/APSInt.h" | ||
#include "llvm/ADT/SmallString.h" | ||
#include "llvm/Support/FormatVariadic.h" | ||
#include "llvm/Support/raw_ostream.h" | ||
|
@@ -241,26 +242,25 @@ computeOffset(ProgramStateRef State, SValBuilder &SVB, SVal Location) { | |
static std::pair<NonLoc, nonloc::ConcreteInt> | ||
getSimplifiedOffsets(NonLoc offset, nonloc::ConcreteInt extent, | ||
SValBuilder &svalBuilder) { | ||
const llvm::APSInt &extentVal = extent.getValue(); | ||
std::optional<nonloc::SymbolVal> SymVal = offset.getAs<nonloc::SymbolVal>(); | ||
if (SymVal && SymVal->isExpression()) { | ||
if (const SymIntExpr *SIE = dyn_cast<SymIntExpr>(SymVal->getSymbol())) { | ||
llvm::APSInt constant = | ||
APSIntType(extent.getValue()).convert(SIE->getRHS()); | ||
llvm::APSInt constant = APSIntType(extentVal).convert(SIE->getRHS()); | ||
switch (SIE->getOpcode()) { | ||
case BO_Mul: | ||
// The constant should never be 0 here, becasue multiplication by zero | ||
// is simplified by the engine. | ||
if ((extent.getValue() % constant) != 0) | ||
if ((extentVal % constant) != 0) | ||
return std::pair<NonLoc, nonloc::ConcreteInt>(offset, extent); | ||
else | ||
return getSimplifiedOffsets( | ||
nonloc::SymbolVal(SIE->getLHS()), | ||
svalBuilder.makeIntVal(extent.getValue() / constant), | ||
svalBuilder); | ||
svalBuilder.makeIntVal(extentVal / constant), svalBuilder); | ||
case BO_Add: | ||
return getSimplifiedOffsets( | ||
nonloc::SymbolVal(SIE->getLHS()), | ||
svalBuilder.makeIntVal(extent.getValue() - constant), svalBuilder); | ||
svalBuilder.makeIntVal(extentVal - constant), svalBuilder); | ||
default: | ||
break; | ||
Comment on lines
243
to
265
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Slightly offtopic request: as you're already editing many lines of this function, please convert it to When I started to work on this checker in April 2023, it was an ugly mixture of |
||
} | ||
|
@@ -363,7 +363,7 @@ static std::string getRegionName(const SubRegion *Region) { | |
|
||
static std::optional<int64_t> getConcreteValue(NonLoc SV) { | ||
if (auto ConcreteVal = SV.getAs<nonloc::ConcreteInt>()) { | ||
return ConcreteVal->getValue().tryExtValue(); | ||
return ConcreteVal->getValue()->tryExtValue(); | ||
} | ||
return std::nullopt; | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.