clang 22.0.0git
clang::dataflow::RecordStorageLocation Class Referencefinal

A storage location for a record (struct, class, or union). More...

#include "clang/Analysis/FlowSensitive/StorageLocation.h"

Inheritance diagram for clang::dataflow::RecordStorageLocation:
[legend]

Public Types

using FieldToLoc = llvm::DenseMap<const ValueDecl *, StorageLocation *>
using SyntheticFieldMap = llvm::StringMap<StorageLocation *>
Public Types inherited from clang::dataflow::StorageLocation
enum class  Kind { Scalar , Record }

Public Member Functions

 RecordStorageLocation (QualType Type, FieldToLoc TheChildren, SyntheticFieldMap TheSyntheticFields)
StorageLocationgetChild (const ValueDecl &D) const
 Returns the child storage location for D.
StorageLocationgetSyntheticField (llvm::StringRef Name) const
 Returns the storage location for the synthetic field Name.
llvm::iterator_range< SyntheticFieldMap::const_iterator > synthetic_fields () const
void addSyntheticField (llvm::StringRef Name, StorageLocation &Loc)
 Add a synthetic field, if none by that name is already present.
void setChild (const ValueDecl &D, StorageLocation *Loc)
 Changes the child storage location for a field D of reference type.
void addChild (const ValueDecl &D, StorageLocation *Loc)
 Add a child storage location for a field D, if not already present.
llvm::iterator_range< FieldToLoc::const_iterator > children () const
Public Member Functions inherited from clang::dataflow::StorageLocation
 StorageLocation (Kind LocKind, QualType Type)
 StorageLocation (const StorageLocation &)=delete
StorageLocationoperator= (const StorageLocation &)=delete
virtual ~StorageLocation ()=default
Kind getKind () const
QualType getType () const

Static Public Member Functions

static bool classof (const StorageLocation *Loc)

Detailed Description

A storage location for a record (struct, class, or union).

Contains storage locations for all modeled fields of the record (also referred to as "children"). The child map is flat, so accessible members of the base class are directly accessible as children of this location.

Record storage locations may also contain so-called synthetic fields. These are typically used to model the internal state of a class (e.g. the value stored in a std::optional) without having to depend on that class's implementation details. All RecordStorageLocations of a given type should have the same synthetic fields.

The storage location for a field of reference type may be null. This typically occurs in one of two situations:

  • The record has not been fully initialized.
  • The maximum depth for modelling a self-referential data structure has been reached. Storage locations for fields of all other types must be non-null.

FIXME: Currently, the storage location of unions is modelled the same way as that of structs or classes. Eventually, we need to change this modelling so that all of the members of a given union have the same storage location.

Definition at line 95 of file StorageLocation.h.

Member Typedef Documentation

◆ FieldToLoc

Definition at line 97 of file StorageLocation.h.

◆ SyntheticFieldMap

Constructor & Destructor Documentation

◆ RecordStorageLocation()

clang::dataflow::RecordStorageLocation::RecordStorageLocation ( QualType Type,
FieldToLoc TheChildren,
SyntheticFieldMap TheSyntheticFields )
inline

Member Function Documentation

◆ addChild()

void clang::dataflow::RecordStorageLocation::addChild ( const ValueDecl & D,
StorageLocation * Loc )
inline

Add a child storage location for a field D, if not already present.

Definition at line 174 of file StorageLocation.h.

References clang::dataflow::StorageLocation::StorageLocation().

◆ addSyntheticField()

void clang::dataflow::RecordStorageLocation::addSyntheticField ( llvm::StringRef Name,
StorageLocation & Loc )
inline

Add a synthetic field, if none by that name is already present.

Definition at line 157 of file StorageLocation.h.

References clang::dataflow::StorageLocation::StorageLocation().

◆ children()

llvm::iterator_range< FieldToLoc::const_iterator > clang::dataflow::RecordStorageLocation::children ( ) const
inline

◆ classof()

bool clang::dataflow::RecordStorageLocation::classof ( const StorageLocation * Loc)
inlinestatic

◆ getChild()

StorageLocation * clang::dataflow::RecordStorageLocation::getChild ( const ValueDecl & D) const
inline

Returns the child storage location for D.

May return null if D has reference type; guaranteed to return non-null in all other cases.

Note that it is an error to call this with a field that does not exist. The function does not return null in this case.

Definition at line 126 of file StorageLocation.h.

References clang::NamedDecl::getNameAsString(), clang::dataflow::StorageLocation::getType(), and clang::dataflow::StorageLocation::StorageLocation().

Referenced by clang::dataflow::builtinTransferInitializer(), clang::dataflow::copyRecord(), and clang::dataflow::recordsEqual().

◆ getSyntheticField()

StorageLocation & clang::dataflow::RecordStorageLocation::getSyntheticField ( llvm::StringRef Name) const
inline

Returns the storage location for the synthetic field Name.

The synthetic field must exist.

Definition at line 145 of file StorageLocation.h.

References clang::dataflow::StorageLocation::StorageLocation().

Referenced by clang::dataflow::copyRecord(), and clang::dataflow::recordsEqual().

◆ setChild()

void clang::dataflow::RecordStorageLocation::setChild ( const ValueDecl & D,
StorageLocation * Loc )
inline

Changes the child storage location for a field D of reference type.

All other fields cannot change their storage location and always retain the storage location passed to the RecordStorageLocation constructor.

Requirements:

D must have reference type.

Definition at line 168 of file StorageLocation.h.

References clang::ValueDecl::getType(), clang::Type::isReferenceType(), and clang::dataflow::StorageLocation::StorageLocation().

Referenced by clang::dataflow::builtinTransferInitializer(), and clang::dataflow::copyField().

◆ synthetic_fields()

llvm::iterator_range< SyntheticFieldMap::const_iterator > clang::dataflow::RecordStorageLocation::synthetic_fields ( ) const
inline

The documentation for this class was generated from the following file: