change more instances of QualType::getCanonicalType to call
ASTContext::getCanonicalType instead (PR2189)



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54105 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp
index e2986a8..bf9f7a0 100644
--- a/lib/Sema/Sema.cpp
+++ b/lib/Sema/Sema.cpp
@@ -110,7 +110,8 @@
 /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit cast. 
 /// If there is already an implicit cast, merge into the existing one.
 void Sema::ImpCastExprToType(Expr *&Expr, QualType Type) {
-  if (Expr->getType().getCanonicalType() == Type.getCanonicalType()) return;
+  if (Context.getCanonicalType(Expr->getType()) ==
+        Context.getCanonicalType(Type)) return;
   
   if (ImplicitCastExpr *ImpCast = dyn_cast<ImplicitCastExpr>(Expr))
     ImpCast->setType(Type);
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp
index 2135770..5da9cd7 100644
--- a/lib/Sema/SemaChecking.cpp
+++ b/lib/Sema/SemaChecking.cpp
@@ -247,8 +247,8 @@
     return true;
   }
 
-  if (FAType.getCanonicalType().getUnqualifiedType() !=
-      SAType.getCanonicalType().getUnqualifiedType()) {
+  if (Context.getCanonicalType(FAType).getUnqualifiedType() !=
+      Context.getCanonicalType(SAType).getUnqualifiedType()) {
     Diag(TheCall->getLocStart(), diag::err_shufflevector_incompatible_vector,
          SourceRange(TheCall->getArg(0)->getLocStart(), 
                      TheCall->getArg(1)->getLocEnd()));
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 610bf61..e046ee9 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -384,7 +384,8 @@
 /// We need to check this explicitly as an incomplete array definition is
 /// considered a VariableArrayType, so will not match a complete array 
 /// definition that would be otherwise equivalent.
-static bool areEquivalentArrayTypes(QualType NewQType, QualType OldQType) {
+static bool areEquivalentArrayTypes(QualType NewQType, QualType OldQType,
+                                    ASTContext &Context) {
   const ArrayType *NewAT = NewQType->getAsArrayType();
   const ArrayType *OldAT = OldQType->getAsArrayType();
 
@@ -403,8 +404,8 @@
   if (NewAT->isIncompleteArrayType() || OldAT->isIncompleteArrayType()) {
     if (NewAT->getIndexTypeQualifier() != OldAT->getIndexTypeQualifier())
       return false;
-    NewQType = NewAT->getElementType().getCanonicalType();
-    OldQType = OldAT->getElementType().getCanonicalType();
+    NewQType = Context.getCanonicalType(NewAT->getElementType());
+    OldQType = Context.getCanonicalType(OldAT->getElementType());
   }
   
   return NewQType == OldQType;
@@ -432,7 +433,8 @@
   // Verify the types match.
   QualType OldCType = Context.getCanonicalType(Old->getType());
   QualType NewCType = Context.getCanonicalType(New->getType());
-  if (OldCType != NewCType && !areEquivalentArrayTypes(NewCType, OldCType)) {
+  if (OldCType != NewCType &&
+      !areEquivalentArrayTypes(NewCType, OldCType, Context)) {
     Diag(New->getLocation(), diag::err_redefinition, New->getName());
     Diag(Old->getLocation(), diag::err_previous_definition);
     return New;
@@ -1252,7 +1254,8 @@
   if (Init->isNullPointerConstant(Context))
     return false;
   if (Init->getType()->isArithmeticType()) {
-    QualType InitTy = Init->getType().getCanonicalType().getUnqualifiedType();
+    QualType InitTy = Context.getCanonicalType(Init->getType())
+                             .getUnqualifiedType();
     if (InitTy == Context.BoolTy) {
       // Special handling for pointers implicitly cast to bool;
       // (e.g. "_Bool rr = &rr;"). This is only legal at the top level.
diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp
index 9a38f6cf..e6a7ce6 100644
--- a/lib/Sema/SemaDeclAttr.cpp
+++ b/lib/Sema/SemaDeclAttr.cpp
@@ -42,12 +42,11 @@
 }
 
 static inline bool isNSStringType(QualType T, ASTContext &Ctx) {
-  if (!T->isPointerType())
+  const PointerType *PT = T->getAsPointerType();
+  if (!PT)
     return false;
   
-  T = T->getAsPointerType()->getPointeeType().getCanonicalType();
-  ObjCInterfaceType* ClsT = dyn_cast<ObjCInterfaceType>(T.getTypePtr());
-  
+  const ObjCInterfaceType *ClsT =PT->getPointeeType()->getAsObjCInterfaceType();
   if (!ClsT)
     return false;
   
@@ -86,10 +85,9 @@
   }
   // unlike gcc's vector_size attribute, we do not allow vectors to be defined
   // in conjunction with complex types (pointers, arrays, functions, etc.).
-  Type *canonType = curType.getCanonicalType().getTypePtr();
-  if (!(canonType->isIntegerType() || canonType->isRealFloatingType())) {
+  if (!curType->isIntegerType() && !curType->isRealFloatingType()) {
     S.Diag(Attr.getLoc(), diag::err_attribute_invalid_vector_type,
-           curType.getCanonicalType().getAsString());
+           curType.getAsString());
     return;
   }
   // unlike gcc's vector_size attribute, the size is specified as the 
@@ -144,10 +142,8 @@
   }
   // navigate to the base type - we need to provide for vector pointers, 
   // vector arrays, and functions returning vectors.
-  Type *canonType = CurType.getCanonicalType().getTypePtr();
-  
-  if (canonType->isPointerType() || canonType->isArrayType() ||
-      canonType->isFunctionType()) {
+  if (CurType->isPointerType() || CurType->isArrayType() ||
+      CurType->isFunctionType()) {
     assert(0 && "HandleVector(): Complex type construction unimplemented");
     /* FIXME: rebuild the type from the inside out, vectorizing the inner type.
      do {
@@ -162,9 +158,9 @@
      */
   }
   // the base type must be integer or float.
-  if (!(canonType->isIntegerType() || canonType->isRealFloatingType())) {
+  if (!CurType->isIntegerType() && !CurType->isRealFloatingType()) {
     S.Diag(Attr.getLoc(), diag::err_attribute_invalid_vector_type,
-           CurType.getCanonicalType().getAsString());
+           CurType.getAsString());
     return;
   }
   unsigned typeSize = static_cast<unsigned>(S.Context.getTypeSize(CurType));
@@ -239,7 +235,6 @@
   // GCC ignores the nonnull attribute on K&R style function
   // prototypes, so we ignore it as well
   const FunctionTypeProto *proto = getFunctionProto(d);
-  
   if (!proto) {
     S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type,
            "nonnull", "function");
@@ -275,7 +270,7 @@
     --x;
 
     // Is the function argument a pointer type?
-    if (!proto->getArgType(x).getCanonicalType()->isPointerType()) {
+    if (!proto->getArgType(x)->isPointerType()) {
       // FIXME: Should also highlight argument in decl.
       S.Diag(Attr.getLoc(), diag::err_nonnull_pointers_only,
              "nonnull", Ex->getSourceRange());
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index 8050557..b9a061b 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -36,8 +36,7 @@
   /// diagnose the use of local variables or parameters within the
   /// default argument expression.
   class VISIBILITY_HIDDEN CheckDefaultArgumentVisitor 
-    : public StmtVisitor<CheckDefaultArgumentVisitor, bool>
-  {
+    : public StmtVisitor<CheckDefaultArgumentVisitor, bool> {
     Expr *DefaultArg;
     Sema *S;
 
@@ -52,11 +51,9 @@
   /// VisitExpr - Visit all of the children of this expression.
   bool CheckDefaultArgumentVisitor::VisitExpr(Expr *Node) {
     bool IsInvalid = false;
-    for (Stmt::child_iterator first = Node->child_begin(), 
-           last = Node->child_end();
-         first != last; ++first)
-      IsInvalid |= Visit(*first);
-
+    for (Stmt::child_iterator I = Node->child_begin(), 
+         E = Node->child_end(); I != E; ++I)
+      IsInvalid |= Visit(*I);
     return IsInvalid;
   }
 
@@ -427,13 +424,14 @@
     // C++ 9.2p4: A member-declarator can contain a constant-initializer only
     // if it declares a static member of const integral or const enumeration
     // type.
-    if (CXXClassVarDecl *CVD =
-              dyn_cast<CXXClassVarDecl>(Member)) { // ...static member of...
+    if (CXXClassVarDecl *CVD = dyn_cast<CXXClassVarDecl>(Member)) {
+      // ...static member of...
       CVD->setInit(Init);
-      QualType MemberTy = CVD->getType().getCanonicalType();
       // ...const integral or const enumeration type.
-      if (MemberTy.isConstQualified() && MemberTy->isIntegralType()) {
-        if (CheckForConstantInitializer(Init, MemberTy)) // constant-initializer
+      if (Context.getCanonicalType(CVD->getType()).isConstQualified() &&
+          CVD->getType()->isIntegralType()) {
+        // constant-initializer
+        if (CheckForConstantInitializer(Init, CVD->getType()))
           InvalidDecl = true;
 
       } else {
diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp
index d3e2ed3..56e97c0 100644
--- a/lib/Sema/SemaDeclObjC.cpp
+++ b/lib/Sema/SemaDeclObjC.cpp
@@ -727,8 +727,8 @@
 /// TODO: Handle protocol list; such as id<p1,p2> in type comparisons
 bool Sema::MatchTwoMethodDeclarations(const ObjCMethodDecl *Method, 
                                       const ObjCMethodDecl *PrevMethod) {
-  if (Method->getResultType().getCanonicalType() !=
-      PrevMethod->getResultType().getCanonicalType())
+  if (Context.getCanonicalType(Method->getResultType()) !=
+      Context.getCanonicalType(PrevMethod->getResultType()))
     return false;
   for (unsigned i = 0, e = Method->getNumParams(); i != e; ++i) {
     ParmVarDecl *ParamDecl = Method->getParamDecl(i);
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index d69a0dc..37e4ec7 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -105,8 +105,10 @@
   }
   // For conversion purposes, we ignore any qualifiers. 
   // For example, "const float" and "float" are equivalent.
-  QualType lhs = lhsExpr->getType().getCanonicalType().getUnqualifiedType();
-  QualType rhs = rhsExpr->getType().getCanonicalType().getUnqualifiedType();
+  QualType lhs =
+    Context.getCanonicalType(lhsExpr->getType()).getUnqualifiedType();
+  QualType rhs = 
+    Context.getCanonicalType(rhsExpr->getType()).getUnqualifiedType();
   
   // If both types are identical, no conversion is needed.
   if (lhs == rhs)
@@ -1318,8 +1320,8 @@
   rhptee = rhsType->getAsPointerType()->getPointeeType();
   
   // make sure we operate on the canonical type
-  lhptee = lhptee.getCanonicalType();
-  rhptee = rhptee.getCanonicalType();
+  lhptee = Context.getCanonicalType(lhptee);
+  rhptee = Context.getCanonicalType(rhptee);
 
   AssignConvertType ConvTy = Compatible;
   
@@ -1380,8 +1382,8 @@
 Sema::CheckAssignmentConstraints(QualType lhsType, QualType rhsType) {
   // Get canonical types.  We're not formatting these types, just comparing
   // them.
-  lhsType = lhsType.getCanonicalType().getUnqualifiedType();
-  rhsType = rhsType.getCanonicalType().getUnqualifiedType();
+  lhsType = Context.getCanonicalType(lhsType).getUnqualifiedType();
+  rhsType = Context.getCanonicalType(rhsType).getUnqualifiedType();
 
   if (lhsType == rhsType)
     return Compatible; // Common case: fast path an exact match.
@@ -1497,8 +1499,10 @@
                                                               Expr *&rex) {
   // For conversion purposes, we ignore any qualifiers. 
   // For example, "const float" and "float" are equivalent.
-  QualType lhsType = lex->getType().getCanonicalType().getUnqualifiedType();
-  QualType rhsType = rex->getType().getCanonicalType().getUnqualifiedType();
+  QualType lhsType =
+    Context.getCanonicalType(lex->getType()).getUnqualifiedType();
+  QualType rhsType =
+    Context.getCanonicalType(rex->getType()).getUnqualifiedType();
   
   // If the vector types are identical, return.
   if (lhsType == rhsType)
@@ -1744,9 +1748,9 @@
   // errors (when -pedantic-errors is enabled).
   if (lType->isPointerType() && rType->isPointerType()) { // C99 6.5.8p2
     QualType LCanPointeeTy =
-      lType->getAsPointerType()->getPointeeType().getCanonicalType();
+      Context.getCanonicalType(lType->getAsPointerType()->getPointeeType());
     QualType RCanPointeeTy =
-      rType->getAsPointerType()->getPointeeType().getCanonicalType();
+      Context.getCanonicalType(rType->getAsPointerType()->getPointeeType());
     
     if (!LHSIsNull && !RHSIsNull &&                       // C99 6.5.9p2
         !LCanPointeeTy->isVoidType() && !RCanPointeeTy->isVoidType() &&
@@ -2459,11 +2463,12 @@
 /// QualTypes that match the QualTypes of the arguments of the FnType.
 /// The number of arguments has already been validated to match the number of
 /// arguments in FnType.
-static bool ExprsMatchFnType(Expr **Args, const FunctionTypeProto *FnType) {
+static bool ExprsMatchFnType(Expr **Args, const FunctionTypeProto *FnType,
+                             ASTContext &Context) {
   unsigned NumParams = FnType->getNumArgs();
   for (unsigned i = 0; i != NumParams; ++i) {
-    QualType ExprTy = Args[i]->getType().getCanonicalType();
-    QualType ParmTy = FnType->getArgType(i).getCanonicalType();
+    QualType ExprTy = Context.getCanonicalType(Args[i]->getType());
+    QualType ParmTy = Context.getCanonicalType(FnType->getArgType(i));
 
     if (ExprTy.getUnqualifiedType() != ParmTy.getUnqualifiedType())
       return false;
@@ -2507,11 +2512,9 @@
     // UsualUnaryConversions will convert the function DeclRefExpr into a 
     // pointer to function.
     Expr *Fn = UsualUnaryConversions(Args[i]);
-    FunctionTypeProto *FnType = 0;
-    if (const PointerType *PT = Fn->getType()->getAsPointerType()) {
-      QualType PointeeType = PT->getPointeeType().getCanonicalType();
-      FnType = dyn_cast<FunctionTypeProto>(PointeeType);
-    }
+    const FunctionTypeProto *FnType = 0;
+    if (const PointerType *PT = Fn->getType()->getAsPointerType())
+      FnType = PT->getPointeeType()->getAsFunctionTypeProto();
  
     // The Expr type must be FunctionTypeProto, since FunctionTypeProto has no
     // parameters, and the number of parameters must match the value passed to
@@ -2523,7 +2526,7 @@
     // Scan the parameter list for the FunctionType, checking the QualType of
     // each parameter against the QualTypes of the arguments to the builtin.
     // If they match, return a new OverloadExpr.
-    if (ExprsMatchFnType(Args+1, FnType)) {
+    if (ExprsMatchFnType(Args+1, FnType, Context)) {
       if (OE)
         return Diag(Fn->getExprLoc(), diag::err_overload_multiple_match,
                     OE->getFn()->getSourceRange());
diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp
index 97e1579..9575d4c 100644
--- a/lib/Sema/SemaExprObjC.cpp
+++ b/lib/Sema/SemaExprObjC.cpp
@@ -233,19 +233,20 @@
 // ArgExprs is optional - if it is present, the number of expressions
 // is obtained from Sel.getNumArgs().
 Sema::ExprResult Sema::ActOnInstanceMessage(ExprTy *receiver, Selector Sel,
-  SourceLocation lbrac, SourceLocation rbrac, ExprTy **Args, unsigned NumArgs) 
-{
+                                            SourceLocation lbrac, 
+                                            SourceLocation rbrac,
+                                            ExprTy **Args, unsigned NumArgs) {
   assert(receiver && "missing receiver expression");
   
   Expr **ArgExprs = reinterpret_cast<Expr **>(Args);
   Expr *RExpr = static_cast<Expr *>(receiver);
   QualType returnType;
 
-  QualType receiverType = 
-    RExpr->getType().getCanonicalType().getUnqualifiedType();
+  QualType ReceiverCType =
+    Context.getCanonicalType(RExpr->getType()).getUnqualifiedType();
   
   // Handle messages to id.
-  if (receiverType == Context.getObjCIdType().getCanonicalType()) {
+  if (ReceiverCType == Context.getCanonicalType(Context.getObjCIdType())) {
     ObjCMethodDecl *Method = InstanceMethodPool[Sel].Method;
     if (!Method)
       Method = FactoryMethodPool[Sel].Method;
@@ -264,7 +265,7 @@
   }
   
   // Handle messages to Class.
-  if (receiverType == Context.getObjCClassType().getCanonicalType()) {
+  if (ReceiverCType == Context.getCanonicalType(Context.getObjCClassType())) {
     ObjCMethodDecl *Method = 0;
     if (ObjCMethodDecl *CurMeth = getCurMethodDecl()) {
       // If we have an implementation in scope, check "private" methods.
@@ -297,8 +298,7 @@
   
   // We allow sending a message to a qualified ID ("id<foo>"), which is ok as 
   // long as one of the protocols implements the selector (if not, warn).
-  if (ObjCQualifiedIdType *QIT = 
-           dyn_cast<ObjCQualifiedIdType>(receiverType)) {
+  if (ObjCQualifiedIdType *QIT = dyn_cast<ObjCQualifiedIdType>(ReceiverCType)) {
     // Search protocols
     for (unsigned i = 0; i < QIT->getNumProtocols(); i++) {
       ObjCProtocolDecl *PDecl = QIT->getProtocols(i);
@@ -310,7 +310,7 @@
            std::string("-"), Sel.getName(),
            RExpr->getSourceRange());
   } else if (const ObjCInterfaceType *OCIReceiver = 
-                receiverType->getAsPointerToObjCInterfaceType()) {
+                ReceiverCType->getAsPointerToObjCInterfaceType()) {
     // We allow sending a message to a pointer to an interface (an object).
     
     ClassDecl = OCIReceiver->getDecl();