clang 20.0.0git
CodeGenTBAA.cpp
Go to the documentation of this file.
1//===-- CodeGenTBAA.cpp - TBAA information for LLVM CodeGen ---------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This is the code that manages TBAA information and defines the TBAA policy
10// for the optimizer to use. Relevant standards text includes:
11//
12// C99 6.5p7
13// C++ [basic.lval] (p10 in n3126, p15 in some earlier versions)
14//
15//===----------------------------------------------------------------------===//
16
17#include "CodeGenTBAA.h"
18#include "ABIInfoImpl.h"
19#include "CGRecordLayout.h"
20#include "CodeGenTypes.h"
22#include "clang/AST/Attr.h"
23#include "clang/AST/Mangle.h"
27#include "llvm/ADT/SmallSet.h"
28#include "llvm/IR/Constants.h"
29#include "llvm/IR/LLVMContext.h"
30#include "llvm/IR/Metadata.h"
31#include "llvm/IR/Module.h"
32#include "llvm/IR/Type.h"
33#include "llvm/Support/Debug.h"
34using namespace clang;
35using namespace CodeGen;
36
38 llvm::Module &M, const CodeGenOptions &CGO,
39 const LangOptions &Features, MangleContext &MContext)
40 : Context(Ctx), CGTypes(CGTypes), Module(M), CodeGenOpts(CGO),
41 Features(Features), MContext(MContext), MDHelper(M.getContext()),
42 Root(nullptr), Char(nullptr) {}
43
45}
46
47llvm::MDNode *CodeGenTBAA::getRoot() {
48 // Define the root of the tree. This identifies the tree, so that
49 // if our LLVM IR is linked with LLVM IR from a different front-end
50 // (or a different version of this front-end), their TBAA trees will
51 // remain distinct, and the optimizer will treat them conservatively.
52 if (!Root) {
53 if (Features.CPlusPlus)
54 Root = MDHelper.createTBAARoot("Simple C++ TBAA");
55 else
56 Root = MDHelper.createTBAARoot("Simple C/C++ TBAA");
57 }
58
59 return Root;
60}
61
62llvm::MDNode *CodeGenTBAA::createScalarTypeNode(StringRef Name,
63 llvm::MDNode *Parent,
64 uint64_t Size) {
65 if (CodeGenOpts.NewStructPathTBAA) {
66 llvm::Metadata *Id = MDHelper.createString(Name);
67 return MDHelper.createTBAATypeNode(Parent, Size, Id);
68 }
69 return MDHelper.createTBAAScalarTypeNode(Name, Parent);
70}
71
72llvm::MDNode *CodeGenTBAA::getChar() {
73 // Define the root of the tree for user-accessible memory. C and C++
74 // give special powers to char and certain similar types. However,
75 // these special powers only cover user-accessible memory, and doesn't
76 // include things like vtables.
77 if (!Char)
78 Char = createScalarTypeNode("omnipotent char", getRoot(), /* Size= */ 1);
79
80 return Char;
81}
82
83static bool TypeHasMayAlias(QualType QTy) {
84 // Tagged types have declarations, and therefore may have attributes.
85 if (auto *TD = QTy->getAsTagDecl())
86 if (TD->hasAttr<MayAliasAttr>())
87 return true;
88
89 // Also look for may_alias as a declaration attribute on a typedef.
90 // FIXME: We should follow GCC and model may_alias as a type attribute
91 // rather than as a declaration attribute.
92 while (auto *TT = QTy->getAs<TypedefType>()) {
93 if (TT->getDecl()->hasAttr<MayAliasAttr>())
94 return true;
95 QTy = TT->desugar();
96 }
97 return false;
98}
99
100/// Check if the given type is a valid base type to be used in access tags.
101static bool isValidBaseType(QualType QTy) {
102 if (const RecordType *TTy = QTy->getAs<RecordType>()) {
103 const RecordDecl *RD = TTy->getDecl()->getDefinition();
104 // Incomplete types are not valid base access types.
105 if (!RD)
106 return false;
107 if (RD->hasFlexibleArrayMember())
108 return false;
109 // RD can be struct, union, class, interface or enum.
110 // For now, we only handle struct and class.
111 if (RD->isStruct() || RD->isClass())
112 return true;
113 }
114 return false;
115}
116
117llvm::MDNode *CodeGenTBAA::getTypeInfoHelper(const Type *Ty) {
119
120 // Handle builtin types.
121 if (const BuiltinType *BTy = dyn_cast<BuiltinType>(Ty)) {
122 switch (BTy->getKind()) {
123 // Character types are special and can alias anything.
124 // In C++, this technically only includes "char" and "unsigned char",
125 // and not "signed char". In C, it includes all three. For now,
126 // the risk of exploiting this detail in C++ seems likely to outweigh
127 // the benefit.
128 case BuiltinType::Char_U:
129 case BuiltinType::Char_S:
130 case BuiltinType::UChar:
131 case BuiltinType::SChar:
132 return getChar();
133
134 // Unsigned types can alias their corresponding signed types.
135 case BuiltinType::UShort:
136 return getTypeInfo(Context.ShortTy);
137 case BuiltinType::UInt:
138 return getTypeInfo(Context.IntTy);
139 case BuiltinType::ULong:
140 return getTypeInfo(Context.LongTy);
141 case BuiltinType::ULongLong:
142 return getTypeInfo(Context.LongLongTy);
143 case BuiltinType::UInt128:
144 return getTypeInfo(Context.Int128Ty);
145
146 case BuiltinType::UShortFract:
147 return getTypeInfo(Context.ShortFractTy);
148 case BuiltinType::UFract:
149 return getTypeInfo(Context.FractTy);
150 case BuiltinType::ULongFract:
151 return getTypeInfo(Context.LongFractTy);
152
153 case BuiltinType::SatUShortFract:
154 return getTypeInfo(Context.SatShortFractTy);
155 case BuiltinType::SatUFract:
156 return getTypeInfo(Context.SatFractTy);
157 case BuiltinType::SatULongFract:
158 return getTypeInfo(Context.SatLongFractTy);
159
160 case BuiltinType::UShortAccum:
161 return getTypeInfo(Context.ShortAccumTy);
162 case BuiltinType::UAccum:
163 return getTypeInfo(Context.AccumTy);
164 case BuiltinType::ULongAccum:
165 return getTypeInfo(Context.LongAccumTy);
166
167 case BuiltinType::SatUShortAccum:
168 return getTypeInfo(Context.SatShortAccumTy);
169 case BuiltinType::SatUAccum:
170 return getTypeInfo(Context.SatAccumTy);
171 case BuiltinType::SatULongAccum:
172 return getTypeInfo(Context.SatLongAccumTy);
173
174 // Treat all other builtin types as distinct types. This includes
175 // treating wchar_t, char16_t, and char32_t as distinct from their
176 // "underlying types".
177 default:
178 return createScalarTypeNode(BTy->getName(Features), getChar(), Size);
179 }
180 }
181
182 // C++1z [basic.lval]p10: "If a program attempts to access the stored value of
183 // an object through a glvalue of other than one of the following types the
184 // behavior is undefined: [...] a char, unsigned char, or std::byte type."
185 if (Ty->isStdByteType())
186 return getChar();
187
188 // Handle pointers and references.
189 //
190 // C has a very strict rule for pointer aliasing. C23 6.7.6.1p2:
191 // For two pointer types to be compatible, both shall be identically
192 // qualified and both shall be pointers to compatible types.
193 //
194 // This rule is impractically strict; we want to at least ignore CVR
195 // qualifiers. Distinguishing by CVR qualifiers would make it UB to
196 // e.g. cast a `char **` to `const char * const *` and dereference it,
197 // which is too common and useful to invalidate. C++'s similar types
198 // rule permits qualifier differences in these nested positions; in fact,
199 // C++ even allows that cast as an implicit conversion.
200 //
201 // Other qualifiers could theoretically be distinguished, especially if
202 // they involve a significant representation difference. We don't
203 // currently do so, however.
204 //
205 // Computing the pointee type string recursively is implicitly more
206 // forgiving than the standards require. Effectively, we are turning
207 // the question "are these types compatible/similar" into "are
208 // accesses to these types allowed to alias". In both C and C++,
209 // the latter question has special carve-outs for signedness
210 // mismatches that only apply at the top level. As a result, we are
211 // allowing e.g. `int *` l-values to access `unsigned *` objects.
212 if (Ty->isPointerType() || Ty->isReferenceType()) {
213 llvm::MDNode *AnyPtr = createScalarTypeNode("any pointer", getChar(), Size);
214 if (!CodeGenOpts.PointerTBAA)
215 return AnyPtr;
216 // Compute the depth of the pointer and generate a tag of the form "p<depth>
217 // <base type tag>".
218 unsigned PtrDepth = 0;
219 do {
220 PtrDepth++;
221 Ty = Ty->getPointeeType().getTypePtr();
222 } while (Ty->isPointerType());
223 // TODO: Implement C++'s type "similarity" and consider dis-"similar"
224 // pointers distinct for non-builtin types.
225 if (isa<BuiltinType>(Ty)) {
226 llvm::MDNode *ScalarMD = getTypeInfoHelper(Ty);
227 StringRef Name =
228 cast<llvm::MDString>(
229 ScalarMD->getOperand(CodeGenOpts.NewStructPathTBAA ? 2 : 0))
230 ->getString();
231 SmallString<256> OutName("p");
232 OutName += std::to_string(PtrDepth);
233 OutName += " ";
234 OutName += Name;
235 return createScalarTypeNode(OutName, AnyPtr, Size);
236 }
237 return AnyPtr;
238 }
239
240 // Accesses to arrays are accesses to objects of their element types.
241 if (CodeGenOpts.NewStructPathTBAA && Ty->isArrayType())
242 return getTypeInfo(cast<ArrayType>(Ty)->getElementType());
243
244 // Enum types are distinct types. In C++ they have "underlying types",
245 // however they aren't related for TBAA.
246 if (const EnumType *ETy = dyn_cast<EnumType>(Ty)) {
247 if (!Features.CPlusPlus)
248 return getTypeInfo(ETy->getDecl()->getIntegerType());
249
250 // In C++ mode, types have linkage, so we can rely on the ODR and
251 // on their mangled names, if they're external.
252 // TODO: Is there a way to get a program-wide unique name for a
253 // decl with local linkage or no linkage?
254 if (!ETy->getDecl()->isExternallyVisible())
255 return getChar();
256
257 SmallString<256> OutName;
258 llvm::raw_svector_ostream Out(OutName);
259 MContext.mangleCanonicalTypeName(QualType(ETy, 0), Out);
260 return createScalarTypeNode(OutName, getChar(), Size);
261 }
262
263 if (const auto *EIT = dyn_cast<BitIntType>(Ty)) {
264 SmallString<256> OutName;
265 llvm::raw_svector_ostream Out(OutName);
266 // Don't specify signed/unsigned since integer types can alias despite sign
267 // differences.
268 Out << "_BitInt(" << EIT->getNumBits() << ')';
269 return createScalarTypeNode(OutName, getChar(), Size);
270 }
271
272 // For now, handle any other kind of type conservatively.
273 return getChar();
274}
275
277 // At -O0 or relaxed aliasing, TBAA is not emitted for regular types.
278 if (CodeGenOpts.OptimizationLevel == 0 || CodeGenOpts.RelaxedAliasing)
279 return nullptr;
280
281 // If the type has the may_alias attribute (even on a typedef), it is
282 // effectively in the general char alias class.
283 if (TypeHasMayAlias(QTy))
284 return getChar();
285
286 // We need this function to not fall back to returning the "omnipotent char"
287 // type node for aggregate and union types. Otherwise, any dereference of an
288 // aggregate will result into the may-alias access descriptor, meaning all
289 // subsequent accesses to direct and indirect members of that aggregate will
290 // be considered may-alias too.
291 // TODO: Combine getTypeInfo() and getValidBaseTypeInfo() into a single
292 // function.
293 if (isValidBaseType(QTy))
294 return getValidBaseTypeInfo(QTy);
295
296 const Type *Ty = Context.getCanonicalType(QTy).getTypePtr();
297 if (llvm::MDNode *N = MetadataCache[Ty])
298 return N;
299
300 // Note that the following helper call is allowed to add new nodes to the
301 // cache, which invalidates all its previously obtained iterators. So we
302 // first generate the node for the type and then add that node to the cache.
303 llvm::MDNode *TypeNode = getTypeInfoHelper(Ty);
304 return MetadataCache[Ty] = TypeNode;
305}
306
308 // Pointee values may have incomplete types, but they shall never be
309 // dereferenced.
310 if (AccessType->isIncompleteType())
312
313 if (TypeHasMayAlias(AccessType))
315
316 uint64_t Size = Context.getTypeSizeInChars(AccessType).getQuantity();
317 return TBAAAccessInfo(getTypeInfo(AccessType), Size);
318}
319
321 llvm::DataLayout DL(&Module);
322 unsigned Size = DL.getPointerTypeSize(VTablePtrType);
323 return TBAAAccessInfo(createScalarTypeNode("vtable pointer", getRoot(), Size),
324 Size);
325}
326
327bool
328CodeGenTBAA::CollectFields(uint64_t BaseOffset,
329 QualType QTy,
331 Fields,
332 bool MayAlias) {
333 /* Things not handled yet include: C++ base classes, bitfields, */
334
335 if (const RecordType *TTy = QTy->getAs<RecordType>()) {
336 if (TTy->isUnionType()) {
337 uint64_t Size = Context.getTypeSizeInChars(QTy).getQuantity();
338 llvm::MDNode *TBAAType = getChar();
339 llvm::MDNode *TBAATag = getAccessTagInfo(TBAAAccessInfo(TBAAType, Size));
340 Fields.push_back(
341 llvm::MDBuilder::TBAAStructField(BaseOffset, Size, TBAATag));
342 return true;
343 }
344 const RecordDecl *RD = TTy->getDecl()->getDefinition();
345 if (RD->hasFlexibleArrayMember())
346 return false;
347
348 // TODO: Handle C++ base classes.
349 if (const CXXRecordDecl *Decl = dyn_cast<CXXRecordDecl>(RD))
350 if (Decl->bases_begin() != Decl->bases_end())
351 return false;
352
353 const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD);
354 const CGRecordLayout &CGRL = CGTypes.getCGRecordLayout(RD);
355
356 unsigned idx = 0;
357 for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end();
358 i != e; ++i, ++idx) {
359 if (isEmptyFieldForLayout(Context, *i))
360 continue;
361
362 uint64_t Offset =
363 BaseOffset + Layout.getFieldOffset(idx) / Context.getCharWidth();
364
365 // Create a single field for consecutive named bitfields using char as
366 // base type.
367 if ((*i)->isBitField()) {
368 const CGBitFieldInfo &Info = CGRL.getBitFieldInfo(*i);
369 // For big endian targets the first bitfield in the consecutive run is
370 // at the most-significant end; see CGRecordLowering::setBitFieldInfo
371 // for more information.
372 bool IsBE = Context.getTargetInfo().isBigEndian();
373 bool IsFirst = IsBE ? Info.StorageSize - (Info.Offset + Info.Size) == 0
374 : Info.Offset == 0;
375 if (!IsFirst)
376 continue;
377 unsigned CurrentBitFieldSize = Info.StorageSize;
378 uint64_t Size =
379 llvm::divideCeil(CurrentBitFieldSize, Context.getCharWidth());
380 llvm::MDNode *TBAAType = getChar();
381 llvm::MDNode *TBAATag =
382 getAccessTagInfo(TBAAAccessInfo(TBAAType, Size));
383 Fields.push_back(
384 llvm::MDBuilder::TBAAStructField(Offset, Size, TBAATag));
385 continue;
386 }
387
388 QualType FieldQTy = i->getType();
389 if (!CollectFields(Offset, FieldQTy, Fields,
390 MayAlias || TypeHasMayAlias(FieldQTy)))
391 return false;
392 }
393 return true;
394 }
395
396 /* Otherwise, treat whatever it is as a field. */
397 uint64_t Offset = BaseOffset;
399 llvm::MDNode *TBAAType = MayAlias ? getChar() : getTypeInfo(QTy);
400 llvm::MDNode *TBAATag = getAccessTagInfo(TBAAAccessInfo(TBAAType, Size));
401 Fields.push_back(llvm::MDBuilder::TBAAStructField(Offset, Size, TBAATag));
402 return true;
403}
404
405llvm::MDNode *
407 if (CodeGenOpts.OptimizationLevel == 0 || CodeGenOpts.RelaxedAliasing)
408 return nullptr;
409
410 const Type *Ty = Context.getCanonicalType(QTy).getTypePtr();
411
412 if (llvm::MDNode *N = StructMetadataCache[Ty])
413 return N;
414
416 if (CollectFields(0, QTy, Fields, TypeHasMayAlias(QTy)))
417 return MDHelper.createTBAAStructNode(Fields);
418
419 // For now, handle any other kind of type conservatively.
420 return StructMetadataCache[Ty] = nullptr;
421}
422
423llvm::MDNode *CodeGenTBAA::getBaseTypeInfoHelper(const Type *Ty) {
424 if (auto *TTy = dyn_cast<RecordType>(Ty)) {
425 const RecordDecl *RD = TTy->getDecl()->getDefinition();
426 const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD);
427 using TBAAStructField = llvm::MDBuilder::TBAAStructField;
429 if (const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
430 // Handle C++ base classes. Non-virtual bases can treated a kind of
431 // field. Virtual bases are more complex and omitted, but avoid an
432 // incomplete view for NewStructPathTBAA.
433 if (CodeGenOpts.NewStructPathTBAA && CXXRD->getNumVBases() != 0)
434 return nullptr;
435 for (const CXXBaseSpecifier &B : CXXRD->bases()) {
436 if (B.isVirtual())
437 continue;
438 QualType BaseQTy = B.getType();
439 const CXXRecordDecl *BaseRD = BaseQTy->getAsCXXRecordDecl();
440 if (BaseRD->isEmpty())
441 continue;
442 llvm::MDNode *TypeNode = isValidBaseType(BaseQTy)
443 ? getValidBaseTypeInfo(BaseQTy)
444 : getTypeInfo(BaseQTy);
445 if (!TypeNode)
446 return nullptr;
447 uint64_t Offset = Layout.getBaseClassOffset(BaseRD).getQuantity();
448 uint64_t Size =
449 Context.getASTRecordLayout(BaseRD).getDataSize().getQuantity();
450 Fields.push_back(
451 llvm::MDBuilder::TBAAStructField(Offset, Size, TypeNode));
452 }
453 // The order in which base class subobjects are allocated is unspecified,
454 // so may differ from declaration order. In particular, Itanium ABI will
455 // allocate a primary base first.
456 // Since we exclude empty subobjects, the objects are not overlapping and
457 // their offsets are unique.
458 llvm::sort(Fields,
459 [](const TBAAStructField &A, const TBAAStructField &B) {
460 return A.Offset < B.Offset;
461 });
462 }
463 for (FieldDecl *Field : RD->fields()) {
464 if (Field->isZeroSize(Context) || Field->isUnnamedBitField())
465 continue;
466 QualType FieldQTy = Field->getType();
467 llvm::MDNode *TypeNode = isValidBaseType(FieldQTy)
468 ? getValidBaseTypeInfo(FieldQTy)
469 : getTypeInfo(FieldQTy);
470 if (!TypeNode)
471 return nullptr;
472
473 uint64_t BitOffset = Layout.getFieldOffset(Field->getFieldIndex());
474 uint64_t Offset = Context.toCharUnitsFromBits(BitOffset).getQuantity();
475 uint64_t Size = Context.getTypeSizeInChars(FieldQTy).getQuantity();
476 Fields.push_back(llvm::MDBuilder::TBAAStructField(Offset, Size,
477 TypeNode));
478 }
479
480 SmallString<256> OutName;
481 if (Features.CPlusPlus) {
482 // Don't use the mangler for C code.
483 llvm::raw_svector_ostream Out(OutName);
484 MContext.mangleCanonicalTypeName(QualType(Ty, 0), Out);
485 } else {
486 OutName = RD->getName();
487 }
488
489 if (CodeGenOpts.NewStructPathTBAA) {
490 llvm::MDNode *Parent = getChar();
492 llvm::Metadata *Id = MDHelper.createString(OutName);
493 return MDHelper.createTBAATypeNode(Parent, Size, Id, Fields);
494 }
495
496 // Create the struct type node with a vector of pairs (offset, type).
498 for (const auto &Field : Fields)
499 OffsetsAndTypes.push_back(std::make_pair(Field.Type, Field.Offset));
500 return MDHelper.createTBAAStructTypeNode(OutName, OffsetsAndTypes);
501 }
502
503 return nullptr;
504}
505
506llvm::MDNode *CodeGenTBAA::getValidBaseTypeInfo(QualType QTy) {
507 assert(isValidBaseType(QTy) && "Must be a valid base type");
508
509 const Type *Ty = Context.getCanonicalType(QTy).getTypePtr();
510
511 // nullptr is a valid value in the cache, so use find rather than []
512 auto I = BaseTypeMetadataCache.find(Ty);
513 if (I != BaseTypeMetadataCache.end())
514 return I->second;
515
516 // First calculate the metadata, before recomputing the insertion point, as
517 // the helper can recursively call us.
518 llvm::MDNode *TypeNode = getBaseTypeInfoHelper(Ty);
519 LLVM_ATTRIBUTE_UNUSED auto inserted =
520 BaseTypeMetadataCache.insert({Ty, TypeNode});
521 assert(inserted.second && "BaseType metadata was already inserted");
522
523 return TypeNode;
524}
525
527 return isValidBaseType(QTy) ? getValidBaseTypeInfo(QTy) : nullptr;
528}
529
531 assert(!Info.isIncomplete() && "Access to an object of an incomplete type!");
532
533 if (Info.isMayAlias())
534 Info = TBAAAccessInfo(getChar(), Info.Size);
535
536 if (!Info.AccessType)
537 return nullptr;
538
539 if (!CodeGenOpts.StructPathTBAA)
540 Info = TBAAAccessInfo(Info.AccessType, Info.Size);
541
542 llvm::MDNode *&N = AccessTagMetadataCache[Info];
543 if (N)
544 return N;
545
546 if (!Info.BaseType) {
547 Info.BaseType = Info.AccessType;
548 assert(!Info.Offset && "Nonzero offset for an access with no base type!");
549 }
550 if (CodeGenOpts.NewStructPathTBAA) {
551 return N = MDHelper.createTBAAAccessTag(Info.BaseType, Info.AccessType,
552 Info.Offset, Info.Size);
553 }
554 return N = MDHelper.createTBAAStructTagNode(Info.BaseType, Info.AccessType,
555 Info.Offset);
556}
557
560 if (SourceInfo.isMayAlias() || TargetInfo.isMayAlias())
562 return TargetInfo;
563}
564
567 TBAAAccessInfo InfoB) {
568 if (InfoA == InfoB)
569 return InfoA;
570
571 if (!InfoA || !InfoB)
572 return TBAAAccessInfo();
573
574 if (InfoA.isMayAlias() || InfoB.isMayAlias())
576
577 // TODO: Implement the rest of the logic here. For example, two accesses
578 // with same final access types result in an access to an object of that final
579 // access type regardless of their base types.
581}
582
585 TBAAAccessInfo SrcInfo) {
586 if (DestInfo == SrcInfo)
587 return DestInfo;
588
589 if (!DestInfo || !SrcInfo)
590 return TBAAAccessInfo();
591
592 if (DestInfo.isMayAlias() || SrcInfo.isMayAlias())
594
595 // TODO: Implement the rest of the logic here. For example, two accesses
596 // with same final access types result in an access to an object of that final
597 // access type regardless of their base types.
599}
Defines the clang::ASTContext interface.
NodeId Parent
Definition: ASTDiff.cpp:191
static bool TypeHasMayAlias(QualType QTy)
Definition: CodeGenTBAA.cpp:83
static bool isValidBaseType(QualType QTy)
Check if the given type is a valid base type to be used in access tags.
uint32_t Id
Definition: SemaARM.cpp:1143
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:186
CanQualType AccumTy
Definition: ASTContext.h:1131
CanQualType LongTy
Definition: ASTContext.h:1127
CanQualType Int128Ty
Definition: ASTContext.h:1127
CanQualType SatAccumTy
Definition: ASTContext.h:1136
CanQualType ShortAccumTy
Definition: ASTContext.h:1131
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 ...
Definition: ASTContext.h:2625
CanQualType SatLongAccumTy
Definition: ASTContext.h:1136
CanQualType SatShortFractTy
Definition: ASTContext.h:1139
CanQualType ShortFractTy
Definition: ASTContext.h:1134
CanQualType IntTy
Definition: ASTContext.h:1127
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
CanQualType ShortTy
Definition: ASTContext.h:1127
CanQualType FractTy
Definition: ASTContext.h:1134
CanQualType LongAccumTy
Definition: ASTContext.h:1132
CanQualType SatFractTy
Definition: ASTContext.h:1139
CanQualType SatLongFractTy
Definition: ASTContext.h:1139
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:778
CanQualType LongFractTy
Definition: ASTContext.h:1134
CanQualType SatShortAccumTy
Definition: ASTContext.h:1136
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
CanQualType LongLongTy
Definition: ASTContext.h:1127
uint64_t getCharWidth() const
Return the size of the character type, in bits.
Definition: ASTContext.h:2395
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
Definition: RecordLayout.h:38
uint64_t getFieldOffset(unsigned FieldNo) const
getFieldOffset - Get the offset of the given field index, in bits.
Definition: RecordLayout.h:200
CharUnits getDataSize() const
getDataSize() - Get the record data size, which is the record size without tail padding,...
Definition: RecordLayout.h:206
CharUnits getBaseClassOffset(const CXXRecordDecl *Base) const
getBaseClassOffset - Get the offset, in chars, for the given base class.
Definition: RecordLayout.h:249
This class is used for builtin types like 'int'.
Definition: Type.h:3000
Represents a base class of a C++ class.
Definition: DeclCXX.h:146
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
bool isEmpty() const
Determine whether this is an empty class in the sense of (C++11 [meta.unary.prop]).
Definition: DeclCXX.h:1190
const T * getTypePtr() const
Retrieve the underlying type pointer, which refers to a canonical type.
Definition: CanonicalType.h:83
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
Definition: CharUnits.h:185
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
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, MangleContext &MContext)
Definition: CodeGenTBAA.cpp:37
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.
Definition: CodeGenTypes.h:54
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,...
Definition: DeclBase.h:2359
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
Definition: Type.h:5962
Represents a member of a struct/union/class.
Definition: Decl.h:3030
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:461
MangleContext - Context for tracking state which persists across multiple calls to the C++ name mangl...
Definition: Mangle.h:45
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.
Definition: Module.h:105
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:276
A (possibly-)qualified type.
Definition: Type.h:941
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:7743
Represents a struct/union/class.
Definition: Decl.h:4141
bool hasFlexibleArrayMember() const
Definition: Decl.h:4174
field_iterator field_end() const
Definition: Decl.h:4350
field_range fields() const
Definition: Decl.h:4347
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
Definition: Decl.h:4332
field_iterator field_begin() const
Definition: Decl.cpp:5057
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:5936
bool isStruct() const
Definition: Decl.h:3760
bool isClass() const
Definition: Decl.h:3762
Exposes information about the current target.
Definition: TargetInfo.h:218
bool isBigEndian() const
Definition: TargetInfo.h:1665
The base class of the type hierarchy.
Definition: Type.h:1829
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition: Type.cpp:1882
bool isArrayType() const
Definition: Type.h:8064
bool isPointerType() const
Definition: Type.h:7996
bool isReferenceType() const
Definition: Type.h:8010
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition: Type.cpp:705
bool isStdByteType() const
Definition: Type.cpp:3076
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
Definition: Type.cpp:2362
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:8516
TagDecl * getAsTagDecl() const
Retrieves the TagDecl that this type refers to, either because the type is a TagType or because it is...
Definition: Type.cpp:1890
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())))
unsigned long uint64_t
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.
Definition: CodeGenTBAA.h:105
uint64_t Offset
Offset - The byte offset of the final access within the base one.
Definition: CodeGenTBAA.h:109
static TBAAAccessInfo getMayAliasInfo()
Definition: CodeGenTBAA.h:63
uint64_t Size
Size - The size of access, in bytes.
Definition: CodeGenTBAA.h:112
static TBAAAccessInfo getIncompleteInfo()
Definition: CodeGenTBAA.h:71
llvm::MDNode * BaseType
BaseType - The base/leading access type.
Definition: CodeGenTBAA.h:101