[cfe-commits] PATCH: Set TypeSourceInfo for TemplateArgumentLoc
Craig Silverstein
csilvers2000 at yahoo.com
Wed Nov 17 23:31:09 PST 2010
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! Look ok to commit?
craig
--cut here--
====
//depot/google3/third_party/llvm/trunk/tools/clang/include/clang/AST/TypeLoc.h#19
-
/home/csilvers/src/google3/third_party/llvm/trunk/tools/clang/include/clang/AST/TypeLoc.h
====
---
/tmp/g4-500/cache/depot/google3/third_party/llvm/trunk/tools/clang/include/clang/AST/TypeLoc.h#19
2010-10-11 17:50:05.000000000 -0700
+++
/home/csilvers/src/google3/third_party/llvm/trunk/tools/clang/include/clang/AST/TypeLoc.h
2010-11-17 22:19:32.884761000 -0800
@@ -124,6 +124,12 @@
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 @@
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);
};
====
//depot/google3/third_party/llvm/trunk/tools/clang/include/clang/Sema/Sema.h#17
-
/home/csilvers/src/google3/third_party/llvm/trunk/tools/clang/include/clang/Sema/Sema.h
====
---
/tmp/g4-500/cache/depot/google3/third_party/llvm/trunk/tools/clang/include/clang/Sema/Sema.h#17
2010-11-17 00:24:59.000000000 -0800
+++
/home/csilvers/src/google3/third_party/llvm/trunk/tools/clang/include/clang/Sema/Sema.h
2010-11-17 20:26:49.711250000 -0800
@@ -2859,10 +2859,11 @@
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,
==== //depot/google3/third_party/llvm/trunk/tools/clang/lib/AST/TypeLoc.cpp#7 -
/home/csilvers/src/google3/third_party/llvm/trunk/tools/clang/lib/AST/TypeLoc.cpp
====
---
/tmp/g4-500/cache/depot/google3/third_party/llvm/trunk/tools/clang/lib/AST/TypeLoc.cpp#7
2010-08-17 18:20:07.000000000 -0700
+++
/home/csilvers/src/google3/third_party/llvm/trunk/tools/clang/lib/AST/TypeLoc.cpp
2010-11-17 22:30:45.217658000 -0800
@@ -94,6 +94,13 @@
}
}
+/// \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) {
====
//depot/google3/third_party/llvm/trunk/tools/clang/lib/Parse/ParseDeclCXX.cpp#45
-
/home/csilvers/src/google3/third_party/llvm/trunk/tools/clang/lib/Parse/ParseDeclCXX.cpp
====
---
/tmp/g4-500/cache/depot/google3/third_party/llvm/trunk/tools/clang/lib/Parse/ParseDeclCXX.cpp#45
2010-11-11 12:44:44.000000000 -0800
+++
/home/csilvers/src/google3/third_party/llvm/trunk/tools/clang/lib/Parse/ParseDeclCXX.cpp
2010-11-17 20:29:34.885201000 -0800
@@ -908,7 +908,7 @@
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
====
//depot/google3/third_party/llvm/trunk/tools/clang/lib/Sema/SemaTemplate.cpp#60
-
/home/csilvers/src/google3/third_party/llvm/trunk/tools/clang/lib/Sema/SemaTemplate.cpp
====
---
/tmp/g4-500/cache/depot/google3/third_party/llvm/trunk/tools/clang/lib/Sema/SemaTemplate.cpp#60
2010-11-16 01:57:59.000000000 -0800
+++
/home/csilvers/src/google3/third_party/llvm/trunk/tools/clang/lib/Sema/SemaTemplate.cpp
2010-11-17 22:38:22.391580000 -0800
@@ -1646,14 +1646,14 @@
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 @@
= 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,
More information about the cfe-commits
mailing list