clang 20.0.0git
Public Types | Public Member Functions | Static Public Member Functions | List of all members
clang::CharUnits Class Reference

CharUnits - This is an opaque type for sizes expressed in character units. More...

#include "clang/AST/CharUnits.h"

Public Types

typedef int64_t QuantityType
 

Public Member Functions

 CharUnits ()=default
 CharUnits - A default constructor.
 
CharUnitsoperator+= (const CharUnits &Other)
 
CharUnitsoperator++ ()
 
CharUnits operator++ (int)
 
CharUnitsoperator-= (const CharUnits &Other)
 
CharUnitsoperator-- ()
 
CharUnits operator-- (int)
 
bool operator== (const CharUnits &Other) const
 
bool operator!= (const CharUnits &Other) const
 
bool operator< (const CharUnits &Other) const
 
bool operator<= (const CharUnits &Other) const
 
bool operator> (const CharUnits &Other) const
 
bool operator>= (const CharUnits &Other) const
 
bool isZero () const
 isZero - Test whether the quantity equals zero.
 
bool isOne () const
 isOne - Test whether the quantity equals one.
 
bool isPositive () const
 isPositive - Test whether the quantity is greater than zero.
 
bool isNegative () const
 isNegative - Test whether the quantity is less than zero.
 
bool isPowerOfTwo () const
 isPowerOfTwo - Test whether the quantity is a power of two.
 
bool isMultipleOf (CharUnits N) const
 Test whether this is a multiple of the other value.
 
CharUnits operator* (QuantityType N) const
 
CharUnitsoperator*= (QuantityType N)
 
CharUnits operator/ (QuantityType N) const
 
CharUnitsoperator/= (QuantityType N)
 
QuantityType operator/ (const CharUnits &Other) const
 
CharUnits operator% (QuantityType N) const
 
QuantityType operator% (const CharUnits &Other) const
 
CharUnits operator+ (const CharUnits &Other) const
 
CharUnits operator- (const CharUnits &Other) const
 
CharUnits operator- () const
 
QuantityType getQuantity () const
 getQuantity - Get the raw integer representation of this quantity.
 
llvm::Align getAsAlign () const
 getAsAlign - Returns Quantity as a valid llvm::Align, Beware llvm::Align assumes power of two 8-bit bytes.
 
llvm::MaybeAlign getAsMaybeAlign () const
 getAsMaybeAlign - Returns Quantity as a valid llvm::Align or std::nullopt, Beware llvm::MaybeAlign assumes power of two 8-bit bytes.
 
CharUnits alignTo (const CharUnits &Align) const
 alignTo - Returns the next integer (mod 2**64) that is greater than or equal to this quantity and is a multiple of Align.
 
CharUnits alignmentAtOffset (CharUnits offset) const
 Given that this is a non-zero alignment value, what is the alignment at the given offset?
 
CharUnits alignmentOfArrayElement (CharUnits elementSize) const
 Given that this is the alignment of the first element of an array, return the minimum alignment of any element in the array.
 

Static Public Member Functions

static CharUnits Zero ()
 Zero - Construct a CharUnits quantity of zero.
 
static CharUnits One ()
 One - Construct a CharUnits quantity of one.
 
static CharUnits fromQuantity (QuantityType Quantity)
 fromQuantity - Construct a CharUnits quantity from a raw integer type.
 
static CharUnits fromQuantity (llvm::Align Quantity)
 fromQuantity - Construct a CharUnits quantity from an llvm::Align quantity.
 

Detailed Description

CharUnits - This is an opaque type for sizes expressed in character units.

Instances of this type represent a quantity as a multiple of the size of the standard C type, char, on the target architecture. As an opaque type, CharUnits protects you from accidentally combining operations on quantities in bit units and character units.

In both C and C++, an object of type 'char', 'signed char', or 'unsigned char' occupies exactly one byte, so 'character unit' and 'byte' refer to the same quantity of storage. However, we use the term 'character unit' rather than 'byte' to avoid an implication that a character unit is exactly 8 bits.

For portability, never assume that a target character is 8 bits wide. Use CharUnit values wherever you calculate sizes, offsets, or alignments in character units.

Definition at line 38 of file CharUnits.h.

Member Typedef Documentation

◆ QuantityType

Definition at line 40 of file CharUnits.h.

Constructor & Destructor Documentation

◆ CharUnits()

clang::CharUnits::CharUnits ( )
default

Member Function Documentation

◆ alignmentAtOffset()

CharUnits clang::CharUnits::alignmentAtOffset ( CharUnits  offset) const
inline

◆ alignmentOfArrayElement()

CharUnits clang::CharUnits::alignmentOfArrayElement ( CharUnits  elementSize) const
inline

Given that this is the alignment of the first element of an array, return the minimum alignment of any element in the array.

Definition at line 214 of file CharUnits.h.

References alignmentAtOffset().

Referenced by clang::CodeGen::CGBuilderTy::CreateGEP(), EmitArrayDelete(), emitNonZeroVLAInit(), EmitOMPAggregateInit(), EmitOMPAggregateReduction(), clang::CodeGen::CGOpenMPRuntime::emitUserDefinedMapper(), and getArrayElementAlign().

◆ alignTo()

CharUnits clang::CharUnits::alignTo ( const CharUnits Align) const
inline

◆ fromQuantity() [1/2]

static CharUnits clang::CharUnits::fromQuantity ( llvm::Align  Quantity)
inlinestatic

fromQuantity - Construct a CharUnits quantity from an llvm::Align quantity.

Definition at line 69 of file CharUnits.h.

References CharUnits().

◆ fromQuantity() [2/2]

static CharUnits clang::CharUnits::fromQuantity ( QuantityType  Quantity)
inlinestatic

fromQuantity - Construct a CharUnits quantity from a raw integer type.

Definition at line 63 of file CharUnits.h.

References CharUnits().

Referenced by addOrSubLValueAsInteger(), clang::CodeGen::ConstantAggregateBuilderBase::addPlaceholderWithSize(), CheckAggExprForMemSetUse(), CheckAtomicAlignment(), computeOffsetHint(), convertUnsignedAPIntToCharUnits(), clang::CodeGen::CGBuilderTy::CreateConstArrayGEP(), clang::CodeGen::CGBuilderTy::CreateConstGEP(), clang::CodeGen::CGBuilderTy::CreateConstInBoundsGEP(), clang::CodeGen::CGBuilderTy::CreateGEP(), createPlaceholderSlot(), clang::CodeGen::CGBuilderTy::CreatePreserveStructAccessIndex(), clang::CodeGen::CGBuilderTy::CreateStructGEP(), CreateTempAllocaForCoercion(), DumpRecordLayout(), emitAddressAtOffset(), clang::CodeGen::CGDebugInfo::EmitDeclareOfBlockDeclRefVariable(), emitStoresForConstant(), clang::CodeGen::CGObjCRuntime::EmitValueForIvarAtOffset(), EmitX86_64VAArgFromMemory(), clang::CodeGen::CGOpenMPRuntime::getAddressOfLocalVariable(), clang::CodeGen::CodeGenFunction::OMPBuilderCBHelpers::getAddressOfLocalVariable(), clang::CodeGen::CodeGenModule::GetAddrOfConstantCFString(), clang::CodeGen::CodeGenModule::GetAddrOfMSGuidDecl(), clang::CodeGen::CGFunctionInfo::getArgStructAlignment(), clang::ento::ElementRegion::getAsArrayOffset(), clang::ASTContext::getASTRecordLayout(), getBaseAlignmentAndOffsetFromLValue(), clang::CodeGen::swiftcall::SwiftAggLowering::getCoerceAndExpandTypes(), getConstantArrayInfoInChars(), llvm::DenseMapInfo< clang::BaseSubobject >::getEmptyKey(), llvm::DenseMapInfo< clang::CharUnits >::getEmptyKey(), clang::CodeGen::ABIArgInfo::getIndirectAlign(), clang::CodeGen::CodeGenTypeCache::getIntAlign(), clang::CodeGen::CodeGenTypeCache::getIntSize(), getLowBit(), getMaxAtomicAccessSize(), clang::CodeGen::swiftcall::getNaturalAlignment(), clang::CodeGen::CodeGenModule::getNaturalTypeAlignment(), clang::CodeGen::CGBlockInfo::Capture::getOffset(), getOffsetAtStartOfUnit(), getOffsetOfFullPath(), clang::CodeGen::CodeGenModule::getOMPAllocateAlignment(), clang::CodeGen::CodeGenTypeCache::getPointerAlign(), clang::CodeGen::CodeGenTypeCache::getPointerSize(), clang::CodeGen::CodeGenTypeCache::getSizeAlign(), clang::CodeGen::CodeGenTypeCache::getSizeSize(), llvm::DenseMapInfo< clang::BaseSubobject >::getTombstoneKey(), llvm::DenseMapInfo< clang::CharUnits >::getTombstoneKey(), getTypeAllocSize(), getTypeStoreSize(), initializeForBlockHeader(), clang::interp::interp__builtin_atomic_lock_free(), clang::interp::interp__builtin_is_aligned_up_down(), isVarDeclStrongDefinition(), clang::LayoutOverrideSource::LayoutOverrideSource(), loadRISCVFeatureBits(), clang::CodeGen::CGBitFieldInfo::MakeInfo(), performTypeAdjustment(), clang::CodeGen::DominatingLLVMValue::save(), clang::analyze_os_log::OSLogBufferLayout::size(), clang::interp::FunctionPointer::toAPValue(), clang::interp::Pointer::toAPValue(), clang::ASTContext::toCharUnitsFromBits(), clang::CodeGen::CodeGenTypes::typeRequiresSplitIntoByteArray(), and clang::ento::ExprEngine::VisitUnaryExprOrTypeTraitExpr().

◆ getAsAlign()

llvm::Align clang::CharUnits::getAsAlign ( ) const
inline

getAsAlign - Returns Quantity as a valid llvm::Align, Beware llvm::Align assumes power of two 8-bit bytes.

Definition at line 189 of file CharUnits.h.

Referenced by buildGlobalBlock(), clang::CodeGen::CodeGenModule::ConstructAttributeList(), clang::CodeGen::CGBuilderTy::CreateAlignedLoad(), clang::CodeGen::CGBuilderTy::CreateAlignedStore(), clang::CodeGen::CGBuilderTy::CreateAtomicCmpXchg(), clang::CodeGen::CGBuilderTy::CreateAtomicRMW(), CreateCoercedLoad(), clang::CodeGen::CGBuilderTy::CreateLoad(), createLoadInstBefore(), clang::CodeGen::CGBuilderTy::CreateMemCpy(), clang::CodeGen::CGBuilderTy::CreateMemCpyInline(), clang::CodeGen::CGBuilderTy::CreateMemMove(), clang::CodeGen::CGBuilderTy::CreateMemSet(), clang::CodeGen::CGBuilderTy::CreateMemSetInline(), createReferenceTemporary(), clang::CodeGen::CGBuilderTy::CreateStore(), createStoreInstBefore(), clang::CodeGen::CodeGenModule::createUnnamedGlobalFrom(), clang::CodeGen::CGOpenMPRuntime::emitLastprivateConditionalUpdate(), EmitNullBaseClassInitialization(), GenerateStringLiteral(), clang::CodeGen::CGOpenMPRuntimeGPU::getAddressOfLocalVariable(), clang::CodeGen::CodeGenModule::GetAddrOfConstantCFString(), clang::CodeGen::CodeGenModule::GetAddrOfConstantCString(), clang::CodeGen::CodeGenModule::GetAddrOfConstantStringFromLiteral(), clang::CodeGen::CodeGenModule::GetAddrOfGlobalTemporary(), clang::CodeGen::CodeGenModule::GetAddrOfUnnamedGlobalConstantDecl(), getInitThreadEpochPtr(), and clang::CodeGen::CodeGenFunction::setBeforeOutermostConditional().

◆ getAsMaybeAlign()

llvm::MaybeAlign clang::CharUnits::getAsMaybeAlign ( ) const
inline

getAsMaybeAlign - Returns Quantity as a valid llvm::Align or std::nullopt, Beware llvm::MaybeAlign assumes power of two 8-bit bytes.

Definition at line 194 of file CharUnits.h.

◆ getQuantity()

QuantityType clang::CharUnits::getQuantity ( ) const
inline

getQuantity - Get the raw integer representation of this quantity.

Definition at line 185 of file CharUnits.h.

Referenced by clang::Sema::AddAlignedAttr(), AddPointerLayoutOffset(), AddRelativeLayoutOffset(), clang::ODRHash::AddStructuralValue(), ApplyNonVirtualAndVirtualOffset(), clang::interp::IntPointer::atOffset(), clang::ASTContext::AtomicUsesUnsupportedLibcall(), buildBlockDescriptor(), clang::Sema::BuildCXXNew(), buildGlobalBlock(), buildMemcpyForAssignmentOp(), clang::Sema::BuildPredefinedExpr(), calculateOffset(), clang::ento::StoreManager::castRegion(), charUnitsToString(), clang::SemaPPC::checkAIXMemberAlignment(), clang::Sema::CheckAlignasUnderalignment(), clang::Sema::checkArrayElementAlignment(), CheckAtomicAlignment(), clang::Sema::CheckCastAlign(), clang::Sema::CheckCXXThrowOperand(), clang::Sema::CheckThreadLocalForLargeAlignment(), computeBlockInfo(), computeOffset(), clang::CodeGen::CodeGenModule::ConstructAttributeList(), clang::CodeGen::CodeGenTypes::convertTypeForLoadStore(), clang::CodeGen::CodeGenTypes::ConvertTypeForMem(), clang::CodeGen::CodeGenModule::createUnnamedGlobalFrom(), clang::Sema::DefaultArgumentPromotion(), clang::Sema::DiagnoseSizeOfParametersAndReturnValue(), clang::CodeGen::ABIArgInfo::dump(), DumpRecordLayout(), clang::ento::RegionRawOffset::dumpToStream(), emitAlignedClause(), EmitCXXNewAllocSize(), clang::CodeGen::CGDebugInfo::EmitDeclareOfBlockDeclRefVariable(), clang::CodeGen::CGOpenMPRuntime::emitDeclareSimdFunction(), clang::CodeGen::CGOpenMPRuntime::emitDeclareTargetFunction(), EmitISOVolatileLoad(), emitNonZeroVLAInit(), clang::CodeGen::emitRoundPointerUpToAlignment(), clang::CodeGen::CGOpenMPRuntime::emitUDMapperArrayInitOrDel(), clang::CodeGen::CGOpenMPRuntime::emitUserDefinedMapper(), encodeTypeForFunctionPointerAuth(), EvaluateComparisonBinaryOperator(), clang::Sema::FillInlineAsmIdentifierInfo(), clang::CodeGen::CodeGenTBAA::getAccessInfo(), clang::CodeGen::CodeGenModule::GetAddrOfConstantCString(), clang::CodeGen::CodeGenModule::GetAddrOfConstantStringFromLiteral(), GetAlignedMapping(), getBlockDescriptorName(), getConstantArrayInfoInChars(), getCopyDestroyHelperFuncName(), getExceedsMsgs(), llvm::DenseMapInfo< clang::CharUnits >::getHashValue(), getIndex(), clang::CodeGen::CGOpenMPRuntimeGPU::getKmpcAllocShared(), clang::CodeGen::swiftcall::getNaturalAlignment(), clang::CodeGen::CodeGenModule::getNaturalTypeAlignment(), clang::ConstantArrayType::getNumAddressingBits(), getOffsetAtStartOfUnit(), clang::CodeGen::CodeGenModule::getOMPAllocateAlignment(), clang::CodeGen::CGOpenCLRuntime::getPipeElemAlign(), clang::CodeGen::CGOpenCLRuntime::getPipeElemSize(), clang::CodeGen::CGBuilderTy::getSize(), clang::CodeGen::CodeGenModule::getSize(), clang::analyze_os_log::OSLogBufferItem::getSizeByte(), HandleOperatorNewCall(), initializeForBlockHeader(), clang::interp::interp__builtin_is_aligned_up_down(), clang::interp::interp__builtin_os_log_format_buffer_size(), clang::CodeGen::SwiftABIInfo::isLegalVectorType(), clang::CodeGen::CGBlockInfo::Capture::makeIndex(), mergeAlignedAttrs(), clang::CodeGen::CGBitFieldInfo::print(), clang::APValue::printPretty(), clang::CodeGen::BlockByrefHelpers::Profile(), clang::CodeGen::CodeGenModule::Release(), clang::CodeGen::CGFunctionInfo::setArgStruct(), clang::CodeGen::ABIArgInfo::setIndirectAlign(), setUsedBits(), clang::ASTContext::toBits(), tryToInvalidateFReadBufferByElements(), clang::Value::Value(), and clang::ento::ExprEngine::VisitUnaryExprOrTypeTraitExpr().

◆ isMultipleOf()

bool clang::CharUnits::isMultipleOf ( CharUnits  N) const
inline

Test whether this is a multiple of the other value.

Among other things, this promises that self.alignTo(N) will just return self.

Definition at line 143 of file CharUnits.h.

◆ isNegative()

bool clang::CharUnits::isNegative ( ) const
inline

isNegative - Test whether the quantity is less than zero.

Definition at line 131 of file CharUnits.h.

Referenced by EmitNullBaseClassInitialization().

◆ isOne()

bool clang::CharUnits::isOne ( ) const
inline

◆ isPositive()

bool clang::CharUnits::isPositive ( ) const
inline

◆ isPowerOfTwo()

bool clang::CharUnits::isPowerOfTwo ( ) const
inline

isPowerOfTwo - Test whether the quantity is a power of two.

Zero is not a power of two.

Definition at line 135 of file CharUnits.h.

◆ isZero()

bool clang::CharUnits::isZero ( ) const
inline

◆ One()

static CharUnits clang::CharUnits::One ( )
inlinestatic

◆ operator!=()

bool clang::CharUnits::operator!= ( const CharUnits Other) const
inline

Definition at line 101 of file CharUnits.h.

References clang::Other.

◆ operator%() [1/2]

QuantityType clang::CharUnits::operator% ( const CharUnits Other) const
inline

Definition at line 168 of file CharUnits.h.

References clang::Other.

◆ operator%() [2/2]

CharUnits clang::CharUnits::operator% ( QuantityType  N) const
inline

Definition at line 165 of file CharUnits.h.

References CharUnits().

◆ operator*()

CharUnits clang::CharUnits::operator* ( QuantityType  N) const
inline

Definition at line 148 of file CharUnits.h.

References CharUnits().

◆ operator*=()

CharUnits & clang::CharUnits::operator*= ( QuantityType  N)
inline

Definition at line 151 of file CharUnits.h.

◆ operator+()

CharUnits clang::CharUnits::operator+ ( const CharUnits Other) const
inline

Definition at line 171 of file CharUnits.h.

References CharUnits(), and clang::Other.

◆ operator++() [1/2]

CharUnits & clang::CharUnits::operator++ ( )
inline

Definition at line 78 of file CharUnits.h.

◆ operator++() [2/2]

CharUnits clang::CharUnits::operator++ ( int  )
inline

Definition at line 82 of file CharUnits.h.

References CharUnits().

◆ operator+=()

CharUnits & clang::CharUnits::operator+= ( const CharUnits Other)
inline

Definition at line 74 of file CharUnits.h.

References clang::Other.

◆ operator-() [1/2]

CharUnits clang::CharUnits::operator- ( ) const
inline

Definition at line 177 of file CharUnits.h.

References CharUnits().

◆ operator-() [2/2]

CharUnits clang::CharUnits::operator- ( const CharUnits Other) const
inline

Definition at line 174 of file CharUnits.h.

References CharUnits(), and clang::Other.

◆ operator--() [1/2]

CharUnits & clang::CharUnits::operator-- ( )
inline

Definition at line 89 of file CharUnits.h.

◆ operator--() [2/2]

CharUnits clang::CharUnits::operator-- ( int  )
inline

Definition at line 93 of file CharUnits.h.

References CharUnits().

◆ operator-=()

CharUnits & clang::CharUnits::operator-= ( const CharUnits Other)
inline

Definition at line 85 of file CharUnits.h.

References clang::Other.

◆ operator/() [1/2]

QuantityType clang::CharUnits::operator/ ( const CharUnits Other) const
inline

Definition at line 162 of file CharUnits.h.

References clang::Other.

◆ operator/() [2/2]

CharUnits clang::CharUnits::operator/ ( QuantityType  N) const
inline

Definition at line 155 of file CharUnits.h.

References CharUnits().

◆ operator/=()

CharUnits & clang::CharUnits::operator/= ( QuantityType  N)
inline

Definition at line 158 of file CharUnits.h.

◆ operator<()

bool clang::CharUnits::operator< ( const CharUnits Other) const
inline

Definition at line 106 of file CharUnits.h.

References clang::Other.

◆ operator<=()

bool clang::CharUnits::operator<= ( const CharUnits Other) const
inline

Definition at line 109 of file CharUnits.h.

References clang::Other.

◆ operator==()

bool clang::CharUnits::operator== ( const CharUnits Other) const
inline

Definition at line 98 of file CharUnits.h.

References clang::Other.

◆ operator>()

bool clang::CharUnits::operator> ( const CharUnits Other) const
inline

Definition at line 112 of file CharUnits.h.

References clang::Other.

◆ operator>=()

bool clang::CharUnits::operator>= ( const CharUnits Other) const
inline

Definition at line 115 of file CharUnits.h.

References clang::Other.

◆ Zero()

static CharUnits clang::CharUnits::Zero ( )
inlinestatic

Zero - Construct a CharUnits quantity of zero.

Definition at line 53 of file CharUnits.h.

References CharUnits().

Referenced by clang::CodeGen::swiftcall::SwiftAggLowering::addTypedData(), BuildAppleKextVirtualCall(), CalculateCookiePadding(), classifyType(), computeBlockInfo(), computeFullPathsForVFTables(), clang::CodeGen::CodeGenModule::computeNonVirtualBaseClassOffset(), DiagnoseReinterpretUpDownCast(), EmitNullBaseClassInitialization(), clang::SourceLocExpr::EvaluateInContext(), getAlignmentAndOffsetFromBinAddOrSub(), clang::CodeGen::CGCXXABI::GetArrayCookieSize(), clang::CodeGen::CGCXXABI::getArrayCookieSizeImpl(), clang::ASTContext::getASTRecordLayout(), getBaseAlignmentAndOffsetFromLValue(), getBaseAlignmentAndOffsetFromPtr(), clang::CodeGen::swiftcall::SwiftAggLowering::getCoerceAndExpandTypes(), getDerivedToBaseAlignmentAndOffset(), clang::VarDecl::getFlexibleArrayInitChars(), clang::ASTContext::getMemberPointerPathAdjustment(), GetNumNonZeroBytesInInit(), clang::ASTContext::getObjCEncodingForFunctionDecl(), clang::ASTContext::getObjCEncodingTypeSize(), clang::ASTContext::getOffsetOfBaseWithVBPtr(), getOffsetOfFullPath(), getTypeExpansion(), clang::ItaniumVTableContext::getVirtualBaseOffsetOffset(), clang::CodeGen::CGCXXABI::getVirtualFunctionPrologueThisAdjustment(), clang::APValue::printPretty(), clang::CodeGen::CGCXXABI::ReadArrayCookie(), selectBestPath(), clang::interp::FunctionPointer::toAPValue(), clang::interp::Pointer::toAPValue(), and clang::VTTBuilder::VTTBuilder().


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