[cfe-commits] r159280 - in /cfe/trunk: include/clang/AST/Expr.h lib/AST/Expr.cpp lib/CodeGen/CGExprCXX.cpp lib/Sema/SemaExpr.cpp
Rafael Espindola
rafael.espindola at gmail.com
Wed Jun 27 11:18:05 PDT 2012
Author: rafael
Date: Wed Jun 27 13:18:05 2012
New Revision: 159280
URL: http://llvm.org/viewvc/llvm-project?rev=159280&view=rev
Log:
Implement John McCall's review of r159212 other than the this pointer not
being updated. Will fix that in a second.
Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/CodeGen/CGExprCXX.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=159280&r1=159279&r2=159280&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Wed Jun 27 13:18:05 2012
@@ -665,12 +665,14 @@
static bool hasAnyTypeDependentArguments(llvm::ArrayRef<Expr *> Exprs);
- /// \brief If we have class type (or pointer to class type), return the
- /// class decl. Return NULL otherwise.
+ /// \brief For an expression of class type or pointer to class type,
+ /// return the most derived class decl the expression is known to refer to.
///
/// If this expression is a cast, this method looks through it to find the
- /// most derived decl that can be infered from the expression.
- const CXXRecordDecl *getMostDerivedClassDeclForType() const;
+ /// most derived decl that can be inferred from the expression.
+ /// This is valid because derived-to-base conversions have undefined
+ /// behavior if the object isn't dynamically of the derived type.
+ const CXXRecordDecl *getBestDynamicClassType() const;
static bool classof(const Stmt *T) {
return T->getStmtClass() >= firstExprConstant &&
Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=159280&r1=159279&r2=159280&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Wed Jun 27 13:18:05 2012
@@ -33,7 +33,7 @@
#include <cstring>
using namespace clang;
-const CXXRecordDecl *Expr::getMostDerivedClassDeclForType() const {
+const CXXRecordDecl *Expr::getBestDynamicClassType() const {
const Expr *E = this;
while (true) {
@@ -51,15 +51,10 @@
}
QualType DerivedType = E->getType();
- if (DerivedType->isDependentType())
- return NULL;
if (const PointerType *PTy = DerivedType->getAs<PointerType>())
DerivedType = PTy->getPointeeType();
const RecordType *Ty = DerivedType->castAs<RecordType>();
- if (!Ty)
- return NULL;
-
Decl *D = Ty->getDecl();
return cast<CXXRecordDecl>(D);
}
Modified: cfe/trunk/lib/CodeGen/CGExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprCXX.cpp?rev=159280&r1=159279&r2=159280&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprCXX.cpp Wed Jun 27 13:18:05 2012
@@ -102,8 +102,7 @@
// b->f();
// }
//
- const CXXRecordDecl *MostDerivedClassDecl =
- Base->getMostDerivedClassDeclForType();
+ const CXXRecordDecl *MostDerivedClassDecl = Base->getBestDynamicClassType();
if (MostDerivedClassDecl->hasAttr<FinalAttr>())
return true;
@@ -228,8 +227,7 @@
bool UseVirtualCall = MD->isVirtual() && !ME->hasQualifier()
&& !canDevirtualizeMemberFunctionCalls(getContext(),
Base, MD);
- const CXXRecordDecl *MostDerivedClassDecl =
- Base->getMostDerivedClassDeclForType();
+ const CXXRecordDecl *MostDerivedClassDecl = Base->getBestDynamicClassType();
llvm::Value *Callee;
if (const CXXDestructorDecl *Dtor = dyn_cast<CXXDestructorDecl>(MD)) {
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=159280&r1=159279&r2=159280&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Jun 27 13:18:05 2012
@@ -10854,8 +10854,9 @@
if (!MD)
return;
const Expr *Base = ME->getBase();
- const CXXRecordDecl *MostDerivedClassDecl
- = Base->getMostDerivedClassDeclForType();
+ if (Base->getType()->isDependentType())
+ return;
+ const CXXRecordDecl *MostDerivedClassDecl = Base->getBestDynamicClassType();
if (!MostDerivedClassDecl)
return;
CXXMethodDecl *DM = MD->getCorrespondingMethodInClass(MostDerivedClassDecl);
More information about the cfe-commits
mailing list