Introduce the canonical type smart pointers, and use them in a few places to
tighten up the static type system.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@78164 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index c474084..ad46bcd 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -2070,18 +2070,19 @@
 /// include typedefs, 'typeof' operators, etc. The returned type is guaranteed
 /// to be free of any of these, allowing two canonical types to be compared
 /// for exact equality with a simple pointer comparison.
-QualType ASTContext::getCanonicalType(QualType T) {
+CanQualType ASTContext::getCanonicalType(QualType T) {
   QualType CanType = T.getTypePtr()->getCanonicalTypeInternal();
   
   // If the result has type qualifiers, make sure to canonicalize them as well.
   unsigned TypeQuals = T.getCVRQualifiers() | CanType.getCVRQualifiers();
-  if (TypeQuals == 0) return CanType;
+  if (TypeQuals == 0) 
+    return CanQualType::CreateUnsafe(CanType);
 
   // If the type qualifiers are on an array type, get the canonical type of the
   // array with the qualifiers applied to the element type.
   ArrayType *AT = dyn_cast<ArrayType>(CanType);
   if (!AT)
-    return CanType.getQualifiedType(TypeQuals);
+    return CanQualType::CreateUnsafe(CanType.getQualifiedType(TypeQuals));
   
   // Get the canonical version of the element with the extra qualifiers on it.
   // This can recursively sink qualifiers through multiple levels of arrays.
@@ -2089,25 +2090,29 @@
   NewEltTy = getCanonicalType(NewEltTy);
   
   if (ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(AT))
-    return getConstantArrayType(NewEltTy, CAT->getSize(),CAT->getSizeModifier(),
-                                CAT->getIndexTypeQualifier());
+    return CanQualType::CreateUnsafe(
+             getConstantArrayType(NewEltTy, CAT->getSize(),
+                                  CAT->getSizeModifier(),
+                                  CAT->getIndexTypeQualifier()));
   if (IncompleteArrayType *IAT = dyn_cast<IncompleteArrayType>(AT))
-    return getIncompleteArrayType(NewEltTy, IAT->getSizeModifier(),
-                                  IAT->getIndexTypeQualifier());
+    return CanQualType::CreateUnsafe(
+             getIncompleteArrayType(NewEltTy, IAT->getSizeModifier(),
+                                    IAT->getIndexTypeQualifier()));
   
   if (DependentSizedArrayType *DSAT = dyn_cast<DependentSizedArrayType>(AT))
-    return getDependentSizedArrayType(NewEltTy,
-                                      DSAT->getSizeExpr(),
-                                      DSAT->getSizeModifier(),
-                                      DSAT->getIndexTypeQualifier(),
-                                      DSAT->getBracketsRange());
+    return CanQualType::CreateUnsafe(
+             getDependentSizedArrayType(NewEltTy,
+                                        DSAT->getSizeExpr(),
+                                        DSAT->getSizeModifier(),
+                                        DSAT->getIndexTypeQualifier(),
+                                        DSAT->getBracketsRange()));
 
   VariableArrayType *VAT = cast<VariableArrayType>(AT);
-  return getVariableArrayType(NewEltTy,
-                              VAT->getSizeExpr(),
-                              VAT->getSizeModifier(),
-                              VAT->getIndexTypeQualifier(),
-                              VAT->getBracketsRange());
+  return CanQualType::CreateUnsafe(getVariableArrayType(NewEltTy,
+                                                        VAT->getSizeExpr(),
+                                                        VAT->getSizeModifier(),
+                                                  VAT->getIndexTypeQualifier(),
+                                                     VAT->getBracketsRange()));
 }
 
 TemplateName ASTContext::getCanonicalTemplateName(TemplateName Name) {
@@ -2250,7 +2255,7 @@
   
   // If we get here, we either have type qualifiers on the type, or we have
   // sugar such as a typedef in the way.  If we have type qualifiers on the type
-  // we must propagate them down into the elemeng type.
+  // we must propagate them down into the element type.
   unsigned CVRQuals = T.getCVRQualifiers();
   unsigned AddrSpace = 0;
   Type *Ty = T.getTypePtr();
diff --git a/lib/AST/DeclCXX.cpp b/lib/AST/DeclCXX.cpp
index ad015d1..52619e9 100644
--- a/lib/AST/DeclCXX.cpp
+++ b/lib/AST/DeclCXX.cpp
@@ -304,7 +304,8 @@
   QualType ClassType = Context.getTypeDeclType(this);
   
   DeclarationName Name 
-    = Context.DeclarationNames.getCXXDestructorName(ClassType);
+    = Context.DeclarationNames.getCXXDestructorName(
+                                          Context.getCanonicalType(ClassType));
 
   DeclContext::lookup_iterator I, E;
   llvm::tie(I, E) = lookup(Name); 
diff --git a/lib/AST/DeclarationName.cpp b/lib/AST/DeclarationName.cpp
index a55b363..da9f01a 100644
--- a/lib/AST/DeclarationName.cpp
+++ b/lib/AST/DeclarationName.cpp
@@ -298,12 +298,10 @@
 
 DeclarationName 
 DeclarationNameTable::getCXXSpecialName(DeclarationName::NameKind Kind, 
-                                        QualType Ty) {
+                                        CanQualType Ty) {
   assert(Kind >= DeclarationName::CXXConstructorName &&
          Kind <= DeclarationName::CXXConversionFunctionName &&
          "Kind must be a C++ special name kind");
-  assert(Ty->isCanonical() && 
-         "Can only build C++ special names from canonical types");
   llvm::FoldingSet<CXXSpecialName> *SpecialNames 
     = static_cast<llvm::FoldingSet<CXXSpecialName>*>(CXXSpecialNamesImpl);