forked from OSchip/llvm-project
Improve support for member function pointers.
llvm-svn: 83039
This commit is contained in:
parent
1fb7ae9e3c
commit
b05a3e551b
|
@ -198,6 +198,21 @@ void AggExprEmitter::VisitCastExpr(CastExpr *E) {
|
||||||
"Implicit cast types must be compatible");
|
"Implicit cast types must be compatible");
|
||||||
Visit(E->getSubExpr());
|
Visit(E->getSubExpr());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case CastExpr::CK_NullToMemberPointer: {
|
||||||
|
QualType T = E->getType();
|
||||||
|
const llvm::Type *PtrDiffTy =
|
||||||
|
CGF.ConvertType(CGF.getContext().getPointerDiffType());
|
||||||
|
|
||||||
|
llvm::Value *NullValue = llvm::Constant::getNullValue(PtrDiffTy);
|
||||||
|
llvm::Value *Ptr = Builder.CreateStructGEP(DestPtr, 0, "ptr");
|
||||||
|
Builder.CreateStore(NullValue, Ptr, VolatileDest);
|
||||||
|
|
||||||
|
llvm::Value *Adj = Builder.CreateStructGEP(DestPtr, 1, "adj");
|
||||||
|
Builder.CreateStore(NullValue, Adj, VolatileDest);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -785,6 +785,13 @@ llvm::Constant *CodeGenModule::EmitConstantExpr(const Expr *E,
|
||||||
return C;
|
return C;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool isDataMemberPointerType(QualType T) {
|
||||||
|
if (const MemberPointerType *MPT = T->getAs<MemberPointerType>())
|
||||||
|
return !MPT->getPointeeType()->isFunctionType();
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
llvm::Constant *CodeGenModule::EmitNullConstant(QualType T) {
|
llvm::Constant *CodeGenModule::EmitNullConstant(QualType T) {
|
||||||
// No need to check for member pointers when not compiling C++.
|
// No need to check for member pointers when not compiling C++.
|
||||||
if (!getContext().getLangOptions().CPlusPlus)
|
if (!getContext().getLangOptions().CPlusPlus)
|
||||||
|
@ -795,7 +802,7 @@ llvm::Constant *CodeGenModule::EmitNullConstant(QualType T) {
|
||||||
QualType ElementTy = CAT->getElementType();
|
QualType ElementTy = CAT->getElementType();
|
||||||
|
|
||||||
// FIXME: Handle arrays of structs that contain member pointers.
|
// FIXME: Handle arrays of structs that contain member pointers.
|
||||||
if (Context.getBaseElementType(ElementTy)->isMemberPointerType()) {
|
if (isDataMemberPointerType(Context.getBaseElementType(ElementTy))) {
|
||||||
llvm::Constant *Element = EmitNullConstant(ElementTy);
|
llvm::Constant *Element = EmitNullConstant(ElementTy);
|
||||||
uint64_t NumElements = CAT->getSize().getZExtValue();
|
uint64_t NumElements = CAT->getSize().getZExtValue();
|
||||||
std::vector<llvm::Constant *> Array(NumElements);
|
std::vector<llvm::Constant *> Array(NumElements);
|
||||||
|
@ -821,7 +828,7 @@ llvm::Constant *CodeGenModule::EmitNullConstant(QualType T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Handle structs that contain member pointers.
|
// FIXME: Handle structs that contain member pointers.
|
||||||
if (T->isMemberPointerType())
|
if (isDataMemberPointerType(T))
|
||||||
return llvm::Constant::getAllOnesValue(getTypes().ConvertTypeForMem(T));
|
return llvm::Constant::getAllOnesValue(getTypes().ConvertTypeForMem(T));
|
||||||
|
|
||||||
return llvm::Constant::getNullValue(getTypes().ConvertTypeForMem(T));
|
return llvm::Constant::getNullValue(getTypes().ConvertTypeForMem(T));
|
||||||
|
|
|
@ -66,7 +66,8 @@ const llvm::Type *CodeGenFunction::ConvertType(QualType T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CodeGenFunction::hasAggregateLLVMType(QualType T) {
|
bool CodeGenFunction::hasAggregateLLVMType(QualType T) {
|
||||||
return T->isRecordType() || T->isArrayType() || T->isAnyComplexType();
|
return T->isRecordType() || T->isArrayType() || T->isAnyComplexType() ||
|
||||||
|
T->isMemberFunctionPointerType();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CodeGenFunction::EmitReturnBlock() {
|
void CodeGenFunction::EmitReturnBlock() {
|
||||||
|
|
Loading…
Reference in New Issue