From 45ab4b5f8961dadcef6545ed6956da5daf95c6cb Mon Sep 17 00:00:00 2001 From: Craig Silverstein Date: Thu, 18 Nov 2010 08:32:02 +0000 Subject: [PATCH] In some situations, TemplateArgumentLoc wasn't setting TypeSourceLoc (see http://llvm.org/bugs/show_bug.cgi?id=8558). This patch fixes it. Thanks to rjmccall for all the coaching! Approved by rjmccall git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@119697 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/TypeLoc.h | 7 +++++++ include/clang/Sema/Sema.h | 9 +++++---- lib/AST/TypeLoc.cpp | 7 +++++++ lib/Parse/ParseDeclCXX.cpp | 2 +- lib/Sema/SemaTemplate.cpp | 11 ++++++++--- 5 files changed, 28 insertions(+), 8 deletions(-) diff --git a/include/clang/AST/TypeLoc.h b/include/clang/AST/TypeLoc.h index 35bba03d77..a290017076 100644 --- a/include/clang/AST/TypeLoc.h +++ b/include/clang/AST/TypeLoc.h @@ -124,6 +124,12 @@ public: initializeImpl(*this, Loc); } + /// \brief Initializes this by copying its information from another + /// TypeLoc of the same type. + void initializeFullCopy(TypeLoc Other) const { + initializeFullCopyImpl(*this, Other); + } + friend bool operator==(const TypeLoc &LHS, const TypeLoc &RHS) { return LHS.Ty == RHS.Ty && LHS.Data == RHS.Data; } @@ -136,6 +142,7 @@ public: private: static void initializeImpl(TypeLoc TL, SourceLocation Loc); + static void initializeFullCopyImpl(TypeLoc TL, TypeLoc Other); static TypeLoc getNextTypeLocImpl(TypeLoc TL); static SourceRange getLocalSourceRangeImpl(TypeLoc TL); }; diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index 26c775fcfa..aa3d790b8e 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -2869,10 +2869,11 @@ public: ASTTemplateArgsPtr TemplateArgs, SourceLocation RAngleLoc); - TypeResult ActOnTagTemplateIdType(TypeResult Type, - TagUseKind TUK, - TypeSpecifierType TagSpec, - SourceLocation TagLoc); + TypeResult ActOnTagTemplateIdType(CXXScopeSpec &SS, + TypeResult Type, + TagUseKind TUK, + TypeSpecifierType TagSpec, + SourceLocation TagLoc); ExprResult BuildTemplateIdExpr(const CXXScopeSpec &SS, LookupResult &R, diff --git a/lib/AST/TypeLoc.cpp b/lib/AST/TypeLoc.cpp index 66578fb3dc..0ba9fc0087 100644 --- a/lib/AST/TypeLoc.cpp +++ b/lib/AST/TypeLoc.cpp @@ -94,6 +94,13 @@ void TypeLoc::initializeImpl(TypeLoc TL, SourceLocation Loc) { } } +/// \brief Initializes a type location by copying all its data from +/// another type location of the same type. +void TypeLoc::initializeFullCopyImpl(TypeLoc TL, TypeLoc Other) { + assert(TL.getType() == Other.getType() && "Must copy from same type"); + memcpy(TL.getOpaqueData(), Other.getOpaqueData(), TL.getFullDataSize()); +} + SourceLocation TypeLoc::getBeginLoc() const { TypeLoc Cur = *this; while (true) { diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp index 140f149101..1bc5815f21 100644 --- a/lib/Parse/ParseDeclCXX.cpp +++ b/lib/Parse/ParseDeclCXX.cpp @@ -908,7 +908,7 @@ void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind, TemplateArgsPtr, TemplateId->RAngleLoc); - TypeResult = Actions.ActOnTagTemplateIdType(TypeResult, TUK, + TypeResult = Actions.ActOnTagTemplateIdType(SS, TypeResult, TUK, TagType, StartLoc); } else { // This is an explicit specialization or a class template diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index 4c25bc32df..daa1e726a0 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -1646,14 +1646,14 @@ Sema::ActOnTemplateIdType(TemplateTy TemplateD, SourceLocation TemplateLoc, return CreateParsedType(Result, DI); } -TypeResult Sema::ActOnTagTemplateIdType(TypeResult TypeResult, +TypeResult Sema::ActOnTagTemplateIdType(CXXScopeSpec &SS, + TypeResult TypeResult, TagUseKind TUK, TypeSpecifierType TagSpec, SourceLocation TagLoc) { if (TypeResult.isInvalid()) return ::TypeResult(); - // FIXME: preserve source info, ideally without copying the DI. TypeSourceInfo *DI; QualType Type = GetTypeFromParser(TypeResult.get(), &DI); @@ -1678,7 +1678,12 @@ TypeResult Sema::ActOnTagTemplateIdType(TypeResult TypeResult, = TypeWithKeyword::getKeywordForTagTypeKind(TagKind); QualType ElabType = Context.getElaboratedType(Keyword, /*NNS=*/0, Type); - return ParsedType::make(ElabType); + TypeSourceInfo *ElabDI = Context.CreateTypeSourceInfo(ElabType); + ElaboratedTypeLoc TL = cast(ElabDI->getTypeLoc()); + TL.setKeywordLoc(TagLoc); + TL.setQualifierRange(SS.getRange()); + TL.getNamedTypeLoc().initializeFullCopy(DI->getTypeLoc()); + return CreateParsedType(ElabType, ElabDI); } ExprResult Sema::BuildTemplateIdExpr(const CXXScopeSpec &SS, -- 2.40.0