[clang] [analyzer][NFC] Mark leaf classes final and drop virtual from some methods (PR #245795)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 24 14:00:47 PST 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-analysis
Author: Gábor Horváth (Xazax-hun)
<details>
<summary>Changes</summary>
Two small cleanups to the analyzer's class hierarchies:
- Mark final the leaf classes of the MemRegion, SymExpr, ConstructionContext, PathDiagnosticPiece and BugReport hierarchies, plus RegionStoreManager, RangeConstraintManager and SimpleSValBuilder, which call their own virtual methods internally. Classes that have subclasses are left as they are.
- Drop virtual from methods that are never overridden: StoreManager::getLValue{Var,Ivar,Field,Element}, CallEvent::getArgSourceRange, RangedConstraintManager::assumeSymRel, SMTConstraintManager::addStateConstraints and CFGDominatorTreeImpl::releaseMemory.
This lets the compiler devirtualize more calls and slightly shrinks the analyzer libraries. There is no significant performance change on LLVM TUs.
---
Patch is 28.22 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/245795.diff
13 Files Affected:
- (modified) clang/include/clang/Analysis/Analyses/Dominators.h (+1-1)
- (modified) clang/include/clang/Analysis/ConstructionContext.h (+12-11)
- (modified) clang/include/clang/Analysis/PathDiagnostic.h (+6-6)
- (modified) clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h (+2-2)
- (modified) clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h (+1-1)
- (modified) clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h (+27-27)
- (modified) clang/include/clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h (+3-3)
- (modified) clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h (+1-1)
- (modified) clang/include/clang/StaticAnalyzer/Core/PathSensitive/Store.h (+4-4)
- (modified) clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h (+8-8)
- (modified) clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp (+1-1)
- (modified) clang/lib/StaticAnalyzer/Core/RegionStore.cpp (+1-1)
- (modified) clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp (+1-1)
``````````diff
diff --git a/clang/include/clang/Analysis/Analyses/Dominators.h b/clang/include/clang/Analysis/Analyses/Dominators.h
index 3dd5319e364684..bfefd798e44b77 100644
--- a/clang/include/clang/Analysis/Analyses/Dominators.h
+++ b/clang/include/clang/Analysis/Analyses/Dominators.h
@@ -167,7 +167,7 @@ class CFGDominatorTreeImpl : public ManagedAnalysis {
}
/// Releases the memory held by the dominator tree.
- virtual void releaseMemory() { DT.reset(); }
+ void releaseMemory() { DT.reset(); }
/// Converts the dominator tree to human readable form.
virtual void print(raw_ostream &OS, const llvm::Module* M= nullptr) const {
diff --git a/clang/include/clang/Analysis/ConstructionContext.h b/clang/include/clang/Analysis/ConstructionContext.h
index 70da9f996bdc2d..47d14f9339e41c 100644
--- a/clang/include/clang/Analysis/ConstructionContext.h
+++ b/clang/include/clang/Analysis/ConstructionContext.h
@@ -341,7 +341,8 @@ class VariableConstructionContext : public ConstructionContext {
/// If a variable has an initializer, eg. T var = makeT();, then the final
/// elidable copy-constructor from makeT() into var would also be a simple
/// variable constructor handled by this class.
-class SimpleVariableConstructionContext : public VariableConstructionContext {
+class SimpleVariableConstructionContext final
+ : public VariableConstructionContext {
friend class ConstructionContext; // Allows to create<>() itself.
explicit SimpleVariableConstructionContext(const DeclStmt *DS)
@@ -363,7 +364,7 @@ class SimpleVariableConstructionContext : public VariableConstructionContext {
/// Note that if the object has trivial destructor, then this code is
/// indistinguishable from a simple variable constructor on the AST level;
/// in this case we provide a simple variable construction context.
-class CXX17ElidedCopyVariableConstructionContext
+class CXX17ElidedCopyVariableConstructionContext final
: public VariableConstructionContext {
const CXXBindTemporaryExpr *BTE;
@@ -410,7 +411,7 @@ class ConstructorInitializerConstructionContext : public ConstructionContext {
/// Represents construction into a field or a base class within a bigger object
/// via a constructor initializer, eg. T(): field(123) { ... }.
-class SimpleConstructorInitializerConstructionContext
+class SimpleConstructorInitializerConstructionContext final
: public ConstructorInitializerConstructionContext {
friend class ConstructionContext; // Allows to create<>() itself.
@@ -435,7 +436,7 @@ class SimpleConstructorInitializerConstructionContext
/// object has trivial destructor, then this code is indistinguishable from
/// a simple constructor-initializer constructor on the AST level; in this case
/// we provide a simple constructor-initializer construction context.
-class CXX17ElidedCopyConstructorInitializerConstructionContext
+class CXX17ElidedCopyConstructorInitializerConstructionContext final
: public ConstructorInitializerConstructionContext {
const CXXBindTemporaryExpr *BTE;
@@ -459,7 +460,7 @@ class CXX17ElidedCopyConstructorInitializerConstructionContext
/// Represents immediate initialization of memory allocated by operator new,
/// eg. new T(123);.
-class NewAllocatedObjectConstructionContext : public ConstructionContext {
+class NewAllocatedObjectConstructionContext final : public ConstructionContext {
const CXXNewExpr *NE;
friend class ConstructionContext; // Allows to create<>() itself.
@@ -522,7 +523,7 @@ class TemporaryObjectConstructionContext : public ConstructionContext {
/// being immediately copied/moved by an elidable copy/move-constructor.
/// This includes temporary objects "in the middle of nowhere" like T(123) and
/// lifetime-extended temporaries.
-class SimpleTemporaryObjectConstructionContext
+class SimpleTemporaryObjectConstructionContext final
: public TemporaryObjectConstructionContext {
friend class ConstructionContext; // Allows to create<>() itself.
@@ -545,7 +546,7 @@ class SimpleTemporaryObjectConstructionContext
/// language; the constructor would then construct variable t directly.
/// This construction context contains information of the elidable constructor
/// and its respective construction context.
-class ElidedTemporaryObjectConstructionContext
+class ElidedTemporaryObjectConstructionContext final
: public TemporaryObjectConstructionContext {
const CXXConstructExpr *ElidedCE;
const ConstructionContext *ElidedCC;
@@ -603,7 +604,7 @@ class ReturnedValueConstructionContext : public ConstructionContext {
/// always going to be a constructor at the return site. However, the usual
/// temporary-related bureaucracy (CXXBindTemporaryExpr,
/// MaterializeTemporaryExpr) is normally located in the caller function's AST.
-class SimpleReturnedValueConstructionContext
+class SimpleReturnedValueConstructionContext final
: public ReturnedValueConstructionContext {
friend class ConstructionContext; // Allows to create<>() itself.
@@ -625,7 +626,7 @@ class SimpleReturnedValueConstructionContext
/// Note that if the object has trivial destructor, then this code is
/// indistinguishable from a simple returned value constructor on the AST level;
/// in this case we provide a simple returned value construction context.
-class CXX17ElidedCopyReturnedValueConstructionContext
+class CXX17ElidedCopyReturnedValueConstructionContext final
: public ReturnedValueConstructionContext {
const CXXBindTemporaryExpr *BTE;
@@ -647,7 +648,7 @@ class CXX17ElidedCopyReturnedValueConstructionContext
}
};
-class ArgumentConstructionContext : public ConstructionContext {
+class ArgumentConstructionContext final : public ConstructionContext {
// The call of which the context is an argument.
const Expr *CE;
@@ -680,7 +681,7 @@ class ArgumentConstructionContext : public ConstructionContext {
}
};
-class LambdaCaptureConstructionContext : public ConstructionContext {
+class LambdaCaptureConstructionContext final : public ConstructionContext {
// The lambda of which the initializer we capture.
const LambdaExpr *LE;
diff --git a/clang/include/clang/Analysis/PathDiagnostic.h b/clang/include/clang/Analysis/PathDiagnostic.h
index 272287b0bace78..fd795a561d3b4b 100644
--- a/clang/include/clang/Analysis/PathDiagnostic.h
+++ b/clang/include/clang/Analysis/PathDiagnostic.h
@@ -530,7 +530,7 @@ class PathDiagnosticSpotPiece : public PathDiagnosticPiece {
}
};
-class PathDiagnosticEventPiece : public PathDiagnosticSpotPiece {
+class PathDiagnosticEventPiece final : public PathDiagnosticSpotPiece {
std::optional<bool> IsPrunable;
public:
@@ -558,7 +558,7 @@ class PathDiagnosticEventPiece : public PathDiagnosticSpotPiece {
}
};
-class PathDiagnosticCallPiece : public PathDiagnosticPiece {
+class PathDiagnosticCallPiece final : public PathDiagnosticPiece {
const Decl *Caller;
const Decl *Callee = nullptr;
@@ -628,7 +628,7 @@ class PathDiagnosticCallPiece : public PathDiagnosticPiece {
}
};
-class PathDiagnosticControlFlowPiece : public PathDiagnosticPiece {
+class PathDiagnosticControlFlowPiece final : public PathDiagnosticPiece {
std::vector<PathDiagnosticLocationPair> LPairs;
public:
@@ -698,7 +698,7 @@ class PathDiagnosticControlFlowPiece : public PathDiagnosticPiece {
void Profile(llvm::FoldingSetNodeID &ID) const override;
};
-class PathDiagnosticMacroPiece : public PathDiagnosticSpotPiece {
+class PathDiagnosticMacroPiece final : public PathDiagnosticSpotPiece {
public:
PathDiagnosticMacroPiece(const PathDiagnosticLocation &pos)
: PathDiagnosticSpotPiece(pos, "", Macro) {}
@@ -721,7 +721,7 @@ class PathDiagnosticMacroPiece : public PathDiagnosticSpotPiece {
void Profile(llvm::FoldingSetNodeID &ID) const override;
};
-class PathDiagnosticNotePiece: public PathDiagnosticSpotPiece {
+class PathDiagnosticNotePiece final : public PathDiagnosticSpotPiece {
public:
PathDiagnosticNotePiece(const PathDiagnosticLocation &Pos, StringRef S,
bool AddPosRange = true)
@@ -737,7 +737,7 @@ class PathDiagnosticNotePiece: public PathDiagnosticSpotPiece {
void Profile(llvm::FoldingSetNodeID &ID) const override;
};
-class PathDiagnosticPopUpPiece: public PathDiagnosticSpotPiece {
+class PathDiagnosticPopUpPiece final : public PathDiagnosticSpotPiece {
public:
PathDiagnosticPopUpPiece(const PathDiagnosticLocation &Pos, StringRef S,
bool AddPosRange = true)
diff --git a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
index 7a617c5c388263..528e57163b76a7 100644
--- a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
+++ b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
@@ -248,7 +248,7 @@ class BugReport {
virtual void Profile(llvm::FoldingSetNodeID& hash) const = 0;
};
-class BasicBugReport : public BugReport {
+class BasicBugReport final : public BugReport {
PathDiagnosticLocation Location;
const Decl *DeclWithIssue = nullptr;
@@ -788,7 +788,7 @@ class DataTag : public ProgramPointTag {
/// The tag upon which the TagVisitor reacts. Add these in order to display
/// additional PathDiagnosticEventPieces along the path.
-class NoteTag : public DataTag {
+class NoteTag final : public DataTag {
public:
using Callback = std::function<std::string(BugReporterContext &,
PathSensitiveBugReport &)>;
diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
index f854c25ede8521..b38bb427500e6a 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
@@ -305,7 +305,7 @@ class CallEvent {
/// Returns the source range for errors associated with this argument.
///
/// May be invalid if the argument is not written in the source.
- virtual SourceRange getArgSourceRange(unsigned Index) const;
+ SourceRange getArgSourceRange(unsigned Index) const;
/// Returns the result type, adjusted for references.
QualType getResultType() const;
diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
index c3d6d552d5e562..15f0afc94579ac 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
@@ -262,7 +262,7 @@ class MemSpaceRegion : public MemRegion {
/// CodeSpaceRegion - The memory space that holds the executable code of
/// functions and blocks.
-class CodeSpaceRegion : public MemSpaceRegion {
+class CodeSpaceRegion final : public MemSpaceRegion {
friend class MemRegionManager;
CodeSpaceRegion(MemRegionManager &mgr)
@@ -296,7 +296,7 @@ class GlobalsSpaceRegion : public MemSpaceRegion {
///
/// Currently, only the static locals are placed there, so we know that these
/// variables do not get invalidated by calls to other functions.
-class StaticGlobalSpaceRegion : public GlobalsSpaceRegion {
+class StaticGlobalSpaceRegion final : public GlobalsSpaceRegion {
friend class MemRegionManager;
const CodeTextRegion *CR;
@@ -344,7 +344,7 @@ class NonStaticGlobalSpaceRegion : public GlobalsSpaceRegion {
/// The region containing globals which are defined in system/external
/// headers and are considered modifiable by system calls (ex: errno).
-class GlobalSystemSpaceRegion : public NonStaticGlobalSpaceRegion {
+class GlobalSystemSpaceRegion final : public NonStaticGlobalSpaceRegion {
friend class MemRegionManager;
GlobalSystemSpaceRegion(MemRegionManager &mgr)
@@ -363,7 +363,7 @@ class GlobalSystemSpaceRegion : public NonStaticGlobalSpaceRegion {
/// (system or internal). Ex: Const global scalars would be modeled as part of
/// this region. This region also includes most system globals since they have
/// low chance of being modified.
-class GlobalImmutableSpaceRegion : public NonStaticGlobalSpaceRegion {
+class GlobalImmutableSpaceRegion final : public NonStaticGlobalSpaceRegion {
friend class MemRegionManager;
GlobalImmutableSpaceRegion(MemRegionManager &mgr)
@@ -380,7 +380,7 @@ class GlobalImmutableSpaceRegion : public NonStaticGlobalSpaceRegion {
/// The region containing globals which can be modified by calls to
/// "internally" defined functions - (for now just) functions other than system
/// calls.
-class GlobalInternalSpaceRegion : public NonStaticGlobalSpaceRegion {
+class GlobalInternalSpaceRegion final : public NonStaticGlobalSpaceRegion {
friend class MemRegionManager;
GlobalInternalSpaceRegion(MemRegionManager &mgr)
@@ -394,7 +394,7 @@ class GlobalInternalSpaceRegion : public NonStaticGlobalSpaceRegion {
}
};
-class HeapSpaceRegion : public MemSpaceRegion {
+class HeapSpaceRegion final : public MemSpaceRegion {
friend class MemRegionManager;
HeapSpaceRegion(MemRegionManager &mgr)
@@ -408,7 +408,7 @@ class HeapSpaceRegion : public MemSpaceRegion {
}
};
-class UnknownSpaceRegion : public MemSpaceRegion {
+class UnknownSpaceRegion final : public MemSpaceRegion {
friend class MemRegionManager;
UnknownSpaceRegion(MemRegionManager &mgr)
@@ -446,7 +446,7 @@ class StackSpaceRegion : public MemSpaceRegion {
}
};
-class StackLocalsSpaceRegion : public StackSpaceRegion {
+class StackLocalsSpaceRegion final : public StackSpaceRegion {
friend class MemRegionManager;
StackLocalsSpaceRegion(MemRegionManager &mgr, const StackFrame *SF)
@@ -460,7 +460,7 @@ class StackLocalsSpaceRegion : public StackSpaceRegion {
}
};
-class StackArgumentsSpaceRegion : public StackSpaceRegion {
+class StackArgumentsSpaceRegion final : public StackSpaceRegion {
private:
friend class MemRegionManager;
@@ -509,7 +509,7 @@ class SubRegion : public MemRegion {
/// AllocaRegion - A region that represents an untyped blob of bytes created
/// by a call to 'alloca'.
-class AllocaRegion : public SubRegion {
+class AllocaRegion final : public SubRegion {
friend class MemRegionManager;
// Block counter. Used to distinguish different pieces of memory allocated by
@@ -615,7 +615,7 @@ class CodeTextRegion : public TypedRegion {
};
/// FunctionCodeRegion - A region that represents code texts of function.
-class FunctionCodeRegion : public CodeTextRegion {
+class FunctionCodeRegion final : public CodeTextRegion {
friend class MemRegionManager;
const NamedDecl *FD;
@@ -662,7 +662,7 @@ class FunctionCodeRegion : public CodeTextRegion {
/// which correspond to "code+data". The distinction is important, because
/// like a closure a block captures the values of externally referenced
/// variables.
-class BlockCodeRegion : public CodeTextRegion {
+class BlockCodeRegion final : public CodeTextRegion {
friend class MemRegionManager;
const BlockDecl *BD;
@@ -709,7 +709,7 @@ class BlockCodeRegion : public CodeTextRegion {
/// which correspond to "code+data". The distinction is important, because
/// like a closure a block captures the values of externally referenced
/// variables.
-class BlockDataRegion : public TypedRegion {
+class BlockDataRegion final : public TypedRegion {
friend class MemRegionManager;
const BlockCodeRegion *BC;
@@ -810,7 +810,7 @@ class BlockDataRegion : public TypedRegion {
/// either a real region, a NULL pointer, etc. It essentially is used to
/// map the concept of symbolic values into the domain of regions. Symbolic
/// regions do not need to be typed.
-class SymbolicRegion : public SubRegion {
+class SymbolicRegion final : public SubRegion {
friend class MemRegionManager;
const SymbolRef sym;
@@ -859,7 +859,7 @@ class SymbolicRegion : public SubRegion {
};
/// StringRegion - Region associated with a StringLiteral.
-class StringRegion : public TypedValueRegion {
+class StringRegion final : public TypedValueRegion {
friend class MemRegionManager;
const StringLiteral *Str;
@@ -893,7 +893,7 @@ class StringRegion : public TypedValueRegion {
};
/// The region associated with an ObjCStringLiteral.
-class ObjCStringRegion : public TypedValueRegion {
+class ObjCStringRegion final : public TypedValueRegion {
friend class MemRegionManager;
const ObjCStringLiteral *Str;
@@ -930,7 +930,7 @@ class ObjCStringRegion : public TypedValueRegion {
/// CompoundLiteralRegion - A memory region representing a compound literal.
/// Compound literals are essentially temporaries that are stack allocated
/// or in the global constant pool.
-class CompoundLiteralRegion : public TypedValueRegion {
+class CompoundLiteralRegion final : public TypedValueRegion {
friend class MemRegionManager;
const CompoundLiteralExpr *CL;
@@ -1016,7 +1016,7 @@ class VarRegion : public DeclRegion {
// instances to represent the parameters of the entrypoint stack frame and
// parameters of outer stack frames that appear as captured within a lambda or
// a block. This should be overhauled.
-class NonParamVarRegion : public VarRegion {
+class NonParamVarRegion final : public VarRegion {
friend class MemRegionManager;
const VarDecl *VD;
@@ -1069,7 +1069,7 @@ class NonParamVarRegion : public VarRegion {
// implementing stack frame creations for functions without decl (functions
// passed by unknown function pointer) methods of `ParamVarRegion` must be
// updated.
-class ParamVarRegion : public VarRegion {
+class ParamVarRegion final : public VarRegion {
friend class MemRegionManager;
const Expr *OriginExpr;
@@ -1109,7 +1109,7 @@ class ParamVarRegion : public VarRegion {
/// CXXThisRegion - Represents the region for the implicit 'this' parameter
/// in a call to a C++ method. This region doesn't represent the object
/// referred to by 'this', but rather 'this' itself.
-class CXXThisRegion : public TypedValueRegion {
+class CXXThisRegion final : public TypedValueRegion {
friend class MemRegionManager;
CXXThisRegion(const PointerType *thisPointerTy,
@@ -1141,7 +1141,7 @@ class CXXThisRegion : public TypedValueRegion {
const PointerType *ThisPointerTy;
};
-class FieldRegion : public DeclRegion {
+class FieldRegion final : public DeclRegion {
friend class MemRegionManager;
const FieldDecl *FD;
@@ -1181,7 +1181,7 @@ class FieldRegion : public DeclRegion {
}
};
-class ObjCIvarRegion : public DeclRegion {
+class ObjCIvarRegion final : public DeclRegion {
friend class MemRegionManager;
const ObjCIvarDecl *IVD;
@@ -1234,7 +1234,7 @@ class RegionRawOffset {
};
/// ElementRegion is used to represent both array elements and casts.
-class ElementRegion : public TypedValueRegion {
+class ElementRegion final : public TypedValueRegion {
friend class MemRegionManager;
QualType ElementType;
@@ -1273,7 +1273,7 @@ class ElementRegion : public TypedValueRegion {
};
// C++ temporary object associated with an expression.
-class CXXTempObjectRegion : public TypedValueRegion {
+class CXXTempObjectRegion final : public TypedValueRegion {
friend class MemRegionManager;
Expr const *Ex;
@@ -1307,7 +1307,7 @@ class CXXTempObjectRegion : public TypedValueRegion {
// C++ temporary object that have lifetime extended to lifetime of the
// variable. Usually they represent temporary bounds to reference variables.
-class CXXLifetimeExtendedObjectRegion : public TypedValueRegion {
+class CXXLifetimeExtendedObjectRegion final : public TypedValueRegion {
friend class MemRegionManager;
Expr const *Ex;
@@ -1346,7 +1346,7 @@ class CXXLifetimeExtendedObjectRegion : public TypedValueRegion {
// CXXBaseObjectRegion represents a base object within a C++ object. It is
// identified by the base class declaration and the region of its parent object.
-class CXXBaseObjectRegion : public TypedValueRegion {
+class CXXBaseObjectRegion final : public TypedValueRegion {
friend class MemRegionManager;
llvm::PointerIntPair<const CXXRecordDecl *, 1, bool> Data;
@@ -1385,7 +1385,7 @@ class CXXBaseObjectRegion : public TypedValueRegion {
// region of its parent object. It is a bit counter-intuitive (but not otherwise
// unseen) that this region represents a larger segment of memory that its
// super-region.
-class CXXDerivedObjectRegion : public TypedValueRegion {
+class CXXDer...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/245795
More information about the cfe-commits
mailing list