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