Skip to content

[Clang][analyzer][NFC] Const-correct CheckerContext API #154741

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -623,10 +623,12 @@ class BugReporter {
ASTContext &getContext() { return D.getASTContext(); }

const SourceManager &getSourceManager() { return D.getSourceManager(); }
const SourceManager &getSourceManager() const { return D.getSourceManager(); }

const AnalyzerOptions &getAnalyzerOptions() { return D.getAnalyzerOptions(); }

Preprocessor &getPreprocessor() { return D.getPreprocessor(); }
const Preprocessor &getPreprocessor() const { return D.getPreprocessor(); }

/// Get the top-level entry point for the issue to be reported.
const Decl *getAnalysisEntryPoint() const { return AnalysisEntryPoint; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,34 @@ class CheckerContext {
AnalysisManager &getAnalysisManager() {
return Eng.getAnalysisManager();
}
const AnalysisManager &getAnalysisManager() const {
return Eng.getAnalysisManager();
}

ConstraintManager &getConstraintManager() {
return Eng.getConstraintManager();
}
const ConstraintManager &getConstraintManager() const {
return Eng.getConstraintManager();
}

StoreManager &getStoreManager() {
return Eng.getStoreManager();
}
const StoreManager &getStoreManager() const { return Eng.getStoreManager(); }

/// Returns the previous node in the exploded graph, which includes
/// the state of the program before the checker ran. Note, checkers should
/// not retain the node in their state since the nodes might get invalidated.
ExplodedNode *getPredecessor() { return Pred; }
const ExplodedNode *getPredecessor() const { return Pred; }
const ProgramPoint getLocation() const { return Location; }
const ProgramStateRef &getState() const { return Pred->getState(); }

/// Check if the checker changed the state of the execution; ex: added
/// a new transition or a bug report.
bool isDifferent() { return Changed; }
bool isDifferent() const { return Changed; }

/// Returns the number of times the current block has been visited
/// along the analyzed path.
Expand Down Expand Up @@ -108,24 +117,38 @@ class CheckerContext {
BugReporter &getBugReporter() {
return Eng.getBugReporter();
}
const BugReporter &getBugReporter() const { return Eng.getBugReporter(); }

const SourceManager &getSourceManager() {
return getBugReporter().getSourceManager();
}
const SourceManager &getSourceManager() const {
return getBugReporter().getSourceManager();
}

Preprocessor &getPreprocessor() { return getBugReporter().getPreprocessor(); }
const Preprocessor &getPreprocessor() const {
return getBugReporter().getPreprocessor();
}

SValBuilder &getSValBuilder() {
return Eng.getSValBuilder();
}
const SValBuilder &getSValBuilder() const { return Eng.getSValBuilder(); }

SymbolManager &getSymbolManager() {
return getSValBuilder().getSymbolManager();
}
const SymbolManager &getSymbolManager() const {
return getSValBuilder().getSymbolManager();
}

ProgramStateManager &getStateManager() {
return Eng.getStateManager();
}
const ProgramStateManager &getStateManager() const {
return Eng.getStateManager();
}

AnalysisDeclContext *getCurrentAnalysisDeclContext() const {
return Pred->getLocationContext()->getAnalysisDeclContext();
Expand Down
11 changes: 11 additions & 0 deletions clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ class ExprEngine {
ASTContext &getContext() const { return AMgr.getASTContext(); }

AnalysisManager &getAnalysisManager() { return AMgr; }
const AnalysisManager &getAnalysisManager() const { return AMgr; }

AnalysisDeclContextManager &getAnalysisDeclContextManager() {
return AMgr.getAnalysisDeclContextManager();
Expand All @@ -206,8 +207,10 @@ class ExprEngine {
}

SValBuilder &getSValBuilder() { return svalBuilder; }
const SValBuilder &getSValBuilder() const { return svalBuilder; }

BugReporter &getBugReporter() { return BR; }
const BugReporter &getBugReporter() const { return BR; }

cross_tu::CrossTranslationUnitContext *
getCrossTranslationUnitContext() {
Expand Down Expand Up @@ -416,19 +419,27 @@ class ExprEngine {
unsigned int Space, bool IsDot) const;

ProgramStateManager &getStateManager() { return StateMgr; }
const ProgramStateManager &getStateManager() const { return StateMgr; }

StoreManager &getStoreManager() { return StateMgr.getStoreManager(); }
const StoreManager &getStoreManager() const {
return StateMgr.getStoreManager();
}

ConstraintManager &getConstraintManager() {
return StateMgr.getConstraintManager();
}
const ConstraintManager &getConstraintManager() const {
return StateMgr.getConstraintManager();
}

// FIXME: Remove when we migrate over to just using SValBuilder.
BasicValueFactory &getBasicVals() {
return StateMgr.getBasicVals();
}

SymbolManager &getSymbolManager() { return SymMgr; }
const SymbolManager &getSymbolManager() const { return SymMgr; }
MemRegionManager &getRegionManager() { return MRMgr; }

DataTag::Factory &getDataTags() { return Engine.getDataTags(); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,11 @@ class ProgramStateManager {
CallEventManager &getCallEventManager() { return *CallEventMgr; }

StoreManager &getStoreManager() { return *StoreMgr; }
const StoreManager &getStoreManager() const { return *StoreMgr; }
ConstraintManager &getConstraintManager() { return *ConstraintMgr; }
const ConstraintManager &getConstraintManager() const {
return *ConstraintMgr;
}
ExprEngine &getOwningEngine() { return *Eng; }

ProgramStateRef
Expand Down