diff options
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/include/clang/AST/ASTContext.h | 6 | ||||
| -rw-r--r-- | clang/lib/AST/ASTContext.cpp | 81 | ||||
| -rw-r--r-- | clang/lib/Frontend/PCHReader.cpp | 17 | ||||
| -rw-r--r-- | clang/lib/Frontend/PCHWriter.cpp | 7 | 
4 files changed, 66 insertions, 45 deletions
diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index 3ccdede8e6d..b3545e8192e 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -614,7 +614,7 @@ public:    /// getTypedefType - Return the unique reference to the type for the    /// specified typename decl. -  QualType getTypedefType(const TypedefDecl *Decl); +  QualType getTypedefType(const TypedefDecl *Decl, QualType Canon = QualType());    QualType getInjectedClassNameType(CXXRecordDecl *Decl, QualType TST); @@ -630,6 +630,10 @@ public:                                           unsigned NumArgs,                                           QualType Canon = QualType()); +  QualType getCanonicalTemplateSpecializationType(TemplateName T, +                                                  const TemplateArgument *Args, +                                                  unsigned NumArgs); +    QualType getTemplateSpecializationType(TemplateName T,                                           const TemplateArgumentListInfo &Args,                                           QualType Canon = QualType()); diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 0be1778260b..604cf2b5cfd 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -1787,10 +1787,12 @@ QualType ASTContext::getTypeDeclTypeSlow(const TypeDecl *Decl) {  /// getTypedefType - Return the unique reference to the type for the  /// specified typename decl. -QualType ASTContext::getTypedefType(const TypedefDecl *Decl) { +QualType +ASTContext::getTypedefType(const TypedefDecl *Decl, QualType Canonical) {    if (Decl->TypeForDecl) return QualType(Decl->TypeForDecl, 0); -  QualType Canonical = getCanonicalType(Decl->getUnderlyingType()); +  if (Canonical.isNull()) +    Canonical = getCanonicalType(Decl->getUnderlyingType());    Decl->TypeForDecl = new(*this, TypeAlignment)      TypedefType(Type::Typedef, Decl, Canonical);    Types.push_back(Decl->TypeForDecl); @@ -1894,41 +1896,8 @@ ASTContext::getTemplateSpecializationType(TemplateName Template,                                            QualType Canon) {    if (!Canon.isNull())      Canon = getCanonicalType(Canon); -  else { -    // Build the canonical template specialization type. -    TemplateName CanonTemplate = getCanonicalTemplateName(Template); -    llvm::SmallVector<TemplateArgument, 4> CanonArgs; -    CanonArgs.reserve(NumArgs); -    for (unsigned I = 0; I != NumArgs; ++I) -      CanonArgs.push_back(getCanonicalTemplateArgument(Args[I])); - -    // Determine whether this canonical template specialization type already -    // exists. -    llvm::FoldingSetNodeID ID; -    TemplateSpecializationType::Profile(ID, CanonTemplate, -                                        CanonArgs.data(), NumArgs, *this); - -    void *InsertPos = 0; -    TemplateSpecializationType *Spec -      = TemplateSpecializationTypes.FindNodeOrInsertPos(ID, InsertPos); - -    if (!Spec) { -      // Allocate a new canonical template specialization type. -      void *Mem = Allocate((sizeof(TemplateSpecializationType) + -                            sizeof(TemplateArgument) * NumArgs), -                           TypeAlignment); -      Spec = new (Mem) TemplateSpecializationType(CanonTemplate, -                                                  CanonArgs.data(), NumArgs, -                                                  Canon); -      Types.push_back(Spec); -      TemplateSpecializationTypes.InsertNode(Spec, InsertPos); -    } - -    if (Canon.isNull()) -      Canon = QualType(Spec, 0); -    assert(Canon->isDependentType() && -           "Non-dependent template-id type must have a canonical type"); -  } +  else +    Canon = getCanonicalTemplateSpecializationType(Template, Args, NumArgs);    // Allocate the (non-canonical) template specialization type, but don't    // try to unique it: these types typically have location information that @@ -1946,6 +1915,44 @@ ASTContext::getTemplateSpecializationType(TemplateName Template,  }  QualType +ASTContext::getCanonicalTemplateSpecializationType(TemplateName Template, +                                                   const TemplateArgument *Args, +                                                   unsigned NumArgs) { +  // Build the canonical template specialization type. +  TemplateName CanonTemplate = getCanonicalTemplateName(Template); +  llvm::SmallVector<TemplateArgument, 4> CanonArgs; +  CanonArgs.reserve(NumArgs); +  for (unsigned I = 0; I != NumArgs; ++I) +    CanonArgs.push_back(getCanonicalTemplateArgument(Args[I])); + +  // Determine whether this canonical template specialization type already +  // exists. +  llvm::FoldingSetNodeID ID; +  TemplateSpecializationType::Profile(ID, CanonTemplate, +                                      CanonArgs.data(), NumArgs, *this); + +  void *InsertPos = 0; +  TemplateSpecializationType *Spec +    = TemplateSpecializationTypes.FindNodeOrInsertPos(ID, InsertPos); + +  if (!Spec) { +    // Allocate a new canonical template specialization type. +    void *Mem = Allocate((sizeof(TemplateSpecializationType) + +                          sizeof(TemplateArgument) * NumArgs), +                         TypeAlignment); +    Spec = new (Mem) TemplateSpecializationType(CanonTemplate, +                                                CanonArgs.data(), NumArgs, +                                                QualType()); +    Types.push_back(Spec); +    TemplateSpecializationTypes.InsertNode(Spec, InsertPos); +  } + +  assert(Spec->isDependentType() && +         "Non-dependent template-id type must have a canonical type"); +  return QualType(Spec, 0); +} + +QualType  ASTContext::getElaboratedType(ElaboratedTypeKeyword Keyword,                                NestedNameSpecifier *NNS,                                QualType NamedType) { diff --git a/clang/lib/Frontend/PCHReader.cpp b/clang/lib/Frontend/PCHReader.cpp index be763d51ca9..330cd9a5c62 100644 --- a/clang/lib/Frontend/PCHReader.cpp +++ b/clang/lib/Frontend/PCHReader.cpp @@ -2116,12 +2116,15 @@ QualType PCHReader::ReadTypeRecord(uint64_t Offset) {      return Context->getTypeDeclType(               cast<UnresolvedUsingTypenameDecl>(GetDecl(Record[0]))); -  case pch::TYPE_TYPEDEF: -    if (Record.size() != 1) { +  case pch::TYPE_TYPEDEF: { +    if (Record.size() != 2) {        Error("incorrect encoding of typedef type");        return QualType();      } -    return Context->getTypeDeclType(cast<TypedefDecl>(GetDecl(Record[0]))); +    TypedefDecl *Decl = cast<TypedefDecl>(GetDecl(Record[0])); +    QualType Canonical = GetType(Record[1]); +    return Context->getTypedefType(Decl, Canonical); +  }    case pch::TYPE_TYPEOF_EXPR:      return Context->getTypeOfExprType(ReadExpr()); @@ -2251,8 +2254,12 @@ QualType PCHReader::ReadTypeRecord(uint64_t Offset) {      llvm::SmallVector<TemplateArgument, 8> Args;      ReadTemplateArgumentList(Args, Record, Idx);      QualType Canon = GetType(Record[Idx++]); -    return Context->getTemplateSpecializationType(Name, Args.data(),Args.size(), -                                                  Canon); +    if (Canon.isNull()) +      return Context->getCanonicalTemplateSpecializationType(Name, Args.data(), +                                                             Args.size()); +    else +      return Context->getTemplateSpecializationType(Name, Args.data(), +                                                    Args.size(), Canon);    }    }    // Suppress a GCC warning diff --git a/clang/lib/Frontend/PCHWriter.cpp b/clang/lib/Frontend/PCHWriter.cpp index 41815314d79..f91f76c1b44 100644 --- a/clang/lib/Frontend/PCHWriter.cpp +++ b/clang/lib/Frontend/PCHWriter.cpp @@ -173,6 +173,8 @@ void PCHTypeWriter::VisitUnresolvedUsingType(const UnresolvedUsingType *T) {  void PCHTypeWriter::VisitTypedefType(const TypedefType *T) {    Writer.AddDeclRef(T->getDecl(), Record); +  assert(!T->isCanonicalUnqualified() && "Invalid typedef ?"); +  Writer.AddTypeRef(T->getCanonicalTypeInternal(), Record);    Code = pch::TYPE_TYPEDEF;  } @@ -223,8 +225,9 @@ PCHTypeWriter::VisitTemplateSpecializationType(    for (TemplateSpecializationType::iterator ArgI = T->begin(), ArgE = T->end();           ArgI != ArgE; ++ArgI)      Writer.AddTemplateArgument(*ArgI, Record); -  QualType Canon = T->getCanonicalTypeInternal(); -  Writer.AddTypeRef(Canon.getTypePtr() != T ? Canon : QualType(), Record); +  Writer.AddTypeRef(T->isCanonicalUnqualified() ? QualType() +                                                : T->getCanonicalTypeInternal(), +                    Record);    Code = pch::TYPE_TEMPLATE_SPECIALIZATION;  }  | 

