Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1 | //===--- CodeGenTypes.cpp - Type translation for LLVM CodeGen -------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 10 | // This is the code that handles AST -> LLVM type lowering. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "CodeGenTypes.h" |
John McCall | f16aa10 | 2010-08-22 21:01:12 +0000 | [diff] [blame] | 15 | #include "CGCXXABI.h" |
Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 16 | #include "CGCall.h" |
Guy Benyei | b13621d | 2012-12-18 14:38:23 +0000 | [diff] [blame] | 17 | #include "CGOpenCLRuntime.h" |
Daniel Dunbar | 2924ade | 2010-03-30 22:26:10 +0000 | [diff] [blame] | 18 | #include "CGRecordLayout.h" |
John McCall | de5d3c7 | 2012-02-17 03:33:10 +0000 | [diff] [blame] | 19 | #include "TargetInfo.h" |
Daniel Dunbar | de7fb84 | 2008-08-11 05:00:27 +0000 | [diff] [blame] | 20 | #include "clang/AST/ASTContext.h" |
Fariborz Jahanian | 742cd1b | 2009-07-25 21:12:28 +0000 | [diff] [blame] | 21 | #include "clang/AST/DeclCXX.h" |
Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 22 | #include "clang/AST/DeclObjC.h" |
Daniel Dunbar | de7fb84 | 2008-08-11 05:00:27 +0000 | [diff] [blame] | 23 | #include "clang/AST/Expr.h" |
Anders Carlsson | 19cc4ab | 2009-07-18 19:43:29 +0000 | [diff] [blame] | 24 | #include "clang/AST/RecordLayout.h" |
Mark Lacey | 8b54999 | 2013-10-30 21:53:58 +0000 | [diff] [blame] | 25 | #include "clang/CodeGen/CGFunctionInfo.h" |
Chandler Carruth | 3b844ba | 2013-01-02 11:45:17 +0000 | [diff] [blame] | 26 | #include "llvm/IR/DataLayout.h" |
| 27 | #include "llvm/IR/DerivedTypes.h" |
| 28 | #include "llvm/IR/Module.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 29 | using namespace clang; |
| 30 | using namespace CodeGen; |
| 31 | |
John McCall | 64aa4b3 | 2013-04-16 22:48:15 +0000 | [diff] [blame] | 32 | CodeGenTypes::CodeGenTypes(CodeGenModule &cgm) |
| 33 | : CGM(cgm), Context(cgm.getContext()), TheModule(cgm.getModule()), |
John McCall | 64aa4b3 | 2013-04-16 22:48:15 +0000 | [diff] [blame] | 34 | Target(cgm.getTarget()), TheCXXABI(cgm.getCXXABI()), |
John McCall | 64aa4b3 | 2013-04-16 22:48:15 +0000 | [diff] [blame] | 35 | TheABIInfo(cgm.getTargetCodeGenInfo().getABIInfo()) { |
Chris Lattner | 57eb23f | 2011-07-10 05:39:13 +0000 | [diff] [blame] | 36 | SkippedLayout = false; |
Chris Lattner | d2d2a11 | 2007-07-14 01:29:45 +0000 | [diff] [blame] | 37 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 38 | |
Devang Patel | b84a06e | 2007-10-23 02:10:49 +0000 | [diff] [blame] | 39 | CodeGenTypes::~CodeGenTypes() { |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 40 | llvm::DeleteContainerSeconds(CGRecordLayouts); |
Chris Lattner | 6f41c17 | 2010-01-11 19:58:10 +0000 | [diff] [blame] | 41 | |
| 42 | for (llvm::FoldingSet<CGFunctionInfo>::iterator |
| 43 | I = FunctionInfos.begin(), E = FunctionInfos.end(); I != E; ) |
| 44 | delete &*I++; |
Devang Patel | b84a06e | 2007-10-23 02:10:49 +0000 | [diff] [blame] | 45 | } |
| 46 | |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 47 | void CodeGenTypes::addRecordTypeName(const RecordDecl *RD, |
| 48 | llvm::StructType *Ty, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 49 | StringRef suffix) { |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 50 | SmallString<256> TypeName; |
Anders Carlsson | e9742b0 | 2011-04-17 21:36:59 +0000 | [diff] [blame] | 51 | llvm::raw_svector_ostream OS(TypeName); |
Anders Carlsson | e0047b1 | 2011-04-20 23:51:43 +0000 | [diff] [blame] | 52 | OS << RD->getKindName() << '.'; |
Anders Carlsson | e9742b0 | 2011-04-17 21:36:59 +0000 | [diff] [blame] | 53 | |
| 54 | // Name the codegen type after the typedef name |
| 55 | // if there is no tag type name available |
Anders Carlsson | e0047b1 | 2011-04-20 23:51:43 +0000 | [diff] [blame] | 56 | if (RD->getIdentifier()) { |
Anders Carlsson | e9742b0 | 2011-04-17 21:36:59 +0000 | [diff] [blame] | 57 | // FIXME: We should not have to check for a null decl context here. |
| 58 | // Right now we do it because the implicit Obj-C decls don't have one. |
Anders Carlsson | e0047b1 | 2011-04-20 23:51:43 +0000 | [diff] [blame] | 59 | if (RD->getDeclContext()) |
Benjamin Kramer | b063ef0 | 2013-02-23 13:53:57 +0000 | [diff] [blame] | 60 | RD->printQualifiedName(OS); |
Anders Carlsson | e9742b0 | 2011-04-17 21:36:59 +0000 | [diff] [blame] | 61 | else |
Anders Carlsson | e0047b1 | 2011-04-20 23:51:43 +0000 | [diff] [blame] | 62 | RD->printName(OS); |
| 63 | } else if (const TypedefNameDecl *TDD = RD->getTypedefNameForAnonDecl()) { |
Anders Carlsson | e9742b0 | 2011-04-17 21:36:59 +0000 | [diff] [blame] | 64 | // FIXME: We should not have to check for a null decl context here. |
| 65 | // Right now we do it because the implicit Obj-C decls don't have one. |
| 66 | if (TDD->getDeclContext()) |
Benjamin Kramer | b063ef0 | 2013-02-23 13:53:57 +0000 | [diff] [blame] | 67 | TDD->printQualifiedName(OS); |
Anders Carlsson | e9742b0 | 2011-04-17 21:36:59 +0000 | [diff] [blame] | 68 | else |
| 69 | TDD->printName(OS); |
| 70 | } else |
| 71 | OS << "anon"; |
| 72 | |
| 73 | if (!suffix.empty()) |
| 74 | OS << suffix; |
| 75 | |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 76 | Ty->setName(OS.str()); |
Devang Patel | 30ec997 | 2007-10-25 18:32:36 +0000 | [diff] [blame] | 77 | } |
| 78 | |
Chris Lattner | 4581fff | 2008-02-06 05:21:55 +0000 | [diff] [blame] | 79 | /// ConvertTypeForMem - Convert type T into a llvm::Type. This differs from |
| 80 | /// ConvertType in that it is used to convert to the memory representation for |
| 81 | /// a type. For example, the scalar representation for _Bool is i1, but the |
| 82 | /// memory representation is usually i8 or i32, depending on the target. |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 83 | llvm::Type *CodeGenTypes::ConvertTypeForMem(QualType T) { |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 84 | llvm::Type *R = ConvertType(T); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 85 | |
Chris Lattner | 19009e6 | 2008-01-09 18:47:25 +0000 | [diff] [blame] | 86 | // If this is a non-bool type, don't map it. |
Duncan Sands | f177d9d | 2010-02-15 16:14:01 +0000 | [diff] [blame] | 87 | if (!R->isIntegerTy(1)) |
Chris Lattner | 19009e6 | 2008-01-09 18:47:25 +0000 | [diff] [blame] | 88 | return R; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 89 | |
Chris Lattner | 19009e6 | 2008-01-09 18:47:25 +0000 | [diff] [blame] | 90 | // Otherwise, return an integer of the target-specified size. |
Owen Anderson | 0032b27 | 2009-08-13 21:57:51 +0000 | [diff] [blame] | 91 | return llvm::IntegerType::get(getLLVMContext(), |
| 92 | (unsigned)Context.getTypeSize(T)); |
Chris Lattner | 19009e6 | 2008-01-09 18:47:25 +0000 | [diff] [blame] | 93 | } |
| 94 | |
Chris Lattner | 71305cc | 2011-07-15 05:16:14 +0000 | [diff] [blame] | 95 | |
| 96 | /// isRecordLayoutComplete - Return true if the specified type is already |
| 97 | /// completely laid out. |
| 98 | bool CodeGenTypes::isRecordLayoutComplete(const Type *Ty) const { |
| 99 | llvm::DenseMap<const Type*, llvm::StructType *>::const_iterator I = |
| 100 | RecordDeclTypes.find(Ty); |
| 101 | return I != RecordDeclTypes.end() && !I->second->isOpaque(); |
| 102 | } |
| 103 | |
| 104 | static bool |
| 105 | isSafeToConvert(QualType T, CodeGenTypes &CGT, |
| 106 | llvm::SmallPtrSet<const RecordDecl*, 16> &AlreadyChecked); |
| 107 | |
| 108 | |
| 109 | /// isSafeToConvert - Return true if it is safe to convert the specified record |
| 110 | /// decl to IR and lay it out, false if doing so would cause us to get into a |
| 111 | /// recursive compilation mess. |
| 112 | static bool |
| 113 | isSafeToConvert(const RecordDecl *RD, CodeGenTypes &CGT, |
| 114 | llvm::SmallPtrSet<const RecordDecl*, 16> &AlreadyChecked) { |
| 115 | // If we have already checked this type (maybe the same type is used by-value |
| 116 | // multiple times in multiple structure fields, don't check again. |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 117 | if (!AlreadyChecked.insert(RD).second) |
| 118 | return true; |
| 119 | |
Chris Lattner | 71305cc | 2011-07-15 05:16:14 +0000 | [diff] [blame] | 120 | const Type *Key = CGT.getContext().getTagDeclType(RD).getTypePtr(); |
| 121 | |
| 122 | // If this type is already laid out, converting it is a noop. |
| 123 | if (CGT.isRecordLayoutComplete(Key)) return true; |
| 124 | |
| 125 | // If this type is currently being laid out, we can't recursively compile it. |
| 126 | if (CGT.isRecordBeingLaidOut(Key)) |
| 127 | return false; |
| 128 | |
| 129 | // If this type would require laying out bases that are currently being laid |
| 130 | // out, don't do it. This includes virtual base classes which get laid out |
| 131 | // when a class is translated, even though they aren't embedded by-value into |
| 132 | // the class. |
| 133 | if (const CXXRecordDecl *CRD = dyn_cast<CXXRecordDecl>(RD)) { |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 134 | for (const auto &I : CRD->bases()) |
| 135 | if (!isSafeToConvert(I.getType()->getAs<RecordType>()->getDecl(), |
Chris Lattner | 71305cc | 2011-07-15 05:16:14 +0000 | [diff] [blame] | 136 | CGT, AlreadyChecked)) |
| 137 | return false; |
| 138 | } |
| 139 | |
| 140 | // If this type would require laying out members that are currently being laid |
| 141 | // out, don't do it. |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 142 | for (const auto *I : RD->fields()) |
Chris Lattner | 71305cc | 2011-07-15 05:16:14 +0000 | [diff] [blame] | 143 | if (!isSafeToConvert(I->getType(), CGT, AlreadyChecked)) |
| 144 | return false; |
| 145 | |
| 146 | // If there are no problems, lets do it. |
| 147 | return true; |
| 148 | } |
| 149 | |
| 150 | /// isSafeToConvert - Return true if it is safe to convert this field type, |
| 151 | /// which requires the structure elements contained by-value to all be |
| 152 | /// recursively safe to convert. |
| 153 | static bool |
| 154 | isSafeToConvert(QualType T, CodeGenTypes &CGT, |
| 155 | llvm::SmallPtrSet<const RecordDecl*, 16> &AlreadyChecked) { |
Pirama Arumuga Nainar | 87d948e | 2016-03-03 15:49:35 -0800 | [diff] [blame] | 156 | // Strip off atomic type sugar. |
| 157 | if (const auto *AT = T->getAs<AtomicType>()) |
| 158 | T = AT->getValueType(); |
| 159 | |
Chris Lattner | 71305cc | 2011-07-15 05:16:14 +0000 | [diff] [blame] | 160 | // If this is a record, check it. |
Pirama Arumuga Nainar | 87d948e | 2016-03-03 15:49:35 -0800 | [diff] [blame] | 161 | if (const auto *RT = T->getAs<RecordType>()) |
Chris Lattner | 71305cc | 2011-07-15 05:16:14 +0000 | [diff] [blame] | 162 | return isSafeToConvert(RT->getDecl(), CGT, AlreadyChecked); |
Pirama Arumuga Nainar | 87d948e | 2016-03-03 15:49:35 -0800 | [diff] [blame] | 163 | |
Chris Lattner | 71305cc | 2011-07-15 05:16:14 +0000 | [diff] [blame] | 164 | // If this is an array, check the elements, which are embedded inline. |
Pirama Arumuga Nainar | 87d948e | 2016-03-03 15:49:35 -0800 | [diff] [blame] | 165 | if (const auto *AT = CGT.getContext().getAsArrayType(T)) |
Chris Lattner | 71305cc | 2011-07-15 05:16:14 +0000 | [diff] [blame] | 166 | return isSafeToConvert(AT->getElementType(), CGT, AlreadyChecked); |
| 167 | |
| 168 | // Otherwise, there is no concern about transforming this. We only care about |
| 169 | // things that are contained by-value in a structure that can have another |
| 170 | // structure as a member. |
| 171 | return true; |
| 172 | } |
| 173 | |
| 174 | |
| 175 | /// isSafeToConvert - Return true if it is safe to convert the specified record |
| 176 | /// decl to IR and lay it out, false if doing so would cause us to get into a |
| 177 | /// recursive compilation mess. |
| 178 | static bool isSafeToConvert(const RecordDecl *RD, CodeGenTypes &CGT) { |
| 179 | // If no structs are being laid out, we can certainly do this one. |
| 180 | if (CGT.noRecordsBeingLaidOut()) return true; |
| 181 | |
| 182 | llvm::SmallPtrSet<const RecordDecl*, 16> AlreadyChecked; |
| 183 | return isSafeToConvert(RD, CGT, AlreadyChecked); |
| 184 | } |
| 185 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 186 | /// isFuncParamTypeConvertible - Return true if the specified type in a |
| 187 | /// function parameter or result position can be converted to an IR type at this |
Chris Lattner | f742eb0 | 2011-07-10 00:18:59 +0000 | [diff] [blame] | 188 | /// point. This boils down to being whether it is complete, as well as whether |
| 189 | /// we've temporarily deferred expanding the type because we're in a recursive |
| 190 | /// context. |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 191 | bool CodeGenTypes::isFuncParamTypeConvertible(QualType Ty) { |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 192 | // Some ABIs cannot have their member pointers represented in IR unless |
| 193 | // certain circumstances have been reached. |
| 194 | if (const auto *MPT = Ty->getAs<MemberPointerType>()) |
| 195 | return getCXXABI().isMemberPointerConvertible(MPT); |
| 196 | |
Chris Lattner | f742eb0 | 2011-07-10 00:18:59 +0000 | [diff] [blame] | 197 | // If this isn't a tagged type, we can convert it! |
| 198 | const TagType *TT = Ty->getAs<TagType>(); |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 199 | if (!TT) return true; |
| 200 | |
Douglas Gregor | bcf38f2 | 2012-02-25 00:16:17 +0000 | [diff] [blame] | 201 | // Incomplete types cannot be converted. |
Douglas Gregor | 4a59bc2 | 2012-02-25 00:06:47 +0000 | [diff] [blame] | 202 | if (TT->isIncompleteType()) |
Chris Lattner | f742eb0 | 2011-07-10 00:18:59 +0000 | [diff] [blame] | 203 | return false; |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 204 | |
Chris Lattner | 71305cc | 2011-07-15 05:16:14 +0000 | [diff] [blame] | 205 | // If this is an enum, then it is always safe to convert. |
Chris Lattner | f742eb0 | 2011-07-10 00:18:59 +0000 | [diff] [blame] | 206 | const RecordType *RT = dyn_cast<RecordType>(TT); |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 207 | if (!RT) return true; |
Chris Lattner | f742eb0 | 2011-07-10 00:18:59 +0000 | [diff] [blame] | 208 | |
| 209 | // Otherwise, we have to be careful. If it is a struct that we're in the |
| 210 | // process of expanding, then we can't convert the function type. That's ok |
| 211 | // though because we must be in a pointer context under the struct, so we can |
| 212 | // just convert it to a dummy type. |
| 213 | // |
| 214 | // We decide this by checking whether ConvertRecordDeclType returns us an |
| 215 | // opaque type for a struct that we know is defined. |
Chris Lattner | 71305cc | 2011-07-15 05:16:14 +0000 | [diff] [blame] | 216 | return isSafeToConvert(RT->getDecl(), *this); |
Chris Lattner | f742eb0 | 2011-07-10 00:18:59 +0000 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | |
| 220 | /// Code to verify a given function type is complete, i.e. the return type |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 221 | /// and all of the parameter types are complete. Also check to see if we are in |
Chris Lattner | f742eb0 | 2011-07-10 00:18:59 +0000 | [diff] [blame] | 222 | /// a RS_StructPointer context, and if so whether any struct types have been |
| 223 | /// pended. If so, we don't want to ask the ABI lowering code to handle a type |
| 224 | /// that cannot be converted to an IR type. |
| 225 | bool CodeGenTypes::isFuncTypeConvertible(const FunctionType *FT) { |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 226 | if (!isFuncParamTypeConvertible(FT->getReturnType())) |
Chris Lattner | f742eb0 | 2011-07-10 00:18:59 +0000 | [diff] [blame] | 227 | return false; |
| 228 | |
| 229 | if (const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(FT)) |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 230 | for (unsigned i = 0, e = FPT->getNumParams(); i != e; i++) |
| 231 | if (!isFuncParamTypeConvertible(FPT->getParamType(i))) |
Chris Lattner | f742eb0 | 2011-07-10 00:18:59 +0000 | [diff] [blame] | 232 | return false; |
| 233 | |
| 234 | return true; |
Eli Friedman | b3b6b9b | 2009-03-05 03:16:41 +0000 | [diff] [blame] | 235 | } |
| 236 | |
Chris Lattner | c5b8806 | 2008-02-06 05:08:19 +0000 | [diff] [blame] | 237 | /// UpdateCompletedType - When we find the full definition for a TagDecl, |
| 238 | /// replace the 'opaque' type we previously made for it if applicable. |
| 239 | void CodeGenTypes::UpdateCompletedType(const TagDecl *TD) { |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 240 | // If this is an enum being completed, then we flush all non-struct types from |
| 241 | // the cache. This allows function types and other things that may be derived |
| 242 | // from the enum to be recomputed. |
Chris Lattner | 8dd5cdf | 2011-07-09 18:53:56 +0000 | [diff] [blame] | 243 | if (const EnumDecl *ED = dyn_cast<EnumDecl>(TD)) { |
| 244 | // Only flush the cache if we've actually already converted this type. |
Chris Lattner | 2045b2d | 2011-07-13 05:31:19 +0000 | [diff] [blame] | 245 | if (TypeCache.count(ED->getTypeForDecl())) { |
| 246 | // Okay, we formed some types based on this. We speculated that the enum |
| 247 | // would be lowered to i32, so we only need to flush the cache if this |
| 248 | // didn't happen. |
| 249 | if (!ConvertType(ED->getIntegerType())->isIntegerTy(32)) |
| 250 | TypeCache.clear(); |
| 251 | } |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 252 | // If necessary, provide the full definition of a type only used with a |
| 253 | // declaration so far. |
| 254 | if (CGDebugInfo *DI = CGM.getModuleDebugInfo()) |
| 255 | DI->completeType(ED); |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 256 | return; |
Eli Friedman | b3b6b9b | 2009-03-05 03:16:41 +0000 | [diff] [blame] | 257 | } |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 258 | |
Chris Lattner | f0a8679 | 2011-07-10 03:47:27 +0000 | [diff] [blame] | 259 | // If we completed a RecordDecl that we previously used and converted to an |
| 260 | // anonymous type, then go ahead and complete it now. |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 261 | const RecordDecl *RD = cast<RecordDecl>(TD); |
Chris Lattner | f0a8679 | 2011-07-10 03:47:27 +0000 | [diff] [blame] | 262 | if (RD->isDependentType()) return; |
| 263 | |
| 264 | // Only complete it if we converted it already. If we haven't converted it |
| 265 | // yet, we'll just do it lazily. |
Chris Lattner | 3ade975 | 2011-07-10 06:03:22 +0000 | [diff] [blame] | 266 | if (RecordDeclTypes.count(Context.getTagDeclType(RD).getTypePtr())) |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 267 | ConvertRecordDeclType(RD); |
David Blaikie | eab6a36 | 2013-06-21 00:40:50 +0000 | [diff] [blame] | 268 | |
| 269 | // If necessary, provide the full definition of a type only used with a |
| 270 | // declaration so far. |
| 271 | if (CGDebugInfo *DI = CGM.getModuleDebugInfo()) |
David Blaikie | 2780489 | 2013-08-15 20:49:17 +0000 | [diff] [blame] | 272 | DI->completeType(RD); |
Chris Lattner | d86e6bc | 2008-02-05 08:06:13 +0000 | [diff] [blame] | 273 | } |
| 274 | |
Pirama Arumuga Nainar | 4967a71 | 2016-09-19 22:19:55 -0700 | [diff] [blame^] | 275 | void CodeGenTypes::RefreshTypeCacheForClass(const CXXRecordDecl *RD) { |
| 276 | QualType T = Context.getRecordType(RD); |
| 277 | T = Context.getCanonicalType(T); |
| 278 | |
| 279 | const Type *Ty = T.getTypePtr(); |
| 280 | if (RecordsWithOpaqueMemberPointers.count(Ty)) { |
| 281 | TypeCache.clear(); |
| 282 | RecordsWithOpaqueMemberPointers.clear(); |
| 283 | } |
| 284 | } |
| 285 | |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 286 | static llvm::Type *getTypeForFormat(llvm::LLVMContext &VMContext, |
Joey Gouly | 19dbb20 | 2013-01-23 11:56:20 +0000 | [diff] [blame] | 287 | const llvm::fltSemantics &format, |
| 288 | bool UseNativeHalf = false) { |
| 289 | if (&format == &llvm::APFloat::IEEEhalf) { |
| 290 | if (UseNativeHalf) |
| 291 | return llvm::Type::getHalfTy(VMContext); |
| 292 | else |
| 293 | return llvm::Type::getInt16Ty(VMContext); |
| 294 | } |
Chris Lattner | b7cfe88 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 295 | if (&format == &llvm::APFloat::IEEEsingle) |
Owen Anderson | 0032b27 | 2009-08-13 21:57:51 +0000 | [diff] [blame] | 296 | return llvm::Type::getFloatTy(VMContext); |
Chris Lattner | b7cfe88 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 297 | if (&format == &llvm::APFloat::IEEEdouble) |
Owen Anderson | 0032b27 | 2009-08-13 21:57:51 +0000 | [diff] [blame] | 298 | return llvm::Type::getDoubleTy(VMContext); |
Chris Lattner | b7cfe88 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 299 | if (&format == &llvm::APFloat::IEEEquad) |
Owen Anderson | 0032b27 | 2009-08-13 21:57:51 +0000 | [diff] [blame] | 300 | return llvm::Type::getFP128Ty(VMContext); |
Chris Lattner | b7cfe88 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 301 | if (&format == &llvm::APFloat::PPCDoubleDouble) |
Owen Anderson | 0032b27 | 2009-08-13 21:57:51 +0000 | [diff] [blame] | 302 | return llvm::Type::getPPC_FP128Ty(VMContext); |
Chris Lattner | b7cfe88 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 303 | if (&format == &llvm::APFloat::x87DoubleExtended) |
Owen Anderson | 0032b27 | 2009-08-13 21:57:51 +0000 | [diff] [blame] | 304 | return llvm::Type::getX86_FP80Ty(VMContext); |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 305 | llvm_unreachable("Unknown float format!"); |
Eli Friedman | f6a943e | 2008-05-27 04:20:05 +0000 | [diff] [blame] | 306 | } |
| 307 | |
Pirama Arumuga Nainar | 87d948e | 2016-03-03 15:49:35 -0800 | [diff] [blame] | 308 | llvm::Type *CodeGenTypes::ConvertFunctionType(QualType QFT, |
| 309 | const FunctionDecl *FD) { |
| 310 | assert(QFT.isCanonical()); |
| 311 | const Type *Ty = QFT.getTypePtr(); |
| 312 | const FunctionType *FT = cast<FunctionType>(QFT.getTypePtr()); |
| 313 | // First, check whether we can build the full function type. If the |
| 314 | // function type depends on an incomplete type (e.g. a struct or enum), we |
| 315 | // cannot lower the function type. |
| 316 | if (!isFuncTypeConvertible(FT)) { |
| 317 | // This function's type depends on an incomplete tag type. |
| 318 | |
| 319 | // Force conversion of all the relevant record types, to make sure |
| 320 | // we re-convert the FunctionType when appropriate. |
| 321 | if (const RecordType *RT = FT->getReturnType()->getAs<RecordType>()) |
| 322 | ConvertRecordDeclType(RT->getDecl()); |
| 323 | if (const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(FT)) |
| 324 | for (unsigned i = 0, e = FPT->getNumParams(); i != e; i++) |
| 325 | if (const RecordType *RT = FPT->getParamType(i)->getAs<RecordType>()) |
| 326 | ConvertRecordDeclType(RT->getDecl()); |
| 327 | |
| 328 | SkippedLayout = true; |
| 329 | |
| 330 | // Return a placeholder type. |
| 331 | return llvm::StructType::get(getLLVMContext()); |
| 332 | } |
| 333 | |
| 334 | // While we're converting the parameter types for a function, we don't want |
| 335 | // to recursively convert any pointed-to structs. Converting directly-used |
| 336 | // structs is ok though. |
| 337 | if (!RecordsBeingLaidOut.insert(Ty).second) { |
| 338 | SkippedLayout = true; |
| 339 | return llvm::StructType::get(getLLVMContext()); |
| 340 | } |
| 341 | |
| 342 | // The function type can be built; call the appropriate routines to |
| 343 | // build it. |
| 344 | const CGFunctionInfo *FI; |
| 345 | if (const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(FT)) { |
| 346 | FI = &arrangeFreeFunctionType( |
| 347 | CanQual<FunctionProtoType>::CreateUnsafe(QualType(FPT, 0)), FD); |
| 348 | } else { |
| 349 | const FunctionNoProtoType *FNPT = cast<FunctionNoProtoType>(FT); |
| 350 | FI = &arrangeFreeFunctionType( |
| 351 | CanQual<FunctionNoProtoType>::CreateUnsafe(QualType(FNPT, 0))); |
| 352 | } |
| 353 | |
| 354 | llvm::Type *ResultType = nullptr; |
| 355 | // If there is something higher level prodding our CGFunctionInfo, then |
| 356 | // don't recurse into it again. |
| 357 | if (FunctionsBeingProcessed.count(FI)) { |
| 358 | |
| 359 | ResultType = llvm::StructType::get(getLLVMContext()); |
| 360 | SkippedLayout = true; |
| 361 | } else { |
| 362 | |
| 363 | // Otherwise, we're good to go, go ahead and convert it. |
| 364 | ResultType = GetFunctionType(*FI); |
| 365 | } |
| 366 | |
| 367 | RecordsBeingLaidOut.erase(Ty); |
| 368 | |
| 369 | if (SkippedLayout) |
| 370 | TypeCache.clear(); |
| 371 | |
| 372 | if (RecordsBeingLaidOut.empty()) |
| 373 | while (!DeferredRecords.empty()) |
| 374 | ConvertRecordDeclType(DeferredRecords.pop_back_val()); |
| 375 | return ResultType; |
| 376 | } |
| 377 | |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 378 | /// ConvertType - Convert the specified type to its LLVM form. |
| 379 | llvm::Type *CodeGenTypes::ConvertType(QualType T) { |
| 380 | T = Context.getCanonicalType(T); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 381 | |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 382 | const Type *Ty = T.getTypePtr(); |
| 383 | |
| 384 | // RecordTypes are cached and processed specially. |
| 385 | if (const RecordType *RT = dyn_cast<RecordType>(Ty)) |
| 386 | return ConvertRecordDeclType(RT->getDecl()); |
| 387 | |
| 388 | // See if type is already cached. |
| 389 | llvm::DenseMap<const Type *, llvm::Type *>::iterator TCI = TypeCache.find(Ty); |
| 390 | // If type is found in map then use it. Otherwise, convert type T. |
| 391 | if (TCI != TypeCache.end()) |
| 392 | return TCI->second; |
| 393 | |
| 394 | // If we don't have it in the cache, convert it now. |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 395 | llvm::Type *ResultType = nullptr; |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 396 | switch (Ty->getTypeClass()) { |
| 397 | case Type::Record: // Handled above. |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 398 | #define TYPE(Class, Base) |
| 399 | #define ABSTRACT_TYPE(Class, Base) |
| 400 | #define NON_CANONICAL_TYPE(Class, Base) case Type::Class: |
| 401 | #define DEPENDENT_TYPE(Class, Base) case Type::Class: |
John McCall | ad5e738 | 2010-03-01 23:49:17 +0000 | [diff] [blame] | 402 | #define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class, Base) case Type::Class: |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 403 | #include "clang/AST/TypeNodes.def" |
John McCall | 864c041 | 2011-04-26 20:42:42 +0000 | [diff] [blame] | 404 | llvm_unreachable("Non-canonical or dependent types aren't possible."); |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 405 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 406 | case Type::Builtin: { |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 407 | switch (cast<BuiltinType>(Ty)->getKind()) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 408 | case BuiltinType::Void: |
Steve Naroff | de2e22d | 2009-07-15 18:40:39 +0000 | [diff] [blame] | 409 | case BuiltinType::ObjCId: |
| 410 | case BuiltinType::ObjCClass: |
Fariborz Jahanian | 13dcd00 | 2009-11-21 19:53:08 +0000 | [diff] [blame] | 411 | case BuiltinType::ObjCSel: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 412 | // LLVM void type can only be used as the result of a function call. Just |
| 413 | // map to the same as char. |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 414 | ResultType = llvm::Type::getInt8Ty(getLLVMContext()); |
| 415 | break; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 416 | |
| 417 | case BuiltinType::Bool: |
Chris Lattner | 19009e6 | 2008-01-09 18:47:25 +0000 | [diff] [blame] | 418 | // Note that we always return bool as i1 for use as a scalar type. |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 419 | ResultType = llvm::Type::getInt1Ty(getLLVMContext()); |
| 420 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 421 | |
Chris Lattner | d2d2a11 | 2007-07-14 01:29:45 +0000 | [diff] [blame] | 422 | case BuiltinType::Char_S: |
| 423 | case BuiltinType::Char_U: |
| 424 | case BuiltinType::SChar: |
| 425 | case BuiltinType::UChar: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 426 | case BuiltinType::Short: |
| 427 | case BuiltinType::UShort: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 428 | case BuiltinType::Int: |
| 429 | case BuiltinType::UInt: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 430 | case BuiltinType::Long: |
| 431 | case BuiltinType::ULong: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 432 | case BuiltinType::LongLong: |
| 433 | case BuiltinType::ULongLong: |
Chris Lattner | 3f59c97 | 2010-12-25 23:25:43 +0000 | [diff] [blame] | 434 | case BuiltinType::WChar_S: |
| 435 | case BuiltinType::WChar_U: |
Alisdair Meredith | f5c209d | 2009-07-14 06:30:34 +0000 | [diff] [blame] | 436 | case BuiltinType::Char16: |
| 437 | case BuiltinType::Char32: |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 438 | ResultType = llvm::IntegerType::get(getLLVMContext(), |
| 439 | static_cast<unsigned>(Context.getTypeSize(T))); |
| 440 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 441 | |
Anton Korobeynikov | aa4a99b | 2011-10-14 23:23:15 +0000 | [diff] [blame] | 442 | case BuiltinType::Half: |
Joey Gouly | 19dbb20 | 2013-01-23 11:56:20 +0000 | [diff] [blame] | 443 | // Half FP can either be storage-only (lowered to i16) or native. |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 444 | ResultType = |
| 445 | getTypeForFormat(getLLVMContext(), Context.getFloatTypeSemantics(T), |
| 446 | Context.getLangOpts().NativeHalfType || |
| 447 | Context.getLangOpts().HalfArgsAndReturns); |
Anton Korobeynikov | aa4a99b | 2011-10-14 23:23:15 +0000 | [diff] [blame] | 448 | break; |
Eli Friedman | f6a943e | 2008-05-27 04:20:05 +0000 | [diff] [blame] | 449 | case BuiltinType::Float: |
Nate Begeman | c8b1227 | 2008-04-18 05:41:31 +0000 | [diff] [blame] | 450 | case BuiltinType::Double: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 451 | case BuiltinType::LongDouble: |
Pirama Arumuga Nainar | 4967a71 | 2016-09-19 22:19:55 -0700 | [diff] [blame^] | 452 | case BuiltinType::Float128: |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 453 | ResultType = getTypeForFormat(getLLVMContext(), |
Joey Gouly | 19dbb20 | 2013-01-23 11:56:20 +0000 | [diff] [blame] | 454 | Context.getFloatTypeSemantics(T), |
| 455 | /* UseNativeHalf = */ false); |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 456 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 457 | |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 458 | case BuiltinType::NullPtr: |
Anders Carlsson | c1eb14a | 2009-09-15 04:39:46 +0000 | [diff] [blame] | 459 | // Model std::nullptr_t as i8* |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 460 | ResultType = llvm::Type::getInt8PtrTy(getLLVMContext()); |
| 461 | break; |
Anders Carlsson | c1eb14a | 2009-09-15 04:39:46 +0000 | [diff] [blame] | 462 | |
Chris Lattner | 2df9ced | 2009-04-30 02:43:43 +0000 | [diff] [blame] | 463 | case BuiltinType::UInt128: |
| 464 | case BuiltinType::Int128: |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 465 | ResultType = llvm::IntegerType::get(getLLVMContext(), 128); |
| 466 | break; |
Guy Benyei | b13621d | 2012-12-18 14:38:23 +0000 | [diff] [blame] | 467 | |
Pirama Arumuga Nainar | 4967a71 | 2016-09-19 22:19:55 -0700 | [diff] [blame^] | 468 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ |
| 469 | case BuiltinType::Id: |
| 470 | #include "clang/Basic/OpenCLImageTypes.def" |
Guy Benyei | 21f18c4 | 2013-02-07 10:55:47 +0000 | [diff] [blame] | 471 | case BuiltinType::OCLSampler: |
Guy Benyei | e6b9d80 | 2013-01-20 12:31:11 +0000 | [diff] [blame] | 472 | case BuiltinType::OCLEvent: |
Pirama Arumuga Nainar | 87d948e | 2016-03-03 15:49:35 -0800 | [diff] [blame] | 473 | case BuiltinType::OCLClkEvent: |
| 474 | case BuiltinType::OCLQueue: |
| 475 | case BuiltinType::OCLNDRange: |
| 476 | case BuiltinType::OCLReserveID: |
Guy Benyei | b13621d | 2012-12-18 14:38:23 +0000 | [diff] [blame] | 477 | ResultType = CGM.getOpenCLRuntime().convertOpenCLSpecificType(Ty); |
| 478 | break; |
Eli Friedman | 8c69235 | 2009-12-18 23:28:34 +0000 | [diff] [blame] | 479 | |
Eli Friedman | 8c69235 | 2009-12-18 23:28:34 +0000 | [diff] [blame] | 480 | case BuiltinType::Dependent: |
John McCall | 2dde35b | 2011-10-18 22:28:37 +0000 | [diff] [blame] | 481 | #define BUILTIN_TYPE(Id, SingletonId) |
| 482 | #define PLACEHOLDER_TYPE(Id, SingletonId) \ |
| 483 | case BuiltinType::Id: |
| 484 | #include "clang/AST/BuiltinTypes.def" |
John McCall | 864c041 | 2011-04-26 20:42:42 +0000 | [diff] [blame] | 485 | llvm_unreachable("Unexpected placeholder builtin type!"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 486 | } |
| 487 | break; |
| 488 | } |
Richard Smith | dc7a4f5 | 2013-04-30 13:56:41 +0000 | [diff] [blame] | 489 | case Type::Auto: |
| 490 | llvm_unreachable("Unexpected undeduced auto type!"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 491 | case Type::Complex: { |
Jay Foad | ef6de3d | 2011-07-11 09:56:20 +0000 | [diff] [blame] | 492 | llvm::Type *EltTy = ConvertType(cast<ComplexType>(Ty)->getElementType()); |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 493 | ResultType = llvm::StructType::get(EltTy, EltTy, nullptr); |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 494 | break; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 495 | } |
Sebastian Redl | 7c80bd6 | 2009-03-16 23:22:08 +0000 | [diff] [blame] | 496 | case Type::LValueReference: |
| 497 | case Type::RValueReference: { |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 498 | const ReferenceType *RTy = cast<ReferenceType>(Ty); |
| 499 | QualType ETy = RTy->getPointeeType(); |
| 500 | llvm::Type *PointeeType = ConvertTypeForMem(ETy); |
Peter Collingbourne | 207f4d8 | 2011-03-18 22:38:29 +0000 | [diff] [blame] | 501 | unsigned AS = Context.getTargetAddressSpace(ETy); |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 502 | ResultType = llvm::PointerType::get(PointeeType, AS); |
| 503 | break; |
Daniel Dunbar | 6aeae7f | 2009-02-26 19:48:14 +0000 | [diff] [blame] | 504 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 505 | case Type::Pointer: { |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 506 | const PointerType *PTy = cast<PointerType>(Ty); |
| 507 | QualType ETy = PTy->getPointeeType(); |
| 508 | llvm::Type *PointeeType = ConvertTypeForMem(ETy); |
| 509 | if (PointeeType->isVoidTy()) |
| 510 | PointeeType = llvm::Type::getInt8Ty(getLLVMContext()); |
Peter Collingbourne | 207f4d8 | 2011-03-18 22:38:29 +0000 | [diff] [blame] | 511 | unsigned AS = Context.getTargetAddressSpace(ETy); |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 512 | ResultType = llvm::PointerType::get(PointeeType, AS); |
| 513 | break; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 514 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 515 | |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 516 | case Type::VariableArray: { |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 517 | const VariableArrayType *A = cast<VariableArrayType>(Ty); |
| 518 | assert(A->getIndexTypeCVRQualifiers() == 0 && |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 519 | "FIXME: We only handle trivial array types so far!"); |
Eli Friedman | c5773c4 | 2008-02-15 18:16:39 +0000 | [diff] [blame] | 520 | // VLAs resolve to the innermost element type; this matches |
| 521 | // the return of alloca, and there isn't any obviously better choice. |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 522 | ResultType = ConvertTypeForMem(A->getElementType()); |
| 523 | break; |
Eli Friedman | c5773c4 | 2008-02-15 18:16:39 +0000 | [diff] [blame] | 524 | } |
| 525 | case Type::IncompleteArray: { |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 526 | const IncompleteArrayType *A = cast<IncompleteArrayType>(Ty); |
| 527 | assert(A->getIndexTypeCVRQualifiers() == 0 && |
Eli Friedman | c5773c4 | 2008-02-15 18:16:39 +0000 | [diff] [blame] | 528 | "FIXME: We only handle trivial array types so far!"); |
Chris Lattner | 3a2b657 | 2011-07-12 06:52:18 +0000 | [diff] [blame] | 529 | // int X[] -> [0 x int], unless the element type is not sized. If it is |
| 530 | // unsized (e.g. an incomplete struct) just use [0 x i8]. |
| 531 | ResultType = ConvertTypeForMem(A->getElementType()); |
| 532 | if (!ResultType->isSized()) { |
| 533 | SkippedLayout = true; |
| 534 | ResultType = llvm::Type::getInt8Ty(getLLVMContext()); |
| 535 | } |
| 536 | ResultType = llvm::ArrayType::get(ResultType, 0); |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 537 | break; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 538 | } |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 539 | case Type::ConstantArray: { |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 540 | const ConstantArrayType *A = cast<ConstantArrayType>(Ty); |
Chris Lattner | 2acc6e3 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 541 | llvm::Type *EltTy = ConvertTypeForMem(A->getElementType()); |
Chris Lattner | 01c5d1d | 2011-07-22 06:27:26 +0000 | [diff] [blame] | 542 | |
| 543 | // Lower arrays of undefined struct type to arrays of i8 just to have a |
| 544 | // concrete type. |
| 545 | if (!EltTy->isSized()) { |
| 546 | SkippedLayout = true; |
| 547 | EltTy = llvm::Type::getInt8Ty(getLLVMContext()); |
| 548 | } |
| 549 | |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 550 | ResultType = llvm::ArrayType::get(EltTy, A->getSize().getZExtValue()); |
| 551 | break; |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 552 | } |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 553 | case Type::ExtVector: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 554 | case Type::Vector: { |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 555 | const VectorType *VT = cast<VectorType>(Ty); |
| 556 | ResultType = llvm::VectorType::get(ConvertType(VT->getElementType()), |
| 557 | VT->getNumElements()); |
| 558 | break; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 559 | } |
| 560 | case Type::FunctionNoProto: |
Pirama Arumuga Nainar | 87d948e | 2016-03-03 15:49:35 -0800 | [diff] [blame] | 561 | case Type::FunctionProto: |
| 562 | ResultType = ConvertFunctionType(T); |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 563 | break; |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 564 | case Type::ObjCObject: |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 565 | ResultType = ConvertType(cast<ObjCObjectType>(Ty)->getBaseType()); |
| 566 | break; |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 567 | |
Chris Lattner | 391d77a | 2008-03-30 23:03:07 +0000 | [diff] [blame] | 568 | case Type::ObjCInterface: { |
Daniel Dunbar | 412f59b | 2009-04-22 10:28:39 +0000 | [diff] [blame] | 569 | // Objective-C interfaces are always opaque (outside of the |
| 570 | // runtime, which can do whatever it likes); we never refine |
| 571 | // these. |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 572 | llvm::Type *&T = InterfaceTypes[cast<ObjCInterfaceType>(Ty)]; |
Daniel Dunbar | 412f59b | 2009-04-22 10:28:39 +0000 | [diff] [blame] | 573 | if (!T) |
Chris Lattner | c1c2011 | 2011-08-12 17:43:31 +0000 | [diff] [blame] | 574 | T = llvm::StructType::create(getLLVMContext()); |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 575 | ResultType = T; |
| 576 | break; |
Chris Lattner | 391d77a | 2008-03-30 23:03:07 +0000 | [diff] [blame] | 577 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 578 | |
Steve Naroff | 14108da | 2009-07-10 23:34:53 +0000 | [diff] [blame] | 579 | case Type::ObjCObjectPointer: { |
Daniel Dunbar | 28e4780 | 2009-07-11 21:12:14 +0000 | [diff] [blame] | 580 | // Protocol qualifications do not influence the LLVM type, we just return a |
| 581 | // pointer to the underlying interface type. We don't need to worry about |
| 582 | // recursive conversion. |
Chris Lattner | 2acc6e3 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 583 | llvm::Type *T = |
Chris Lattner | 181eeee | 2011-07-20 06:23:59 +0000 | [diff] [blame] | 584 | ConvertTypeForMem(cast<ObjCObjectPointerType>(Ty)->getPointeeType()); |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 585 | ResultType = T->getPointerTo(); |
| 586 | break; |
Steve Naroff | 14108da | 2009-07-10 23:34:53 +0000 | [diff] [blame] | 587 | } |
Daniel Dunbar | 28e4780 | 2009-07-11 21:12:14 +0000 | [diff] [blame] | 588 | |
Chris Lattner | 2045b2d | 2011-07-13 05:31:19 +0000 | [diff] [blame] | 589 | case Type::Enum: { |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 590 | const EnumDecl *ED = cast<EnumType>(Ty)->getDecl(); |
John McCall | 5e1cdac | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 591 | if (ED->isCompleteDefinition() || ED->isFixed()) |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 592 | return ConvertType(ED->getIntegerType()); |
Chris Lattner | 2045b2d | 2011-07-13 05:31:19 +0000 | [diff] [blame] | 593 | // Return a placeholder 'i32' type. This can be changed later when the |
| 594 | // type is defined (see UpdateCompletedType), but is likely to be the |
| 595 | // "right" answer. |
| 596 | ResultType = llvm::Type::getInt32Ty(getLLVMContext()); |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 597 | break; |
Chris Lattner | de0efb3 | 2008-02-06 05:48:29 +0000 | [diff] [blame] | 598 | } |
Daniel Dunbar | 9048891 | 2008-08-28 18:02:04 +0000 | [diff] [blame] | 599 | |
| 600 | case Type::BlockPointer: { |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 601 | const QualType FTy = cast<BlockPointerType>(Ty)->getPointeeType(); |
| 602 | llvm::Type *PointeeType = ConvertTypeForMem(FTy); |
Peter Collingbourne | 207f4d8 | 2011-03-18 22:38:29 +0000 | [diff] [blame] | 603 | unsigned AS = Context.getTargetAddressSpace(FTy); |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 604 | ResultType = llvm::PointerType::get(PointeeType, AS); |
| 605 | break; |
Daniel Dunbar | 9048891 | 2008-08-28 18:02:04 +0000 | [diff] [blame] | 606 | } |
Sebastian Redl | 424c51d | 2009-01-25 13:35:30 +0000 | [diff] [blame] | 607 | |
Anders Carlsson | 0e65001 | 2009-05-17 17:41:20 +0000 | [diff] [blame] | 608 | case Type::MemberPointer: { |
Pirama Arumuga Nainar | 4967a71 | 2016-09-19 22:19:55 -0700 | [diff] [blame^] | 609 | auto *MPTy = cast<MemberPointerType>(Ty); |
| 610 | if (!getCXXABI().isMemberPointerConvertible(MPTy)) { |
| 611 | RecordsWithOpaqueMemberPointers.insert(MPTy->getClass()); |
| 612 | ResultType = llvm::StructType::create(getLLVMContext()); |
| 613 | } else { |
| 614 | ResultType = getCXXABI().ConvertMemberPointerType(MPTy); |
| 615 | } |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 616 | break; |
Anders Carlsson | 0e65001 | 2009-05-17 17:41:20 +0000 | [diff] [blame] | 617 | } |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 618 | |
| 619 | case Type::Atomic: { |
John McCall | 9eda3ab | 2013-03-07 21:37:17 +0000 | [diff] [blame] | 620 | QualType valueType = cast<AtomicType>(Ty)->getValueType(); |
| 621 | ResultType = ConvertTypeForMem(valueType); |
| 622 | |
| 623 | // Pad out to the inflated size if necessary. |
| 624 | uint64_t valueSize = Context.getTypeSize(valueType); |
| 625 | uint64_t atomicSize = Context.getTypeSize(Ty); |
| 626 | if (valueSize != atomicSize) { |
| 627 | assert(valueSize < atomicSize); |
| 628 | llvm::Type *elts[] = { |
| 629 | ResultType, |
| 630 | llvm::ArrayType::get(CGM.Int8Ty, (atomicSize - valueSize) / 8) |
| 631 | }; |
| 632 | ResultType = llvm::StructType::get(getLLVMContext(), |
| 633 | llvm::makeArrayRef(elts)); |
| 634 | } |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 635 | break; |
| 636 | } |
Pirama Arumuga Nainar | 4967a71 | 2016-09-19 22:19:55 -0700 | [diff] [blame^] | 637 | case Type::Pipe: { |
| 638 | ResultType = CGM.getOpenCLRuntime().getPipeType(); |
| 639 | break; |
| 640 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 641 | } |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 642 | |
| 643 | assert(ResultType && "Didn't convert a type?"); |
| 644 | |
| 645 | TypeCache[Ty] = ResultType; |
| 646 | return ResultType; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 647 | } |
| 648 | |
John McCall | 9eda3ab | 2013-03-07 21:37:17 +0000 | [diff] [blame] | 649 | bool CodeGenModule::isPaddedAtomicType(QualType type) { |
| 650 | return isPaddedAtomicType(type->castAs<AtomicType>()); |
| 651 | } |
| 652 | |
| 653 | bool CodeGenModule::isPaddedAtomicType(const AtomicType *type) { |
| 654 | return Context.getTypeSize(type) != Context.getTypeSize(type->getValueType()); |
| 655 | } |
| 656 | |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 657 | /// ConvertRecordDeclType - Lay out a tagged decl type like struct or union. |
| 658 | llvm::StructType *CodeGenTypes::ConvertRecordDeclType(const RecordDecl *RD) { |
Daniel Dunbar | efb6d0d | 2008-09-06 02:26:43 +0000 | [diff] [blame] | 659 | // TagDecl's are not necessarily unique, instead use the (clang) |
| 660 | // type connected to the decl. |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 661 | const Type *Key = Context.getTagDeclType(RD).getTypePtr(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 662 | |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 663 | llvm::StructType *&Entry = RecordDeclTypes[Key]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 664 | |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 665 | // If we don't have a StructType at all yet, create the forward declaration. |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 666 | if (!Entry) { |
Chris Lattner | c1c2011 | 2011-08-12 17:43:31 +0000 | [diff] [blame] | 667 | Entry = llvm::StructType::create(getLLVMContext()); |
Chris Lattner | cd87d1e | 2011-07-12 05:53:08 +0000 | [diff] [blame] | 668 | addRecordTypeName(RD, Entry, ""); |
| 669 | } |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 670 | llvm::StructType *Ty = Entry; |
Douglas Gregor | 1274ccd | 2010-10-08 23:50:27 +0000 | [diff] [blame] | 671 | |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 672 | // If this is still a forward declaration, or the LLVM type is already |
| 673 | // complete, there's nothing more to do. |
Chris Lattner | 71305cc | 2011-07-15 05:16:14 +0000 | [diff] [blame] | 674 | RD = RD->getDefinition(); |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 675 | if (!RD || !RD->isCompleteDefinition() || !Ty->isOpaque()) |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 676 | return Ty; |
| 677 | |
Chris Lattner | 71305cc | 2011-07-15 05:16:14 +0000 | [diff] [blame] | 678 | // If converting this type would cause us to infinitely loop, don't do it! |
| 679 | if (!isSafeToConvert(RD, *this)) { |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 680 | DeferredRecords.push_back(RD); |
| 681 | return Ty; |
Chris Lattner | 5de00fc | 2008-02-06 06:03:51 +0000 | [diff] [blame] | 682 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 683 | |
Chris Lattner | 5de00fc | 2008-02-06 06:03:51 +0000 | [diff] [blame] | 684 | // Okay, this is a definition of a type. Compile the implementation now. |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 685 | bool InsertResult = RecordsBeingLaidOut.insert(Key).second; |
| 686 | (void)InsertResult; |
Chris Lattner | 71305cc | 2011-07-15 05:16:14 +0000 | [diff] [blame] | 687 | assert(InsertResult && "Recursively compiling a struct?"); |
| 688 | |
John McCall | 86ff308 | 2010-02-04 22:26:26 +0000 | [diff] [blame] | 689 | // Force conversion of non-virtual base classes recursively. |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 690 | if (const CXXRecordDecl *CRD = dyn_cast<CXXRecordDecl>(RD)) { |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 691 | for (const auto &I : CRD->bases()) { |
| 692 | if (I.isVirtual()) continue; |
Chris Lattner | 71305cc | 2011-07-15 05:16:14 +0000 | [diff] [blame] | 693 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 694 | ConvertRecordDeclType(I.getType()->getAs<RecordType>()->getDecl()); |
John McCall | 86ff308 | 2010-02-04 22:26:26 +0000 | [diff] [blame] | 695 | } |
| 696 | } |
| 697 | |
Anders Carlsson | 696798f | 2009-07-27 17:10:54 +0000 | [diff] [blame] | 698 | // Layout fields. |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 699 | CGRecordLayout *Layout = ComputeRecordLayout(RD, Ty); |
Anders Carlsson | 696798f | 2009-07-27 17:10:54 +0000 | [diff] [blame] | 700 | CGRecordLayouts[Key] = Layout; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 701 | |
Chris Lattner | 71305cc | 2011-07-15 05:16:14 +0000 | [diff] [blame] | 702 | // We're done laying out this struct. |
| 703 | bool EraseResult = RecordsBeingLaidOut.erase(Key); (void)EraseResult; |
| 704 | assert(EraseResult && "struct not in RecordsBeingLaidOut set?"); |
| 705 | |
Chris Lattner | f0a8679 | 2011-07-10 03:47:27 +0000 | [diff] [blame] | 706 | // If this struct blocked a FunctionType conversion, then recompute whatever |
| 707 | // was derived from that. |
| 708 | // FIXME: This is hugely overconservative. |
Chris Lattner | 57eb23f | 2011-07-10 05:39:13 +0000 | [diff] [blame] | 709 | if (SkippedLayout) |
| 710 | TypeCache.clear(); |
Chris Lattner | 71305cc | 2011-07-15 05:16:14 +0000 | [diff] [blame] | 711 | |
| 712 | // If we're done converting the outer-most record, then convert any deferred |
| 713 | // structs as well. |
| 714 | if (RecordsBeingLaidOut.empty()) |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 715 | while (!DeferredRecords.empty()) |
| 716 | ConvertRecordDeclType(DeferredRecords.pop_back_val()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 717 | |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 718 | return Ty; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 719 | } |
Chris Lattner | fc3b8e9 | 2008-02-06 05:18:32 +0000 | [diff] [blame] | 720 | |
Anders Carlsson | 2d98777 | 2010-11-24 20:22:04 +0000 | [diff] [blame] | 721 | /// getCGRecordLayout - Return record layout info for the given record decl. |
Anders Carlsson | ad3e711 | 2009-08-24 17:16:23 +0000 | [diff] [blame] | 722 | const CGRecordLayout & |
Anders Carlsson | 2d98777 | 2010-11-24 20:22:04 +0000 | [diff] [blame] | 723 | CodeGenTypes::getCGRecordLayout(const RecordDecl *RD) { |
| 724 | const Type *Key = Context.getTagDeclType(RD).getTypePtr(); |
Anders Carlsson | 8292696 | 2010-11-24 19:52:29 +0000 | [diff] [blame] | 725 | |
Daniel Dunbar | 270e203 | 2010-03-31 00:11:27 +0000 | [diff] [blame] | 726 | const CGRecordLayout *Layout = CGRecordLayouts.lookup(Key); |
Anders Carlsson | c8f01eb | 2010-11-24 19:51:04 +0000 | [diff] [blame] | 727 | if (!Layout) { |
Anders Carlsson | 2d98777 | 2010-11-24 20:22:04 +0000 | [diff] [blame] | 728 | // Compute the type information. |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 729 | ConvertRecordDeclType(RD); |
Anders Carlsson | c8f01eb | 2010-11-24 19:51:04 +0000 | [diff] [blame] | 730 | |
| 731 | // Now try again. |
| 732 | Layout = CGRecordLayouts.lookup(Key); |
| 733 | } |
| 734 | |
Daniel Dunbar | 270e203 | 2010-03-31 00:11:27 +0000 | [diff] [blame] | 735 | assert(Layout && "Unable to find record layout information for type"); |
| 736 | return *Layout; |
Devang Patel | b84a06e | 2007-10-23 02:10:49 +0000 | [diff] [blame] | 737 | } |
Anders Carlsson | 3e5af90 | 2010-05-14 19:41:56 +0000 | [diff] [blame] | 738 | |
John McCall | f16aa10 | 2010-08-22 21:01:12 +0000 | [diff] [blame] | 739 | bool CodeGenTypes::isZeroInitializable(QualType T) { |
Anders Carlsson | 3e5af90 | 2010-05-14 19:41:56 +0000 | [diff] [blame] | 740 | // No need to check for member pointers when not compiling C++. |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 741 | if (!Context.getLangOpts().CPlusPlus) |
John McCall | f16aa10 | 2010-08-22 21:01:12 +0000 | [diff] [blame] | 742 | return true; |
Pirama Arumuga Nainar | b6d6993 | 2015-07-01 12:25:36 -0700 | [diff] [blame] | 743 | |
| 744 | if (const auto *AT = Context.getAsArrayType(T)) { |
| 745 | if (isa<IncompleteArrayType>(AT)) |
| 746 | return true; |
| 747 | if (const auto *CAT = dyn_cast<ConstantArrayType>(AT)) |
| 748 | if (Context.getConstantArrayElementCount(CAT) == 0) |
| 749 | return true; |
| 750 | T = Context.getBaseElementType(T); |
| 751 | } |
| 752 | |
John McCall | f16aa10 | 2010-08-22 21:01:12 +0000 | [diff] [blame] | 753 | // Records are non-zero-initializable if they contain any |
| 754 | // non-zero-initializable subobjects. |
Anders Carlsson | 3e5af90 | 2010-05-14 19:41:56 +0000 | [diff] [blame] | 755 | if (const RecordType *RT = T->getAs<RecordType>()) { |
| 756 | const CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl()); |
John McCall | f16aa10 | 2010-08-22 21:01:12 +0000 | [diff] [blame] | 757 | return isZeroInitializable(RD); |
Anders Carlsson | 3e5af90 | 2010-05-14 19:41:56 +0000 | [diff] [blame] | 758 | } |
John McCall | f16aa10 | 2010-08-22 21:01:12 +0000 | [diff] [blame] | 759 | |
| 760 | // We have to ask the ABI about member pointers. |
Anders Carlsson | 3e5af90 | 2010-05-14 19:41:56 +0000 | [diff] [blame] | 761 | if (const MemberPointerType *MPT = T->getAs<MemberPointerType>()) |
John McCall | f16aa10 | 2010-08-22 21:01:12 +0000 | [diff] [blame] | 762 | return getCXXABI().isZeroInitializable(MPT); |
Anders Carlsson | 3e5af90 | 2010-05-14 19:41:56 +0000 | [diff] [blame] | 763 | |
John McCall | f16aa10 | 2010-08-22 21:01:12 +0000 | [diff] [blame] | 764 | // Everything else is okay. |
| 765 | return true; |
Anders Carlsson | 3e5af90 | 2010-05-14 19:41:56 +0000 | [diff] [blame] | 766 | } |
Anders Carlsson | c39211d | 2010-05-18 03:47:15 +0000 | [diff] [blame] | 767 | |
Pirama Arumuga Nainar | b6d6993 | 2015-07-01 12:25:36 -0700 | [diff] [blame] | 768 | bool CodeGenTypes::isZeroInitializable(const RecordDecl *RD) { |
Anders Carlsson | 3379e9b | 2010-11-24 19:57:04 +0000 | [diff] [blame] | 769 | return getCGRecordLayout(RD).isZeroInitializable(); |
Anders Carlsson | c39211d | 2010-05-18 03:47:15 +0000 | [diff] [blame] | 770 | } |