blob: ab45d1f7f966019c21683b9c1f28b8022cc4ac42 [file] [log] [blame]
Dan Gohman947c9af2010-10-14 23:06:10 +00001//===--- CodeGenTypes.cpp - TBAA information for LLVM CodeGen -------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
Dan Gohman5419ce62010-10-21 18:49:12 +000010// This is the code that manages TBAA information and defines the TBAA policy
11// for the optimizer to use. Relevant standards text includes:
Dan Gohmanf47df3e2010-10-15 20:54:41 +000012//
13// C99 6.5p7
14// C++ [basic.lval] (p10 in n3126, p15 in some earlier versions)
Dan Gohman947c9af2010-10-14 23:06:10 +000015//
16//===----------------------------------------------------------------------===//
17
18#include "CodeGenTBAA.h"
19#include "clang/AST/ASTContext.h"
Benjamin Kramerea70eb32012-12-01 15:09:41 +000020#include "clang/AST/Attr.h"
Peter Collingbourne0ff0b372011-01-13 18:57:25 +000021#include "clang/AST/Mangle.h"
Benjamin Kramerea70eb32012-12-01 15:09:41 +000022#include "clang/AST/RecordLayout.h"
Saleem Abdulrasool10a49722016-04-08 16:52:00 +000023#include "clang/Frontend/CodeGenOptions.h"
Manman Renc451e572013-04-04 21:53:22 +000024#include "llvm/ADT/SmallSet.h"
Chandler Carruthffd55512013-01-02 11:45:17 +000025#include "llvm/IR/Constants.h"
26#include "llvm/IR/LLVMContext.h"
27#include "llvm/IR/Metadata.h"
Ivan A. Kosarev4e50e702017-11-27 09:39:29 +000028#include "llvm/IR/Module.h"
Chandler Carruthffd55512013-01-02 11:45:17 +000029#include "llvm/IR/Type.h"
Dan Gohman947c9af2010-10-14 23:06:10 +000030using namespace clang;
31using namespace CodeGen;
32
Ivan A. Kosarev4e50e702017-11-27 09:39:29 +000033CodeGenTBAA::CodeGenTBAA(ASTContext &Ctx, llvm::Module &M,
Kostya Serebryany5dd2cfc2012-04-24 06:57:01 +000034 const CodeGenOptions &CGO,
Dan Gohman2e29eb52010-10-15 20:23:12 +000035 const LangOptions &Features, MangleContext &MContext)
Ivan A. Kosarev4e50e702017-11-27 09:39:29 +000036 : Context(Ctx), Module(M), CodeGenOpts(CGO),
37 Features(Features), MContext(MContext), MDHelper(M.getContext()),
38 Root(nullptr), Char(nullptr)
39{}
Dan Gohman947c9af2010-10-14 23:06:10 +000040
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +000041CodeGenTBAA::~CodeGenTBAA() {
42}
Dan Gohman947c9af2010-10-14 23:06:10 +000043
Dan Gohman7dfd13c2010-10-25 21:48:30 +000044llvm::MDNode *CodeGenTBAA::getRoot() {
45 // Define the root of the tree. This identifies the tree, so that
46 // if our LLVM IR is linked with LLVM IR from a different front-end
47 // (or a different version of this front-end), their TBAA trees will
48 // remain distinct, and the optimizer will treat them conservatively.
Manman Ren37dec102016-02-11 19:19:18 +000049 if (!Root) {
50 if (Features.CPlusPlus)
51 Root = MDHelper.createTBAARoot("Simple C++ TBAA");
52 else
53 Root = MDHelper.createTBAARoot("Simple C/C++ TBAA");
54 }
Dan Gohman7dfd13c2010-10-25 21:48:30 +000055
56 return Root;
57}
58
Ivan A. Kosarev4e50e702017-11-27 09:39:29 +000059llvm::MDNode *CodeGenTBAA::createScalarTypeNode(StringRef Name,
60 llvm::MDNode *Parent,
61 uint64_t Size) {
Ivan A. Kosarevd50b8472017-12-22 09:54:23 +000062 if (CodeGenOpts.NewStructPathTBAA) {
63 llvm::Metadata *Id = MDHelper.createString(Name);
64 return MDHelper.createTBAATypeNode(Parent, Size, Id);
65 }
Manman Ren4f755de2013-10-08 00:08:49 +000066 return MDHelper.createTBAAScalarTypeNode(Name, Parent);
Manman Rene1ad74e2013-04-11 23:02:56 +000067}
68
Dan Gohman7dfd13c2010-10-25 21:48:30 +000069llvm::MDNode *CodeGenTBAA::getChar() {
70 // Define the root of the tree for user-accessible memory. C and C++
71 // give special powers to char and certain similar types. However,
72 // these special powers only cover user-accessible memory, and doesn't
73 // include things like vtables.
74 if (!Char)
Ivan A. Kosarev4e50e702017-11-27 09:39:29 +000075 Char = createScalarTypeNode("omnipotent char", getRoot(), /* Size= */ 1);
Dan Gohman7dfd13c2010-10-25 21:48:30 +000076
77 return Char;
78}
79
Dan Gohmanc2897692010-12-13 23:51:08 +000080static bool TypeHasMayAlias(QualType QTy) {
81 // Tagged types have declarations, and therefore may have attributes.
82 if (const TagType *TTy = dyn_cast<TagType>(QTy))
83 return TTy->getDecl()->hasAttr<MayAliasAttr>();
84
85 // Typedef types have declarations, and therefore may have attributes.
86 if (const TypedefType *TTy = dyn_cast<TypedefType>(QTy)) {
87 if (TTy->getDecl()->hasAttr<MayAliasAttr>())
88 return true;
89 // Also, their underlying types may have relevant attributes.
90 return TypeHasMayAlias(TTy->desugar());
91 }
92
93 return false;
94}
95
Ivan A. Kosarevb9c59f32017-10-31 11:05:34 +000096/// Check if the given type is a valid base type to be used in access tags.
97static bool isValidBaseType(QualType QTy) {
98 if (QTy->isReferenceType())
99 return false;
100 if (const RecordType *TTy = QTy->getAs<RecordType>()) {
101 const RecordDecl *RD = TTy->getDecl()->getDefinition();
102 // Incomplete types are not valid base access types.
103 if (!RD)
104 return false;
105 if (RD->hasFlexibleArrayMember())
106 return false;
Hal Finkela5986b92017-12-03 03:10:13 +0000107 // RD can be struct, union, class, interface or enum.
108 // For now, we only handle struct and class.
109 if (RD->isStruct() || RD->isClass())
Ivan A. Kosarevb9c59f32017-10-31 11:05:34 +0000110 return true;
111 }
112 return false;
113}
114
Ivan A. Kosarev5d9d32e2017-11-21 11:18:06 +0000115llvm::MDNode *CodeGenTBAA::getTypeInfoHelper(const Type *Ty) {
Ivan A. Kosarev4e50e702017-11-27 09:39:29 +0000116 uint64_t Size = Context.getTypeSizeInChars(Ty).getQuantity();
117
Dan Gohman5419ce62010-10-21 18:49:12 +0000118 // Handle builtin types.
Dan Gohman3f1cf0f2010-10-14 23:39:00 +0000119 if (const BuiltinType *BTy = dyn_cast<BuiltinType>(Ty)) {
Dan Gohman947c9af2010-10-14 23:06:10 +0000120 switch (BTy->getKind()) {
Dan Gohmanf5c5e072010-10-15 17:52:03 +0000121 // Character types are special and can alias anything.
122 // In C++, this technically only includes "char" and "unsigned char",
123 // and not "signed char". In C, it includes all three. For now,
Dan Gohman4a3b1b32010-10-15 20:24:10 +0000124 // the risk of exploiting this detail in C++ seems likely to outweigh
Dan Gohmanf5c5e072010-10-15 17:52:03 +0000125 // the benefit.
Dan Gohman947c9af2010-10-14 23:06:10 +0000126 case BuiltinType::Char_U:
127 case BuiltinType::Char_S:
128 case BuiltinType::UChar:
129 case BuiltinType::SChar:
Dan Gohman7dfd13c2010-10-25 21:48:30 +0000130 return getChar();
Dan Gohman3f1cf0f2010-10-14 23:39:00 +0000131
132 // Unsigned types can alias their corresponding signed types.
133 case BuiltinType::UShort:
Ivan A. Kosarev289574e2017-10-02 09:54:47 +0000134 return getTypeInfo(Context.ShortTy);
Dan Gohman3f1cf0f2010-10-14 23:39:00 +0000135 case BuiltinType::UInt:
Ivan A. Kosarev289574e2017-10-02 09:54:47 +0000136 return getTypeInfo(Context.IntTy);
Dan Gohman3f1cf0f2010-10-14 23:39:00 +0000137 case BuiltinType::ULong:
Ivan A. Kosarev289574e2017-10-02 09:54:47 +0000138 return getTypeInfo(Context.LongTy);
Dan Gohman3f1cf0f2010-10-14 23:39:00 +0000139 case BuiltinType::ULongLong:
Ivan A. Kosarev289574e2017-10-02 09:54:47 +0000140 return getTypeInfo(Context.LongLongTy);
Dan Gohman3f1cf0f2010-10-14 23:39:00 +0000141 case BuiltinType::UInt128:
Ivan A. Kosarev289574e2017-10-02 09:54:47 +0000142 return getTypeInfo(Context.Int128Ty);
Dan Gohman3f1cf0f2010-10-14 23:39:00 +0000143
Dan Gohman2d0a3c72010-10-15 20:24:53 +0000144 // Treat all other builtin types as distinct types. This includes
145 // treating wchar_t, char16_t, and char32_t as distinct from their
146 // "underlying types".
Dan Gohman947c9af2010-10-14 23:06:10 +0000147 default:
Ivan A. Kosarev4e50e702017-11-27 09:39:29 +0000148 return createScalarTypeNode(BTy->getName(Features), getChar(), Size);
Dan Gohman947c9af2010-10-14 23:06:10 +0000149 }
150 }
151
David Majnemer8f94a232017-07-25 23:33:58 +0000152 // C++1z [basic.lval]p10: "If a program attempts to access the stored value of
153 // an object through a glvalue of other than one of the following types the
154 // behavior is undefined: [...] a char, unsigned char, or std::byte type."
155 if (Ty->isStdByteType())
Ivan A. Kosarev5d9d32e2017-11-21 11:18:06 +0000156 return getChar();
David Majnemer8f94a232017-07-25 23:33:58 +0000157
Ivan A. Kosarevb75a50b2017-09-26 14:22:48 +0000158 // Handle pointers and references.
Dan Gohmanc44fd642010-10-15 20:26:20 +0000159 // TODO: Implement C++'s type "similarity" and consider dis-"similar"
160 // pointers distinct.
Ivan A. Kosarevb75a50b2017-09-26 14:22:48 +0000161 if (Ty->isPointerType() || Ty->isReferenceType())
Ivan A. Kosarev4e50e702017-11-27 09:39:29 +0000162 return createScalarTypeNode("any pointer", getChar(), Size);
Dan Gohmand65c1962010-10-15 00:01:39 +0000163
Dan Gohman2e29eb52010-10-15 20:23:12 +0000164 // Enum types are distinct types. In C++ they have "underlying types",
165 // however they aren't related for TBAA.
166 if (const EnumType *ETy = dyn_cast<EnumType>(Ty)) {
Dan Gohman2e29eb52010-10-15 20:23:12 +0000167 // In C++ mode, types have linkage, so we can rely on the ODR and
168 // on their mangled names, if they're external.
169 // TODO: Is there a way to get a program-wide unique name for a
170 // decl with local linkage or no linkage?
Eli Friedmaneecc09a2013-07-05 20:27:40 +0000171 if (!Features.CPlusPlus || !ETy->getDecl()->isExternallyVisible())
Ivan A. Kosarev5d9d32e2017-11-21 11:18:06 +0000172 return getChar();
Dan Gohman2e29eb52010-10-15 20:23:12 +0000173
Dylan Noblesmith2c1dd272012-02-05 02:13:05 +0000174 SmallString<256> OutName;
Rafael Espindola3968cd02011-02-11 02:52:17 +0000175 llvm::raw_svector_ostream Out(OutName);
Reid Klecknercc99e262013-11-19 23:23:00 +0000176 MContext.mangleTypeName(QualType(ETy, 0), Out);
Ivan A. Kosarev4e50e702017-11-27 09:39:29 +0000177 return createScalarTypeNode(OutName, getChar(), Size);
Dan Gohman2e29eb52010-10-15 20:23:12 +0000178 }
179
Dan Gohman3f1cf0f2010-10-14 23:39:00 +0000180 // For now, handle any other kind of type conservatively.
Ivan A. Kosarev5d9d32e2017-11-21 11:18:06 +0000181 return getChar();
182}
183
184llvm::MDNode *CodeGenTBAA::getTypeInfo(QualType QTy) {
185 // At -O0 or relaxed aliasing, TBAA is not emitted for regular types.
186 if (CodeGenOpts.OptimizationLevel == 0 || CodeGenOpts.RelaxedAliasing)
187 return nullptr;
188
189 // If the type has the may_alias attribute (even on a typedef), it is
190 // effectively in the general char alias class.
191 if (TypeHasMayAlias(QTy))
192 return getChar();
193
194 // We need this function to not fall back to returning the "omnipotent char"
195 // type node for aggregate and union types. Otherwise, any dereference of an
196 // aggregate will result into the may-alias access descriptor, meaning all
197 // subsequent accesses to direct and indirect members of that aggregate will
198 // be considered may-alias too.
199 // TODO: Combine getTypeInfo() and getBaseTypeInfo() into a single function.
200 if (isValidBaseType(QTy))
201 return getBaseTypeInfo(QTy);
202
203 const Type *Ty = Context.getCanonicalType(QTy).getTypePtr();
204 if (llvm::MDNode *N = MetadataCache[Ty])
205 return N;
206
207 // Note that the following helper call is allowed to add new nodes to the
208 // cache, which invalidates all its previously obtained iterators. So we
209 // first generate the node for the type and then add that node to the cache.
210 llvm::MDNode *TypeNode = getTypeInfoHelper(Ty);
211 return MetadataCache[Ty] = TypeNode;
Dan Gohman947c9af2010-10-14 23:06:10 +0000212}
Kostya Serebryany141e46f2012-03-26 17:03:51 +0000213
Ivan A. Kosarev4e50e702017-11-27 09:39:29 +0000214TBAAAccessInfo CodeGenTBAA::getVTablePtrAccessInfo(llvm::Type *VTablePtrType) {
215 llvm::DataLayout DL(&Module);
216 unsigned Size = DL.getPointerTypeSize(VTablePtrType);
217 return TBAAAccessInfo(createScalarTypeNode("vtable pointer", getRoot(), Size),
218 Size);
Kostya Serebryany141e46f2012-03-26 17:03:51 +0000219}
Dan Gohman22695fc2012-09-28 21:58:29 +0000220
221bool
222CodeGenTBAA::CollectFields(uint64_t BaseOffset,
223 QualType QTy,
224 SmallVectorImpl<llvm::MDBuilder::TBAAStructField> &
225 Fields,
226 bool MayAlias) {
227 /* Things not handled yet include: C++ base classes, bitfields, */
228
229 if (const RecordType *TTy = QTy->getAs<RecordType>()) {
230 const RecordDecl *RD = TTy->getDecl()->getDefinition();
231 if (RD->hasFlexibleArrayMember())
232 return false;
233
234 // TODO: Handle C++ base classes.
235 if (const CXXRecordDecl *Decl = dyn_cast<CXXRecordDecl>(RD))
236 if (Decl->bases_begin() != Decl->bases_end())
237 return false;
238
239 const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD);
240
241 unsigned idx = 0;
242 for (RecordDecl::field_iterator i = RD->field_begin(),
243 e = RD->field_end(); i != e; ++i, ++idx) {
244 uint64_t Offset = BaseOffset +
245 Layout.getFieldOffset(idx) / Context.getCharWidth();
246 QualType FieldQTy = i->getType();
247 if (!CollectFields(Offset, FieldQTy, Fields,
248 MayAlias || TypeHasMayAlias(FieldQTy)))
249 return false;
250 }
251 return true;
252 }
253
254 /* Otherwise, treat whatever it is as a field. */
255 uint64_t Offset = BaseOffset;
256 uint64_t Size = Context.getTypeSizeInChars(QTy).getQuantity();
Ivan A. Kosarev3d68ce92017-10-05 11:08:17 +0000257 llvm::MDNode *TBAAType = MayAlias ? getChar() : getTypeInfo(QTy);
Ivan A. Kosarev4e50e702017-11-27 09:39:29 +0000258 llvm::MDNode *TBAATag = getAccessTagInfo(TBAAAccessInfo(TBAAType, Size));
Manman Ren09a39122013-04-22 19:50:07 +0000259 Fields.push_back(llvm::MDBuilder::TBAAStructField(Offset, Size, TBAATag));
Dan Gohman22695fc2012-09-28 21:58:29 +0000260 return true;
261}
262
263llvm::MDNode *
264CodeGenTBAA::getTBAAStructInfo(QualType QTy) {
265 const Type *Ty = Context.getCanonicalType(QTy).getTypePtr();
266
267 if (llvm::MDNode *N = StructMetadataCache[Ty])
268 return N;
269
270 SmallVector<llvm::MDBuilder::TBAAStructField, 4> Fields;
271 if (CollectFields(0, QTy, Fields, TypeHasMayAlias(QTy)))
272 return MDHelper.createTBAAStructNode(Fields);
273
274 // For now, handle any other kind of type conservatively.
Craig Topper8a13c412014-05-21 05:09:00 +0000275 return StructMetadataCache[Ty] = nullptr;
Dan Gohman22695fc2012-09-28 21:58:29 +0000276}
Manman Renc451e572013-04-04 21:53:22 +0000277
Ivan A. Kosarev5d9d32e2017-11-21 11:18:06 +0000278llvm::MDNode *CodeGenTBAA::getBaseTypeInfoHelper(const Type *Ty) {
279 if (auto *TTy = dyn_cast<RecordType>(Ty)) {
Manman Renc451e572013-04-04 21:53:22 +0000280 const RecordDecl *RD = TTy->getDecl()->getDefinition();
Manman Renc451e572013-04-04 21:53:22 +0000281 const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD);
Ivan A. Kosarev4e50e702017-11-27 09:39:29 +0000282 SmallVector<llvm::MDBuilder::TBAAStructField, 4> Fields;
Hal Finkela5986b92017-12-03 03:10:13 +0000283 for (FieldDecl *Field : RD->fields()) {
284 QualType FieldQTy = Field->getType();
285 llvm::MDNode *TypeNode = isValidBaseType(FieldQTy) ?
286 getBaseTypeInfo(FieldQTy) : getTypeInfo(FieldQTy);
287 if (!TypeNode)
288 return BaseTypeMetadataCache[Ty] = nullptr;
Ivan A. Kosarevda342472017-11-30 09:26:39 +0000289
Hal Finkela5986b92017-12-03 03:10:13 +0000290 uint64_t BitOffset = Layout.getFieldOffset(Field->getFieldIndex());
291 uint64_t Offset = Context.toCharUnitsFromBits(BitOffset).getQuantity();
292 uint64_t Size = Context.getTypeSizeInChars(FieldQTy).getQuantity();
293 Fields.push_back(llvm::MDBuilder::TBAAStructField(Offset, Size,
294 TypeNode));
Manman Renc451e572013-04-04 21:53:22 +0000295 }
296
Manman Renc451e572013-04-04 21:53:22 +0000297 SmallString<256> OutName;
Manman Ren879ce882013-08-21 20:58:45 +0000298 if (Features.CPlusPlus) {
Reid Klecknercc99e262013-11-19 23:23:00 +0000299 // Don't use the mangler for C code.
Manman Ren879ce882013-08-21 20:58:45 +0000300 llvm::raw_svector_ostream Out(OutName);
Reid Klecknercc99e262013-11-19 23:23:00 +0000301 MContext.mangleTypeName(QualType(Ty, 0), Out);
Manman Ren879ce882013-08-21 20:58:45 +0000302 } else {
303 OutName = RD->getName();
304 }
Ivan A. Kosarev4e50e702017-11-27 09:39:29 +0000305
Ivan A. Kosarevd50b8472017-12-22 09:54:23 +0000306 if (CodeGenOpts.NewStructPathTBAA) {
307 llvm::MDNode *Parent = getChar();
308 uint64_t Size = Context.getTypeSizeInChars(Ty).getQuantity();
309 llvm::Metadata *Id = MDHelper.createString(OutName);
310 return MDHelper.createTBAATypeNode(Parent, Size, Id, Fields);
311 }
Ivan A. Kosarev4e50e702017-11-27 09:39:29 +0000312
Manman Renc451e572013-04-04 21:53:22 +0000313 // Create the struct type node with a vector of pairs (offset, type).
Ivan A. Kosarev4e50e702017-11-27 09:39:29 +0000314 SmallVector<std::pair<llvm::MDNode*, uint64_t>, 4> OffsetsAndTypes;
315 for (const auto &Field : Fields)
Ivan A. Kosareve814f322017-12-18 16:50:11 +0000316 OffsetsAndTypes.push_back(std::make_pair(Field.Type, Field.Offset));
Ivan A. Kosarev4e50e702017-11-27 09:39:29 +0000317 return MDHelper.createTBAAStructTypeNode(OutName, OffsetsAndTypes);
Manman Renc451e572013-04-04 21:53:22 +0000318 }
319
Ivan A. Kosarev5d9d32e2017-11-21 11:18:06 +0000320 return nullptr;
321}
322
323llvm::MDNode *CodeGenTBAA::getBaseTypeInfo(QualType QTy) {
324 if (!isValidBaseType(QTy))
325 return nullptr;
326
327 const Type *Ty = Context.getCanonicalType(QTy).getTypePtr();
328 if (llvm::MDNode *N = BaseTypeMetadataCache[Ty])
329 return N;
330
331 // Note that the following helper call is allowed to add new nodes to the
332 // cache, which invalidates all its previously obtained iterators. So we
333 // first generate the node for the type and then add that node to the cache.
334 llvm::MDNode *TypeNode = getBaseTypeInfoHelper(Ty);
335 return BaseTypeMetadataCache[Ty] = TypeNode;
Manman Renc451e572013-04-04 21:53:22 +0000336}
337
Ivan A. Kosarev3d68ce92017-10-05 11:08:17 +0000338llvm::MDNode *CodeGenTBAA::getAccessTagInfo(TBAAAccessInfo Info) {
Ivan A. Kosarev4e50e702017-11-27 09:39:29 +0000339 assert(!Info.isIncomplete() && "Access to an object of an incomplete type!");
340
Ivan A. Kosarevb9c59f32017-10-31 11:05:34 +0000341 if (Info.isMayAlias())
Ivan A. Kosarev4e50e702017-11-27 09:39:29 +0000342 Info = TBAAAccessInfo(getChar(), Info.Size);
Ivan A. Kosarevb9c59f32017-10-31 11:05:34 +0000343
Ivan A. Kosareva511ed72017-10-03 10:52:39 +0000344 if (!Info.AccessType)
Craig Topper8a13c412014-05-21 05:09:00 +0000345 return nullptr;
Manman Ren4f755de2013-10-08 00:08:49 +0000346
Manman Renc451e572013-04-04 21:53:22 +0000347 if (!CodeGenOpts.StructPathTBAA)
Ivan A. Kosarev4e50e702017-11-27 09:39:29 +0000348 Info = TBAAAccessInfo(Info.AccessType, Info.Size);
Manman Renc451e572013-04-04 21:53:22 +0000349
Ivan A. Kosarev383890b2017-10-06 08:17:48 +0000350 llvm::MDNode *&N = AccessTagMetadataCache[Info];
351 if (N)
Manman Renc451e572013-04-04 21:53:22 +0000352 return N;
353
Ivan A. Kosarev383890b2017-10-06 08:17:48 +0000354 if (!Info.BaseType) {
355 Info.BaseType = Info.AccessType;
356 assert(!Info.Offset && "Nonzero offset for an access with no base type!");
357 }
Ivan A. Kosarevd50b8472017-12-22 09:54:23 +0000358 if (CodeGenOpts.NewStructPathTBAA) {
359 return N = MDHelper.createTBAAAccessTag(Info.BaseType, Info.AccessType,
360 Info.Offset, Info.Size);
361 }
Ivan A. Kosarev383890b2017-10-06 08:17:48 +0000362 return N = MDHelper.createTBAAStructTagNode(Info.BaseType, Info.AccessType,
363 Info.Offset);
Manman Renc451e572013-04-04 21:53:22 +0000364}
Manman Rene1ad74e2013-04-11 23:02:56 +0000365
Ivan A. Kosareved141ba2017-10-17 09:12:13 +0000366TBAAAccessInfo CodeGenTBAA::mergeTBAAInfoForCast(TBAAAccessInfo SourceInfo,
367 TBAAAccessInfo TargetInfo) {
Ivan A. Kosarevb9c59f32017-10-31 11:05:34 +0000368 if (SourceInfo.isMayAlias() || TargetInfo.isMayAlias())
369 return TBAAAccessInfo::getMayAliasInfo();
Ivan A. Kosareved141ba2017-10-17 09:12:13 +0000370 return TargetInfo;
371}
Ivan A. Kosarevb9c59f32017-10-31 11:05:34 +0000372
373TBAAAccessInfo
374CodeGenTBAA::mergeTBAAInfoForConditionalOperator(TBAAAccessInfo InfoA,
375 TBAAAccessInfo InfoB) {
376 if (InfoA == InfoB)
377 return InfoA;
378
379 if (!InfoA || !InfoB)
380 return TBAAAccessInfo();
381
382 if (InfoA.isMayAlias() || InfoB.isMayAlias())
383 return TBAAAccessInfo::getMayAliasInfo();
384
385 // TODO: Implement the rest of the logic here. For example, two accesses
386 // with same final access types result in an access to an object of that final
387 // access type regardless of their base types.
388 return TBAAAccessInfo::getMayAliasInfo();
389}