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

llvm-svn: 119697
This commit is contained in:
Craig Silverstein 2010-11-18 08:32:02 +00:00
parent 1385dff8c0
commit 9bc166ac86
5 changed files with 28 additions and 8 deletions

View File

@ -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);
};

View File

@ -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,

View File

@ -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) {

View File

@ -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

View File

@ -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<ElaboratedTypeLoc>(ElabDI->getTypeLoc());
TL.setKeywordLoc(TagLoc);
TL.setQualifierRange(SS.getRange());
TL.getNamedTypeLoc().initializeFullCopy(DI->getTypeLoc());
return CreateParsedType(ElabType, ElabDI);
}
ExprResult Sema::BuildTemplateIdExpr(const CXXScopeSpec &SS,