Move ContainsPointerToDataMember to CodeGenTypes. No functionality change.

llvm-svn: 103792
This commit is contained in:
Anders Carlsson 2010-05-14 19:41:56 +00:00
parent 7bc111f5a9
commit 1cf9274a5a
3 changed files with 29 additions and 25 deletions

View File

@ -984,32 +984,8 @@ llvm::Constant *CodeGenModule::EmitConstantExpr(const Expr *E,
return C;
}
static bool containsPointerToDataMember(CodeGenTypes &Types, QualType T) {
// No need to check for member pointers when not compiling C++.
if (!Types.getContext().getLangOptions().CPlusPlus)
return false;
T = Types.getContext().getBaseElementType(T);
if (const RecordType *RT = T->getAs<RecordType>()) {
const CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl());
// FIXME: It would be better if there was a way to explicitly compute the
// record layout instead of converting to a type.
Types.ConvertTagDeclType(RD);
const CGRecordLayout &Layout = Types.getCGRecordLayout(RD);
return Layout.containsPointerToDataMember();
}
if (const MemberPointerType *MPT = T->getAs<MemberPointerType>())
return !MPT->getPointeeType()->isFunctionType();
return false;
}
llvm::Constant *CodeGenModule::EmitNullConstant(QualType T) {
if (!containsPointerToDataMember(getTypes(), T))
if (!getTypes().ContainsPointerToDataMember(T))
return llvm::Constant::getNullValue(getTypes().ConvertTypeForMem(T));
if (const ConstantArrayType *CAT = Context.getAsConstantArrayType(T)) {

View File

@ -467,3 +467,27 @@ CodeGenTypes::getCGRecordLayout(const RecordDecl *TD) const {
assert(Layout && "Unable to find record layout information for type");
return *Layout;
}
bool CodeGenTypes::ContainsPointerToDataMember(QualType T) {
// No need to check for member pointers when not compiling C++.
if (!Context.getLangOptions().CPlusPlus)
return false;
T = Context.getBaseElementType(T);
if (const RecordType *RT = T->getAs<RecordType>()) {
const CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl());
// FIXME: It would be better if there was a way to explicitly compute the
// record layout instead of converting to a type.
ConvertTagDeclType(RD);
const CGRecordLayout &Layout = getCGRecordLayout(RD);
return Layout.containsPointerToDataMember();
}
if (const MemberPointerType *MPT = T->getAs<MemberPointerType>())
return !MPT->getPointeeType()->isFunctionType();
return false;
}

View File

@ -186,6 +186,10 @@ public: // These are internal details of CGT that shouldn't be used externally.
/// argument types it would be passed as on the provided vector \arg
/// ArgTys. See ABIArgInfo::Expand.
void GetExpandedTypes(QualType Ty, std::vector<const llvm::Type*> &ArgTys);
/// ContainsPointerToDataMember - Return whether the given type contains a
/// pointer to a data member.
bool ContainsPointerToDataMember(QualType T);
};
} // end namespace CodeGen