[clang] [analyzer][NFC] Mark leaf classes final and drop virtual from some methods (PR #245795)
Gábor Horváth via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 24 14:00:02 PST 2026
https://github.com/Xazax-hun created https://github.com/llvm/llvm-project/pull/245795
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.
>From 8501ba3ca0ea418d4d48d1dd019b56a6b7a8aa2b Mon Sep 17 00:00:00 2001
From: Gabor Horvath <gaborh at apple.com>
Date: Tue, 24 Nov 2026 19:04:42 +0000
Subject: [PATCH 1/2] [analyzer][NFC] Mark leaf classes final
Mark final the classes without subclasses in the MemRegion, SymExpr,
ConstructionContext, PathDiagnosticPiece and BugReport
hierarchies (plus NoteTag), and the RegionStoreManager,
RangeConstraintManager and SimpleSValBuilder implementations, which
call their own virtual methods internally. This lets the compiler
devirtualize calls made through pointers to these types, e.g.
FieldRegion::getValueType() in RegionStoreManager::getBindingForField(),
or the SymExpr visitors in the range inferrer and SimpleSValBuilder.
PathSensitiveBugReport (subclassed by RetainCountChecker) and the
intermediate classes of each hierarchy are left as they are.
In a release build this removes 100 of the 2021 indirect calls (blr on
arm64) in libclangStaticAnalyzerCore, 33 of the 6346 in
libclangStaticAnalyzerCheckers and 5 of the 2218 in libclangAnalysis,
and shrinks the __text of the two analyzer libraries by 0.10% and
0.03%.
On some LLVM TUs (GVN, LiveVariables, RegionStore, SemaExpr) this
changes the instructions of the static analyzer by -0.02% to -0.28%,
which is within the noise caused by code layout changes, so the
performance impact is neutral. Diagnostics are unchanged.
Assisted-by: Claude Opus 5.5
---
.../clang/Analysis/ConstructionContext.h | 23 ++++----
clang/include/clang/Analysis/PathDiagnostic.h | 12 ++---
.../Core/BugReporter/BugReporter.h | 4 +-
.../Core/PathSensitive/MemRegion.h | 54 +++++++++----------
.../Core/PathSensitive/SymbolManager.h | 16 +++---
.../Core/RangeConstraintManager.cpp | 2 +-
clang/lib/StaticAnalyzer/Core/RegionStore.cpp | 2 +-
.../StaticAnalyzer/Core/SimpleSValBuilder.cpp | 2 +-
8 files changed, 58 insertions(+), 57 deletions(-)
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/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 CXXDerivedObjectRegion final : public TypedValueRegion {
friend class MemRegionManager;
const CXXRecordDecl *DerivedD;
diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
index c5419db957615d..01a980bdbc0f2c 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
@@ -41,7 +41,7 @@ class BasicValueFactory;
class StoreManager;
///A symbol representing the value stored at a MemRegion.
-class SymbolRegionValue : public SymbolData {
+class SymbolRegionValue final : public SymbolData {
const TypedValueRegion *R;
friend class SymExprAllocator;
@@ -79,7 +79,7 @@ class SymbolRegionValue : public SymbolData {
/// A symbol representing the result of an expression in the case when we do
/// not know anything about what the expression is.
-class SymbolConjured : public SymbolData {
+class SymbolConjured final : public SymbolData {
ConstCFGElementRef Elem;
QualType T;
unsigned Count;
@@ -134,7 +134,7 @@ class SymbolConjured : public SymbolData {
/// A symbol representing the value of a MemRegion whose parent region has
/// symbolic value.
-class SymbolDerived : public SymbolData {
+class SymbolDerived final : public SymbolData {
SymbolRef parentSymbol;
const TypedValueRegion *R;
@@ -179,7 +179,7 @@ class SymbolDerived : public SymbolData {
/// SymbolExtent - Represents the extent (size in bytes) of a bounded region.
/// Clients should not ask the SymbolManager for a region's extent. Always use
/// SubRegion::getExtent instead -- the value returned may not be a symbol.
-class SymbolExtent : public SymbolData {
+class SymbolExtent final : public SymbolData {
const SubRegion *R;
friend class SymExprAllocator;
@@ -217,7 +217,7 @@ class SymbolExtent : public SymbolData {
/// Metadata symbols remain live as long as they are marked as in use before
/// dead-symbol sweeping AND their associated regions are still alive.
/// Intended for use by checkers.
-class SymbolMetadata : public SymbolData {
+class SymbolMetadata final : public SymbolData {
const MemRegion* R;
const Stmt *S;
QualType T;
@@ -283,7 +283,7 @@ class SymbolMetadata : public SymbolData {
};
/// Represents a cast expression.
-class SymbolCast : public SymExpr {
+class SymbolCast final : public SymExpr {
const SymExpr *Operand;
/// Type of the operand.
@@ -334,7 +334,7 @@ class SymbolCast : public SymExpr {
};
/// Represents a symbolic expression involving a unary operator.
-class UnarySymExpr : public SymExpr {
+class UnarySymExpr final : public SymExpr {
const SymExpr *Operand;
UnaryOperator::Opcode Op;
QualType T;
@@ -430,7 +430,7 @@ class BinarySymExpr : public SymExpr {
/// Template implementation for all binary symbolic expressions
template <class LHSTYPE, class RHSTYPE, SymExpr::Kind ClassK>
-class BinarySymExprImpl : public BinarySymExpr {
+class BinarySymExprImpl final : public BinarySymExpr {
LHSTYPE LHS;
RHSTYPE RHS;
diff --git a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
index dc6fce1ceee9b4..e30a9374979d3c 100644
--- a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -1943,7 +1943,7 @@ RangeSet SymbolicRangeInferrer::VisitBinaryOperator(RangeSet LHS,
// Constraint manager implementation details
//===----------------------------------------------------------------------===//
-class RangeConstraintManager : public RangedConstraintManager {
+class RangeConstraintManager final : public RangedConstraintManager {
public:
RangeConstraintManager(ExprEngine *EE, SValBuilder &SVB)
: RangedConstraintManager(EE, SVB), F(getBasicVals()) {}
diff --git a/clang/lib/StaticAnalyzer/Core/RegionStore.cpp b/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
index e2d6d7eb86f350..b34a3f61462bf0 100644
--- a/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -478,7 +478,7 @@ RegionBindingsRef RegionBindingsRef::removeBinding(const MemRegion *R,
namespace {
class InvalidateRegionsWorker;
-class RegionStoreManager : public StoreManager {
+class RegionStoreManager final : public StoreManager {
public:
RegionBindings::Factory RBFactory;
mutable ClusterBindings::Factory CBFactory;
diff --git a/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp b/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
index 881cff258c0ab2..c1adb7c26bc67f 100644
--- a/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ b/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -22,7 +22,7 @@ using namespace clang;
using namespace ento;
namespace {
-class SimpleSValBuilder : public SValBuilder {
+class SimpleSValBuilder final : public SValBuilder {
// Query the constraint manager whether the SVal has only one possible
// (integer) value. If that is the case, the value is returned. Otherwise,
>From cf8966d0bcf075ffab74947f20d9d10b3332a4f0 Mon Sep 17 00:00:00 2001
From: Gabor Horvath <gaborh at apple.com>
Date: Tue, 24 Nov 2026 19:28:43 +0000
Subject: [PATCH 2/2] [analyzer][NFC] Drop virtual from methods that are never
overridden
StoreManager::getLValueVar, getLValueIvar, getLValueField and
getLValueElement, CallEvent::getArgSourceRange,
RangedConstraintManager::assumeSymRel,
SMTConstraintManager::addStateConstraints and
CFGDominatorTreeImpl::releaseMemory are virtual but have no overrides
anywhere in-tree, and none of them overrides a base class method. Make
them non-virtual, so that calls to them are direct and the trivial ones
(e.g. getLValueVar and getLValueField) can be inlined.
In a release build this removes another 32 of the indirect calls (blr on
arm64) in libclangStaticAnalyzerCore and 28 in
libclangStaticAnalyzerCheckers, and shrinks their __text by 424 and 392
bytes.
On some LLVM TUs (GVN, LiveVariables, RegionStore, SemaExpr) the
instruction count of the static analyzer is within noise of the
previous commit, so the performance impact is neutral. Diagnostics are
unchanged.
Assisted-by: Claude Opus 5.5
---
clang/include/clang/Analysis/Analyses/Dominators.h | 2 +-
.../clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h | 2 +-
.../Core/PathSensitive/RangedConstraintManager.h | 6 +++---
.../Core/PathSensitive/SMTConstraintManager.h | 2 +-
.../clang/StaticAnalyzer/Core/PathSensitive/Store.h | 8 ++++----
5 files changed, 10 insertions(+), 10 deletions(-)
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/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/RangedConstraintManager.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h
index 6b7b94cd3319ce..f9804eac6a5126 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h
@@ -428,9 +428,9 @@ class RangedConstraintManager : public SimpleConstraintManager {
protected:
/// Assume a constraint between a symbolic expression and a concrete integer.
- virtual ProgramStateRef assumeSymRel(ProgramStateRef State, SymbolRef Sym,
- BinaryOperator::Opcode op,
- const llvm::APSInt &Int);
+ ProgramStateRef assumeSymRel(ProgramStateRef State, SymbolRef Sym,
+ BinaryOperator::Opcode op,
+ const llvm::APSInt &Int);
//===------------------------------------------------------------------===//
// Interface that subclasses must implement.
diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
index 47c4c38aa21e7f..4e357d3c7cd6d9 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
@@ -366,7 +366,7 @@ class SMTConstraintManager : public clang::ento::SimpleConstraintManager {
/// Given a program state, construct the logical conjunction and add it to
/// the solver
- virtual void addStateConstraints(ProgramStateRef State) const {
+ void addStateConstraints(ProgramStateRef State) const {
// TODO: Don't add all the constraints, only the relevant ones
auto CZ = State->get<ConstraintSMT>();
auto I = CZ.begin(), IE = CZ.end();
diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/Store.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/Store.h
index 555d5d59d447c9..ae132f8a57a33d 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/Store.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/Store.h
@@ -139,7 +139,7 @@ class StoreManager {
SValBuilder& getSValBuilder() { return svalBuilder; }
- virtual Loc getLValueVar(const VarDecl *VD, const StackFrame *SF) {
+ Loc getLValueVar(const VarDecl *VD, const StackFrame *SF) {
return svalBuilder.makeLoc(MRMgr.getVarRegion(VD, SF));
}
@@ -148,13 +148,13 @@ class StoreManager {
return loc::MemRegionVal(MRMgr.getCompoundLiteralRegion(CL, SF));
}
- virtual SVal getLValueIvar(const ObjCIvarDecl *decl, SVal base);
+ SVal getLValueIvar(const ObjCIvarDecl *decl, SVal base);
- virtual SVal getLValueField(const FieldDecl *D, SVal Base) {
+ SVal getLValueField(const FieldDecl *D, SVal Base) {
return getLValueFieldOrIvar(D, Base);
}
- virtual SVal getLValueElement(QualType elementType, NonLoc offset, SVal Base);
+ SVal getLValueElement(QualType elementType, NonLoc offset, SVal Base);
/// ArrayToPointer - Used by ExprEngine::VistCast to handle implicit
/// conversions between arrays and pointers.
More information about the cfe-commits
mailing list