clang 20.0.0git
Functions
UninitializedObjectChecker.cpp File Reference
#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
#include "UninitializedObject.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/Driver/DriverDiagnostic.h"
#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
#include "clang/StaticAnalyzer/Core/Checker.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicType.h"

Go to the source code of this file.

Functions

static const TypedValueRegiongetConstructedRegion (const CXXConstructorDecl *CtorDecl, CheckerContext &Context)
 Returns the region that was constructed by CtorDecl, or nullptr if that isn't possible.
 
static bool willObjectBeAnalyzedLater (const CXXConstructorDecl *Ctor, CheckerContext &Context)
 Checks whether the object constructed by Ctor will be analyzed later (e.g.
 
static bool shouldIgnoreRecord (const RecordDecl *RD, StringRef Pattern)
 Checks whether RD contains a field with a name or type name that matches Pattern.
 
static bool hasUnguardedAccess (const FieldDecl *FD, ProgramStateRef State)
 Checks syntactically whether it is possible to access FD from the record that contains it without a preceding assert (even if that access happens inside a method).
 
static void printTail (llvm::raw_ostream &Out, const FieldChainInfo::FieldChain L)
 Prints every element except the last to Out.
 
static const StmtgetMethodBody (const CXXMethodDecl *M)
 

Function Documentation

◆ getConstructedRegion()

static const TypedValueRegion * getConstructedRegion ( const CXXConstructorDecl CtorDecl,
CheckerContext Context 
)
static

Returns the region that was constructed by CtorDecl, or nullptr if that isn't possible.

Definition at line 453 of file UninitializedObjectChecker.cpp.

References clang::ento::MemRegion::getAs(), clang::Type::getAsCXXRecordDecl(), clang::ento::SVal::getAsRegion(), and clang::ento::TypedValueRegion::getValueType().

Referenced by willObjectBeAnalyzedLater().

◆ getMethodBody()

static const Stmt * getMethodBody ( const CXXMethodDecl M)
static

◆ hasUnguardedAccess()

static bool hasUnguardedAccess ( const FieldDecl FD,
ProgramStateRef  State 
)
static

Checks syntactically whether it is possible to access FD from the record that contains it without a preceding assert (even if that access happens inside a method).

This is mainly used for records that act like unions, like having multiple bit fields, with only a fraction being properly initialized. If these fields are properly guarded with asserts, this method returns false.

Since this check is done syntactically, this method could be inaccurate.

Definition at line 520 of file UninitializedObjectChecker.cpp.

References clang::ast_matchers::anyOf, clang::AS_public, clang::ast_matchers::callExpr, clang::ast_matchers::conditionalOperator, clang::ast_matchers::functionDecl, clang::Decl::getAccess(), getMethodBody(), clang::FieldDecl::getParent(), clang::ast_matchers::hasAnyName, clang::ast_matchers::hasDeclaration(), clang::ast_matchers::hasDescendant, clang::ast_matchers::ifStmt, clang::ast_matchers::match(), clang::ast_matchers::memberExpr, Parent, clang::ast_matchers::stmt, and clang::ast_matchers::switchStmt.

◆ printTail()

static void printTail ( llvm::raw_ostream &  Out,
const FieldChainInfo::FieldChain  L 
)
static

Prints every element except the last to Out.

Since ImmutableLists store elements in reverse order, and have no reverse iterators, we use a recursive function to print the fieldchain correctly. The last element in the chain is to be printed by FieldChainInfo::print.

Definition at line 437 of file UninitializedObjectChecker.cpp.

References printTail().

Referenced by clang::ento::FieldChainInfo::printNoteMsg(), and printTail().

◆ shouldIgnoreRecord()

static bool shouldIgnoreRecord ( const RecordDecl RD,
StringRef  Pattern 
)
static

Checks whether RD contains a field with a name or type name that matches Pattern.

Definition at line 497 of file UninitializedObjectChecker.cpp.

References clang::RecordDecl::fields().

◆ willObjectBeAnalyzedLater()

static bool willObjectBeAnalyzedLater ( const CXXConstructorDecl Ctor,
CheckerContext Context 
)
static

Checks whether the object constructed by Ctor will be analyzed later (e.g.

if the object is a field of another object, in which case we'd check it multiple times).

Definition at line 468 of file UninitializedObjectChecker.cpp.

References getConstructedRegion(), clang::LocationContext::getDecl(), clang::LocationContext::getParent(), and clang::ento::SubRegion::isSubRegionOf().