clang 22.0.0git
clang::TargetCXXABI Class Reference

The basic abstraction for the target C++ ABI. More...

#include "clang/Basic/TargetCXXABI.h"

Public Types

enum  Kind
 The basic C++ ABI kind. More...
enum  TailPaddingUseRules { AlwaysUseTailPadding , UseTailPaddingUnlessPOD03 , UseTailPaddingUnlessPOD11 }
 When is record layout allowed to allocate objects in the tail padding of a base class? More...

Public Member Functions

 TargetCXXABI ()
 A bogus initialization of the platform ABI.
 TargetCXXABI (Kind kind)
void set (Kind kind)
Kind getKind () const
bool isItaniumFamily () const
 Does this ABI generally fall into the Itanium family of ABIs?
bool isMicrosoft () const
 Is this ABI an MSVC-compatible ABI?
bool areMemberFunctionsAligned () const
 Are member functions differently aligned?
bool areArgsDestroyedLeftToRightInCallee () const
 Are arguments to a call destroyed left to right in the callee?
bool hasConstructorVariants () const
 Does this ABI have different entrypoints for complete-object and base-subobject constructors?
bool hasPrimaryVBases () const
 Does this ABI allow virtual bases to be primary base classes?
bool hasKeyFunctions () const
 Does this ABI use key functions?
bool canKeyFunctionBeInline () const
 Can an out-of-line inline function serve as a key function?
TailPaddingUseRules getTailPaddingUseRules () const

Static Public Member Functions

static Kind getKind (StringRef Name)
static const auto & getSpelling (Kind ABIKind)
static bool isABI (StringRef Name)
static bool usesRelativeVTables (const llvm::Triple &T)
static bool isSupportedCXXABI (const llvm::Triple &T, Kind Kind)

Friends

bool operator== (const TargetCXXABI &left, const TargetCXXABI &right)
bool operator!= (const TargetCXXABI &left, const TargetCXXABI &right)

Detailed Description

The basic abstraction for the target C++ ABI.

Definition at line 28 of file TargetCXXABI.h.

Member Enumeration Documentation

◆ Kind

The basic C++ ABI kind.

Definition at line 31 of file TargetCXXABI.h.

◆ TailPaddingUseRules

When is record layout allowed to allocate objects in the tail padding of a base class?

This decision cannot be changed without breaking platform ABI compatibility. In ISO C++98, tail padding reuse was only permitted for non-POD base classes, but that restriction was removed retroactively by DR 43, and tail padding reuse is always permitted in all de facto C++ language modes. However, many platforms use a variant of the old C++98 rule for compatibility.

Enumerator
AlwaysUseTailPadding 

The tail-padding of a base class is always theoretically available, even if it's POD.

UseTailPaddingUnlessPOD03 

Only allocate objects in the tail padding of a base class if the base class is not POD according to the rules of C++ TR1.

UseTailPaddingUnlessPOD11 

Only allocate objects in the tail padding of a base class if the base class is not POD according to the rules of C++11.

Definition at line 267 of file TargetCXXABI.h.

Constructor & Destructor Documentation

◆ TargetCXXABI() [1/2]

clang::TargetCXXABI::TargetCXXABI ( )
inline

A bogus initialization of the platform ABI.

Definition at line 72 of file TargetCXXABI.h.

Referenced by operator!=, and operator==.

◆ TargetCXXABI() [2/2]

clang::TargetCXXABI::TargetCXXABI ( Kind kind)
inline

Definition at line 74 of file TargetCXXABI.h.

Member Function Documentation

◆ areArgsDestroyedLeftToRightInCallee()

bool clang::TargetCXXABI::areArgsDestroyedLeftToRightInCallee ( ) const
inline

Are arguments to a call destroyed left to right in the callee?

This is a fundamental language change, since it implies that objects passed by value do not live to the end of the full expression. Temporaries passed to a function taking a const reference live to the end of the full expression as usual. Both the caller and the callee must have access to the destructor, while only the caller needs the destructor if this is false.

Definition at line 188 of file TargetCXXABI.h.

References isMicrosoft().

Referenced by canEmitDelegateCallArgs(), and handleHlslSplitdouble().

◆ areMemberFunctionsAligned()

bool clang::TargetCXXABI::areMemberFunctionsAligned ( ) const
inline

Are member functions differently aligned?

Many Itanium-style C++ ABIs require member functions to be aligned, so that a pointer to such a function is guaranteed to have a zero in the least significant bit, so that pointers to member functions can use that bit to distinguish between virtual and non-virtual functions. However, some Itanium-style C++ ABIs differentiate between virtual and non-virtual functions via other means, and consequently don't require that member functions be aligned.

Definition at line 158 of file TargetCXXABI.h.

References getKind().

◆ canKeyFunctionBeInline()

bool clang::TargetCXXABI::canKeyFunctionBeInline ( ) const
inline

Can an out-of-line inline function serve as a key function?

This flag is only useful in ABIs where type data (for example, vtables and type_info objects) are emitted only after processing the definition of a special "key" virtual function. (This is safe because the ODR requires that every virtual function be defined somewhere in a program.) This usually permits such data to be emitted in only a single object file, as opposed to redundantly in every object file that requires it.

One simple and common definition of "key function" is the first virtual function in the class definition which is not defined there. This rule works very well when that function has a non-inline definition in some non-header file. Unfortunately, when that function is defined inline, this rule requires the type data to be emitted weakly, as if there were no key function.

The ARM ABI observes that the ODR provides an additional guarantee: a virtual function is always ODR-used, so if it is defined inline, that definition must appear in every translation unit that defines the class. Therefore, there is no reason to allow such functions to serve as key functions.

Because this changes the rules for emitting type data, it can cause type data to be emitted with both weak and strong linkage, which is not allowed on all platforms. Therefore, exploiting this observation requires an ABI break and cannot be done on a generic Itanium platform.

Definition at line 238 of file TargetCXXABI.h.

References getKind().

◆ getKind() [1/2]

Kind clang::TargetCXXABI::getKind ( ) const
inline

◆ getKind() [2/2]

Kind clang::TargetCXXABI::getKind ( StringRef Name)
inlinestatic

Definition at line 59 of file TargetCXXABI.h.

Referenced by clang::ASTContext::getCXXABIKind(), and operator==.

◆ getSpelling()

const auto & clang::TargetCXXABI::getSpelling ( Kind ABIKind)
inlinestatic

Definition at line 60 of file TargetCXXABI.h.

◆ getTailPaddingUseRules()

TailPaddingUseRules clang::TargetCXXABI::getTailPaddingUseRules ( ) const
inline

◆ hasConstructorVariants()

bool clang::TargetCXXABI::hasConstructorVariants ( ) const
inline

Does this ABI have different entrypoints for complete-object and base-subobject constructors?

Definition at line 194 of file TargetCXXABI.h.

References isItaniumFamily().

◆ hasKeyFunctions()

bool clang::TargetCXXABI::hasKeyFunctions ( ) const
inline

Does this ABI use key functions?

If so, class data such as the vtable is emitted with strong linkage by the TU containing the key function.

Definition at line 206 of file TargetCXXABI.h.

References isItaniumFamily().

◆ hasPrimaryVBases()

bool clang::TargetCXXABI::hasPrimaryVBases ( ) const
inline

Does this ABI allow virtual bases to be primary base classes?

Definition at line 199 of file TargetCXXABI.h.

References isItaniumFamily().

◆ isABI()

bool clang::TargetCXXABI::isABI ( StringRef Name)
inlinestatic

Definition at line 63 of file TargetCXXABI.h.

◆ isItaniumFamily()

bool clang::TargetCXXABI::isItaniumFamily ( ) const
inline

Does this ABI generally fall into the Itanium family of ABIs?

The generic Itanium ABI is the standard ABI of most open-source and Unix-like platforms. It is the primary ABI targeted by many compilers, including Clang and GCC.

It is documented here: http://itanium-cxx-abi.github.io/cxx-abi/

The generic ARM ABI is a modified version of the Itanium ABI proposed by ARM for use on ARM-based platforms.

These changes include:

  • the representation of member function pointers is adjusted to not conflict with the 'thumb' bit of ARM function pointers;
  • constructors and destructors return 'this';
  • guard variables are smaller;
  • inline functions are never key functions;
  • array cookies have a slightly different layout;
  • additional convenience functions are specified;
  • and more!

It is documented here: https://github.com/ARM-software/abi-aa/blob/main/cppabi32/cppabi32.rst

The iOS ABI is a partial implementation of the ARM ABI. Several of the features of the ARM ABI were not fully implemented in the compilers that iOS was launched with.

Essentially, the iOS ABI includes the ARM changes to:

  • member function pointers,
  • guard variables,
  • array cookies, and
  • constructor/destructor signatures.

The iOS 64-bit and macOS 64-bit ARM ABI follows ARM's published 64-bit ABI more closely, but we don't guarantee to follow it perfectly.

WatchOS is a modernisation of the iOS ABI, which roughly means it's the iOS64 ABI ported to 32-bits. The primary difference from iOS64 is that RTTI objects must still be unique at the moment.

The generic AArch64 ABI is also a modified version of the Itanium ABI, but it has fewer divergences than the 32-bit ARM ABI.

The relevant changes from the generic ABI in this case are:

  • representation of member function pointers adjusted as in ARM.
  • guard variables are smaller.

It is documented here: https://github.com/ARM-software/abi-aa/blob/main/cppabi64/cppabi64.rst

The generic Mips ABI is a modified version of the Itanium ABI.

At the moment, only change from the generic ABI in this case is:

  • representation of member function pointers adjusted as in ARM.

The WebAssembly ABI is a modified version of the Itanium ABI.

The changes from the Itanium ABI are:

  • representation of member function pointers is adjusted, as in ARM;
  • member functions are not specially aligned;
  • constructors and destructors return 'this', as in ARM;
  • guard variables are 32-bit on wasm32, as in ARM;
  • unused bits of guard variables are reserved, as in ARM;
  • inline functions are never key functions, as in ARM;
  • C++11 POD rules are used for tail padding, as in iOS64.

TODO: At present the WebAssembly ABI is not considered stable, so none of these details is necessarily final yet.

The Fuchsia ABI is a modified version of the Itanium ABI.

The relevant changes from the Itanium ABI are:

  • constructors and destructors return 'this', as in ARM.

The XL ABI is the ABI used by IBM xlclang compiler and is a modified version of the Itanium ABI.

The relevant changes from the Itanium ABI are:

  • static initialization is adjusted to use sinit and sterm functions;

The Microsoft ABI is the ABI used by Microsoft Visual Studio (and compatible compilers).

FIXME: should this be split into Win32 and Win64 variants?

Only scattered and incomplete official documentation exists.

Definition at line 122 of file TargetCXXABI.h.

References getKind().

Referenced by clang::ASTNameGenerator::Implementation::getAllManglings(), hasConstructorVariants(), hasKeyFunctions(), hasPrimaryVBases(), InitDeviceMC(), and UseRelativeLayout().

◆ isMicrosoft()

bool clang::TargetCXXABI::isMicrosoft ( ) const
inline

Is this ABI an MSVC-compatible ABI?

The generic Itanium ABI is the standard ABI of most open-source and Unix-like platforms. It is the primary ABI targeted by many compilers, including Clang and GCC.

It is documented here: http://itanium-cxx-abi.github.io/cxx-abi/

The generic ARM ABI is a modified version of the Itanium ABI proposed by ARM for use on ARM-based platforms.

These changes include:

  • the representation of member function pointers is adjusted to not conflict with the 'thumb' bit of ARM function pointers;
  • constructors and destructors return 'this';
  • guard variables are smaller;
  • inline functions are never key functions;
  • array cookies have a slightly different layout;
  • additional convenience functions are specified;
  • and more!

It is documented here: https://github.com/ARM-software/abi-aa/blob/main/cppabi32/cppabi32.rst

The iOS ABI is a partial implementation of the ARM ABI. Several of the features of the ARM ABI were not fully implemented in the compilers that iOS was launched with.

Essentially, the iOS ABI includes the ARM changes to:

  • member function pointers,
  • guard variables,
  • array cookies, and
  • constructor/destructor signatures.

The iOS 64-bit and macOS 64-bit ARM ABI follows ARM's published 64-bit ABI more closely, but we don't guarantee to follow it perfectly.

WatchOS is a modernisation of the iOS ABI, which roughly means it's the iOS64 ABI ported to 32-bits. The primary difference from iOS64 is that RTTI objects must still be unique at the moment.

The generic AArch64 ABI is also a modified version of the Itanium ABI, but it has fewer divergences than the 32-bit ARM ABI.

The relevant changes from the generic ABI in this case are:

  • representation of member function pointers adjusted as in ARM.
  • guard variables are smaller.

It is documented here: https://github.com/ARM-software/abi-aa/blob/main/cppabi64/cppabi64.rst

The generic Mips ABI is a modified version of the Itanium ABI.

At the moment, only change from the generic ABI in this case is:

  • representation of member function pointers adjusted as in ARM.

The WebAssembly ABI is a modified version of the Itanium ABI.

The changes from the Itanium ABI are:

  • representation of member function pointers is adjusted, as in ARM;
  • member functions are not specially aligned;
  • constructors and destructors return 'this', as in ARM;
  • guard variables are 32-bit on wasm32, as in ARM;
  • unused bits of guard variables are reserved, as in ARM;
  • inline functions are never key functions, as in ARM;
  • C++11 POD rules are used for tail padding, as in iOS64.

TODO: At present the WebAssembly ABI is not considered stable, so none of these details is necessarily final yet.

The Fuchsia ABI is a modified version of the Itanium ABI.

The relevant changes from the Itanium ABI are:

  • constructors and destructors return 'this', as in ARM.

The XL ABI is the ABI used by IBM xlclang compiler and is a modified version of the Itanium ABI.

The relevant changes from the Itanium ABI are:

  • static initialization is adjusted to use sinit and sterm functions;

The Microsoft ABI is the ABI used by Microsoft Visual Studio (and compatible compilers).

FIXME: should this be split into Win32 and Win64 variants?

Only scattered and incomplete official documentation exists.

Definition at line 136 of file TargetCXXABI.h.

References getKind().

Referenced by clang::TargetInfo::adjust(), areArgsDestroyedLeftToRightInCallee(), BuildAppleKextVirtualCall(), checkForMultipleExportedDefaultConstructors(), checkInheritableAttr(), clang::CodeGen::CodeGenFunction::EmitAutoVarAlloca(), clang::ASTNameGenerator::Implementation::getAllManglings(), clang::CodeGen::CodeGenModule::getVTableLinkage(), hasInAllocaArgs(), InitDeviceMC(), clang::installapi::isInlined(), clang::ASTContext::isMSStaticDataMemberInlineDefinition(), isStdBuiltin(), isVarDeclStrongDefinition(), clang::FieldDecl::isZeroSize(), MarkBaseDestructorsReferenced(), ReferenceDllExportedMembers(), and shouldEmitVTableThunk().

◆ isSupportedCXXABI()

bool clang::TargetCXXABI::isSupportedCXXABI ( const llvm::Triple & T,
Kind Kind )
inlinestatic

Definition at line 87 of file TargetCXXABI.h.

References clang::T.

◆ set()

void clang::TargetCXXABI::set ( Kind kind)
inline

Definition at line 76 of file TargetCXXABI.h.

◆ usesRelativeVTables()

bool clang::TargetCXXABI::usesRelativeVTables ( const llvm::Triple & T)
inlinestatic

Definition at line 67 of file TargetCXXABI.h.

References clang::T.

◆ operator!=

bool operator!= ( const TargetCXXABI & left,
const TargetCXXABI & right )
friend

Definition at line 313 of file TargetCXXABI.h.

References TargetCXXABI().

◆ operator==

bool operator== ( const TargetCXXABI & left,
const TargetCXXABI & right )
friend

Definition at line 309 of file TargetCXXABI.h.

References getKind(), and TargetCXXABI().


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