convert more code to use ASTContext to get canonical types instead
of doing it directly. This is required for PR2189.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54102 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index dedc9b8..47a3e3a 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -1542,15 +1542,15 @@
lhs.getAddressSpace() != rhs.getAddressSpace())
return false;
- QualType ltype = cast<PointerType>(lhs.getCanonicalType())->getPointeeType();
- QualType rtype = cast<PointerType>(rhs.getCanonicalType())->getPointeeType();
+ QualType ltype = lhs->getAsPointerType()->getPointeeType();
+ QualType rtype = rhs->getAsPointerType()->getPointeeType();
return typesAreCompatible(ltype, rtype);
}
bool ASTContext::functionTypesAreCompatible(QualType lhs, QualType rhs) {
- const FunctionType *lbase = cast<FunctionType>(lhs.getCanonicalType());
- const FunctionType *rbase = cast<FunctionType>(rhs.getCanonicalType());
+ const FunctionType *lbase = lhs->getAsFunctionType();
+ const FunctionType *rbase = rhs->getAsFunctionType();
const FunctionTypeProto *lproto = dyn_cast<FunctionTypeProto>(lbase);
const FunctionTypeProto *rproto = dyn_cast<FunctionTypeProto>(rbase);
@@ -1673,8 +1673,8 @@
/// C99 6.2.7p1: Two types have compatible types if their types are the
/// same. See 6.7.[2,3,5] for additional rules.
bool ASTContext::typesAreCompatible(QualType LHS_NC, QualType RHS_NC) {
- QualType LHS = LHS_NC.getCanonicalType();
- QualType RHS = RHS_NC.getCanonicalType();
+ QualType LHS = getCanonicalType(LHS_NC);
+ QualType RHS = getCanonicalType(RHS_NC);
// C++ [expr]: If an expression initially has the type "reference to T", the
// type is adjusted to "T" prior to any further analysis, the expression
diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp
index d31bde2..60b762f 100644
--- a/lib/AST/Expr.cpp
+++ b/lib/AST/Expr.cpp
@@ -387,13 +387,13 @@
/// - (__real__ e) and (__imag__ e) where e is an lvalue [GNU extension]
/// - reference type [C++ [expr]]
///
-Expr::isLvalueResult Expr::isLvalue() const {
+Expr::isLvalueResult Expr::isLvalue(ASTContext &Ctx) const {
// first, check the type (C99 6.3.2.1)
if (TR->isFunctionType()) // from isObjectType()
return LV_NotObjectType;
// Allow qualified void which is an incomplete type other than void (yuck).
- if (TR->isVoidType() && !TR.getCanonicalType().getCVRQualifiers())
+ if (TR->isVoidType() && !Ctx.getCanonicalType(TR).getCVRQualifiers())
return LV_IncompleteVoidType;
if (TR->isReferenceType()) // C++ [expr]
@@ -406,7 +406,7 @@
case ArraySubscriptExprClass: // C99 6.5.3p4 (e1[e2] == (*((e1)+(e2))))
// For vectors, make sure base is an lvalue (i.e. not a function call).
if (cast<ArraySubscriptExpr>(this)->getBase()->getType()->isVectorType())
- return cast<ArraySubscriptExpr>(this)->getBase()->isLvalue();
+ return cast<ArraySubscriptExpr>(this)->getBase()->isLvalue(Ctx);
return LV_Valid;
case DeclRefExprClass: { // C99 6.5.1p2
const Decl *RefdDecl = cast<DeclRefExpr>(this)->getDecl();
@@ -416,7 +416,7 @@
}
case MemberExprClass: { // C99 6.5.2.3p4
const MemberExpr *m = cast<MemberExpr>(this);
- return m->isArrow() ? LV_Valid : m->getBase()->isLvalue();
+ return m->isArrow() ? LV_Valid : m->getBase()->isLvalue(Ctx);
}
case UnaryOperatorClass:
if (cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Deref)
@@ -425,10 +425,10 @@
if (cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Real ||
cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Imag ||
cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Extension)
- return cast<UnaryOperator>(this)->getSubExpr()->isLvalue(); // GNU.
+ return cast<UnaryOperator>(this)->getSubExpr()->isLvalue(Ctx); // GNU.
break;
case ParenExprClass: // C99 6.5.1p5
- return cast<ParenExpr>(this)->getSubExpr()->isLvalue();
+ return cast<ParenExpr>(this)->getSubExpr()->isLvalue(Ctx);
case CompoundLiteralExprClass: // C99 6.5.2.5p5
return LV_Valid;
case ExtVectorElementExprClass:
@@ -444,7 +444,7 @@
== PreDefinedExpr::CXXThis
? LV_InvalidExpression : LV_Valid);
case CXXDefaultArgExprClass:
- return cast<CXXDefaultArgExpr>(this)->getExpr()->isLvalue();
+ return cast<CXXDefaultArgExpr>(this)->getExpr()->isLvalue(Ctx);
default:
break;
}
@@ -456,8 +456,8 @@
/// if it is a structure or union, does not have any member (including,
/// recursively, any member or element of all contained aggregates or unions)
/// with a const-qualified type.
-Expr::isModifiableLvalueResult Expr::isModifiableLvalue() const {
- isLvalueResult lvalResult = isLvalue();
+Expr::isModifiableLvalueResult Expr::isModifiableLvalue(ASTContext &Ctx) const {
+ isLvalueResult lvalResult = isLvalue(Ctx);
switch (lvalResult) {
case LV_Valid: break;
@@ -473,7 +473,7 @@
if (TR->isIncompleteType())
return MLV_IncompleteType;
- if (const RecordType *r = dyn_cast<RecordType>(TR.getCanonicalType())) {
+ if (const RecordType *r = TR->getAsRecordType()) {
if (r->hasConstFields())
return MLV_ConstQualified;
}