From 2c9f87ca5cccbfdaad82762368af5b2323320653 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Fri, 24 Aug 2012 00:54:33 +0000 Subject: New -fcatch-undefined-behavior features: * when checking that a pointer or reference refers to appropriate storage for a type, also check the alignment and perform a null check * check that references are bound to appropriate storage * check that 'this' has appropriate storage in member accesses and member function calls git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162523 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGExprCXX.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'lib/CodeGen/CGExprCXX.cpp') diff --git a/lib/CodeGen/CGExprCXX.cpp b/lib/CodeGen/CGExprCXX.cpp index 31ea1b5448..0faf98032c 100644 --- a/lib/CodeGen/CGExprCXX.cpp +++ b/lib/CodeGen/CGExprCXX.cpp @@ -33,6 +33,11 @@ RValue CodeGenFunction::EmitCXXMemberCall(const CXXMethodDecl *MD, assert(MD->isInstance() && "Trying to emit a member call expr on a static method!"); + // C++11 [class.mfct.non-static]p2: + // If a non-static member function of a class X is called for an object that + // is not of type X, or of a type derived from X, the behavior is undefined. + EmitCheck(CT_MemberCall, This, getContext().getRecordType(MD->getParent())); + CallArgList Args; // Push the this ptr. @@ -337,6 +342,8 @@ CodeGenFunction::EmitCXXMemberPointerCallExpr(const CXXMemberCallExpr *E, else This = EmitLValue(BaseExpr).getAddress(); + EmitCheck(CT_MemberCall, This, QualType(MPT->getClass(), 0)); + // Ask the ABI to load the callee. Note that This is modified. llvm::Value *Callee = CGM.getCXXABI().EmitLoadOfMemberFunctionPointer(*this, This, MemFnPtr, MPT); -- cgit v1.2.3