;
34using namespaceCodeGen;
39: Context(Ctx), CGTypes(CGTypes),
Module(M), CodeGenOpts(CGO),
42MDHelper(M.getContext()), Root(nullptr), Char(nullptr) {}
47llvm::MDNode *CodeGenTBAA::getRoot() {
53 if(Features.CPlusPlus)
54Root = MDHelper.createTBAARoot(
"Simple C++ TBAA");
56Root = MDHelper.createTBAARoot(
"Simple C/C++ TBAA");
62llvm::MDNode *CodeGenTBAA::createScalarTypeNode(StringRef Name,
65 if(CodeGenOpts.NewStructPathTBAA) {
66llvm::Metadata *
Id= MDHelper.createString(Name);
67 returnMDHelper.createTBAATypeNode(
Parent, Size,
Id);
69 returnMDHelper.createTBAAScalarTypeNode(Name,
Parent);
72llvm::MDNode *CodeGenTBAA::getChar() {
78Char = createScalarTypeNode(
"omnipotent char", getRoot(),
1);
86 if(TD->hasAttr<MayAliasAttr>())
93 if(TT->getDecl()->hasAttr<MayAliasAttr>())
117llvm::MDNode *CodeGenTBAA::getTypeInfoHelper(
const Type*Ty) {
121 if(
const BuiltinType*BTy = dyn_cast<BuiltinType>(Ty)) {
122 switch(BTy->getKind()) {
128 caseBuiltinType::Char_U:
129 caseBuiltinType::Char_S:
130 caseBuiltinType::UChar:
131 caseBuiltinType::SChar:
135 caseBuiltinType::UShort:
137 caseBuiltinType::UInt:
139 caseBuiltinType::ULong:
141 caseBuiltinType::ULongLong:
143 caseBuiltinType::UInt128:
146 caseBuiltinType::UShortFract:
148 caseBuiltinType::UFract:
150 caseBuiltinType::ULongFract:
153 caseBuiltinType::SatUShortFract:
155 caseBuiltinType::SatUFract:
157 caseBuiltinType::SatULongFract:
160 caseBuiltinType::UShortAccum:
162 caseBuiltinType::UAccum:
164 caseBuiltinType::ULongAccum:
167 caseBuiltinType::SatUShortAccum:
169 caseBuiltinType::SatUAccum:
171 caseBuiltinType::SatULongAccum:
178 returncreateScalarTypeNode(BTy->getName(Features), getChar(), Size);
205llvm::MDNode *AnyPtr = createScalarTypeNode(
"any pointer", getChar(), Size);
206 if(!CodeGenOpts.PointerTBAA)
224 unsignedPtrDepth = 0;
237assert(!isa<VariableArrayType>(Ty));
246 if(isa<BuiltinType>(Ty)) {
247llvm::MDNode *ScalarMD = getTypeInfoHelper(Ty);
249cast<llvm::MDString>(
250ScalarMD->getOperand(CodeGenOpts.NewStructPathTBAA ? 2 : 0))
272 if(!RT->getDecl()->getDeclName())
276llvm::raw_svector_ostream TyOut(TyName);
277MangleCtx->mangleCanonicalTypeName(
QualType(Ty, 0), TyOut);
281OutName += std::to_string(PtrDepth);
284 returncreateScalarTypeNode(OutName, AnyPtr, Size);
288 if(CodeGenOpts.NewStructPathTBAA && Ty->
isArrayType())
289 return getTypeInfo(cast<ArrayType>(Ty)->getElementType());
293 if(
const EnumType*ETy = dyn_cast<EnumType>(Ty)) {
294 if(!Features.CPlusPlus)
295 return getTypeInfo(ETy->getDecl()->getIntegerType());
301 if(!ETy->getDecl()->isExternallyVisible())
305llvm::raw_svector_ostream Out(OutName);
308 returncreateScalarTypeNode(OutName, getChar(), Size);
311 if(
const auto*EIT = dyn_cast<BitIntType>(Ty)) {
313llvm::raw_svector_ostream Out(OutName);
316Out <<
"_BitInt("<< EIT->getNumBits() <<
')';
317 returncreateScalarTypeNode(OutName, getChar(), Size);
327 if(!Features.
Sanitize.
has(SanitizerKind::Type) &&
328(CodeGenOpts.OptimizationLevel == 0 || CodeGenOpts.RelaxedAliasing))
344 returngetValidBaseTypeInfo(QTy);
347 if(llvm::MDNode *N = MetadataCache[Ty])
353llvm::MDNode *TypeNode = getTypeInfoHelper(Ty);
354 returnMetadataCache[Ty] = TypeNode;
371 constllvm::DataLayout &DL =
Module.getDataLayout();
372 unsignedSize = DL.getPointerTypeSize(VTablePtrType);
373 return TBAAAccessInfo(createScalarTypeNode(
"vtable pointer", getRoot(), Size),
378CodeGenTBAA::CollectFields(uint64_t BaseOffset,
386 if(TTy->isUnionType()) {
388llvm::MDNode *TBAAType = getChar();
391llvm::MDBuilder::TBAAStructField(BaseOffset, Size, TBAATag));
400 if(
Decl->bases_begin() !=
Decl->bases_end())
408i != e; ++i, ++idx) {
417 if((*i)->isBitField()) {
429llvm::divideCeil(CurrentBitFieldSize, Context.
getCharWidth());
430llvm::MDNode *TBAAType = getChar();
431llvm::MDNode *TBAATag =
434llvm::MDBuilder::TBAAStructField(Offset, Size, TBAATag));
439 if(!CollectFields(Offset, FieldQTy, Fields,
451Fields.push_back(llvm::MDBuilder::TBAAStructField(Offset, Size, TBAATag));
457 if(CodeGenOpts.OptimizationLevel == 0 || CodeGenOpts.RelaxedAliasing)
462 if(llvm::MDNode *N = StructMetadataCache[Ty])
467 returnMDHelper.createTBAAStructNode(Fields);
470 returnStructMetadataCache[Ty] =
nullptr;
473llvm::MDNode *CodeGenTBAA::getBaseTypeInfoHelper(
const Type*Ty) {
474 if(
auto*TTy = dyn_cast<RecordType>(Ty)) {
477 usingTBAAStructField = llvm::MDBuilder::TBAAStructField;
479 if(
const CXXRecordDecl*CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
483 if(CodeGenOpts.NewStructPathTBAA && CXXRD->getNumVBases() != 0)
493? getValidBaseTypeInfo(BaseQTy)
501llvm::MDBuilder::TBAAStructField(Offset, Size, TypeNode));
509[](
constTBAAStructField &A,
constTBAAStructField &B) {
510 returnA.Offset < B.Offset;
514 if(
Field->isZeroSize(Context) ||
Field->isUnnamedBitField())
518? getValidBaseTypeInfo(FieldQTy)
526Fields.push_back(llvm::MDBuilder::TBAAStructField(Offset, Size,
531 if(Features.CPlusPlus) {
533llvm::raw_svector_ostream Out(OutName);
540 if(CodeGenOpts.NewStructPathTBAA) {
541llvm::MDNode *
Parent= getChar();
543llvm::Metadata *
Id= MDHelper.createString(OutName);
544 returnMDHelper.createTBAATypeNode(
Parent, Size,
Id, Fields);
549 for(
const auto&Field : Fields)
550OffsetsAndTypes.push_back(std::make_pair(
Field.Type,
Field.Offset));
551 returnMDHelper.createTBAAStructTypeNode(OutName, OffsetsAndTypes);
557llvm::MDNode *CodeGenTBAA::getValidBaseTypeInfo(
QualTypeQTy) {
563 autoI = BaseTypeMetadataCache.find(Ty);
564 if(I != BaseTypeMetadataCache.end())
569llvm::MDNode *TypeNode = getBaseTypeInfoHelper(Ty);
570LLVM_ATTRIBUTE_UNUSED
autoinserted =
571BaseTypeMetadataCache.insert({Ty, TypeNode});
572assert(inserted.second &&
"BaseType metadata was already inserted");
582assert(!Info.
isIncomplete() &&
"Access to an object of an incomplete type!");
590 if(!CodeGenOpts.StructPathTBAA)
593llvm::MDNode *&N = AccessTagMetadataCache[Info];
599assert(!Info.
Offset&&
"Nonzero offset for an access with no base type!");
601 if(CodeGenOpts.NewStructPathTBAA) {
622 if(!InfoA || !InfoB)
637 if(DestInfo == SrcInfo)
640 if(!DestInfo || !SrcInfo)
Defines the clang::ASTContext interface.
static bool TypeHasMayAlias(QualType QTy)
static bool isValidBaseType(QualType QTy)
Check if the given type is a valid base type to be used in access tags.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
const ASTRecordLayout & getASTRecordLayout(const RecordDecl *D) const
Get or compute information about the layout of the specified record (struct/union/class) D,...
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
CanQualType SatLongAccumTy
CanQualType SatShortFractTy
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
CanQualType SatLongFractTy
const TargetInfo & getTargetInfo() const
CanQualType SatShortAccumTy
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
uint64_t getCharWidth() const
Return the size of the character type, in bits.
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
uint64_t getFieldOffset(unsigned FieldNo) const
getFieldOffset - Get the offset of the given field index, in bits.
CharUnits getDataSize() const
getDataSize() - Get the record data size, which is the record size without tail padding,...
CharUnits getBaseClassOffset(const CXXRecordDecl *Base) const
getBaseClassOffset - Get the offset, in chars, for the given base class.
This class is used for builtin types like 'int'.
Represents a base class of a C++ class.
Represents a C++ struct/union/class.
bool isEmpty() const
Determine whether this is an empty class in the sense of (C++11 [meta.unary.prop]).
const T * getTypePtr() const
Retrieve the underlying type pointer, which refers to a canonical type.
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
MangleContext & getMangleContext()
Gets the mangle context.
CGRecordLayout - This class handles struct and union layout info while lowering AST types to LLVM typ...
const CGBitFieldInfo & getBitFieldInfo(const FieldDecl *FD) const
Return the BitFieldInfo that corresponds to the field FD.
llvm::MDNode * getBaseTypeInfo(QualType QTy)
getBaseTypeInfo - Get metadata that describes the given base access type.
llvm::MDNode * getTypeInfo(QualType QTy)
getTypeInfo - Get metadata used to describe accesses to objects of the given type.
TBAAAccessInfo getVTablePtrAccessInfo(llvm::Type *VTablePtrType)
getVTablePtrAccessInfo - Get the TBAA information that describes an access to a virtual table pointer...
TBAAAccessInfo mergeTBAAInfoForMemoryTransfer(TBAAAccessInfo DestInfo, TBAAAccessInfo SrcInfo)
mergeTBAAInfoForMemoryTransfer - Get merged TBAA information for the purpose of memory transfer calls...
TBAAAccessInfo mergeTBAAInfoForCast(TBAAAccessInfo SourceInfo, TBAAAccessInfo TargetInfo)
mergeTBAAInfoForCast - Get merged TBAA information for the purpose of type casts.
TBAAAccessInfo mergeTBAAInfoForConditionalOperator(TBAAAccessInfo InfoA, TBAAAccessInfo InfoB)
mergeTBAAInfoForConditionalOperator - Get merged TBAA information for the purpose of conditional oper...
llvm::MDNode * getAccessTagInfo(TBAAAccessInfo Info)
getAccessTagInfo - Get TBAA tag for a given memory access.
llvm::MDNode * getTBAAStructInfo(QualType QTy)
getTBAAStructInfo - Get the TBAAStruct MDNode to be used for a memcpy of the given type.
CodeGenTBAA(ASTContext &Ctx, CodeGenTypes &CGTypes, llvm::Module &M, const CodeGenOptions &CGO, const LangOptions &Features)
TBAAAccessInfo getAccessInfo(QualType AccessType)
getAccessInfo - Get TBAA information that describes an access to an object of the given type.
This class organizes the cross-module state that is used while lowering AST types to LLVM types.
CGCXXABI & getCXXABI() const
const CGRecordLayout & getCGRecordLayout(const RecordDecl *)
getCGRecordLayout - Return record layout info for the given record decl.
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext,...
Decl - This represents one declaration (or definition), e.g.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
Represents a member of a struct/union/class.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
SanitizerSet Sanitize
Set of enabled sanitizers.
virtual void mangleCanonicalTypeName(QualType T, raw_ostream &, bool NormalizeIntegers=false)=0
Generates a unique string for an externally visible type for use with TBAA or type uniquing.
Describes a module or submodule.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
A (possibly-)qualified type.
Represents a struct/union/class.
bool hasFlexibleArrayMember() const
field_iterator field_end() const
field_range fields() const
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
field_iterator field_begin() const
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Exposes information about the current target.
The base class of the type hierarchy.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
bool isPointerType() const
bool isReferenceType() const
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
bool isStdByteType() const
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
const T * getAs() const
Member-template getAs<specific type>'.
TagDecl * getAsTagDecl() const
Retrieves the TagDecl that this type refers to, either because the type is a TagType or because it is...
Defines the clang::TargetInfo interface.
bool isEmptyFieldForLayout(const ASTContext &Context, const FieldDecl *FD)
isEmptyFieldForLayout - Return true iff the field is "empty", that is, either a zero-width bit-field ...
The JSON file list parser is used to communicate input to InstallAPI.
if(T->getSizeExpr()) TRY_TO(TraverseStmt(const_cast< Expr * >(T -> getSizeExpr())))
Structure with information about how a bitfield should be accessed.
unsigned Offset
The offset within a contiguous run of bitfields that are represented as a single "field" within the L...
unsigned Size
The total size of the bit-field, in bits.
unsigned StorageSize
The storage size in bits which should be used when accessing this bitfield.
llvm::MDNode * AccessType
AccessType - The final access type.
uint64_t Offset
Offset - The byte offset of the final access within the base one.
static TBAAAccessInfo getMayAliasInfo()
uint64_t Size
Size - The size of access, in bytes.
static TBAAAccessInfo getIncompleteInfo()
llvm::MDNode * BaseType
BaseType - The base/leading access type.
bool isIncomplete() const
bool has(SanitizerMask K) const
Check if a certain (single) sanitizer is enabled.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4