From: Douglas Gregor Date: Thu, 6 Jan 2011 00:33:28 +0000 (+0000) Subject: When default-initializing a TemplateArgumentLocInfo, make sure that we X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b0ddf3aeb2f119cac42468b029584e8839b354cc;p=clang When default-initializing a TemplateArgumentLocInfo, make sure that we initialize *all* of the bits to zero. Also, when the pattern of a template argument pack expansion, make sure to set the ellipsis location along all paths. This should clear up the valgrind failure that popped up in Clang. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@122931 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/TemplateBase.h b/include/clang/AST/TemplateBase.h index 7f3e591a96..22ca164d38 100644 --- a/include/clang/AST/TemplateBase.h +++ b/include/clang/AST/TemplateBase.h @@ -330,7 +330,7 @@ private: }; public: - TemplateArgumentLocInfo() : Expression(0) {} + TemplateArgumentLocInfo(); TemplateArgumentLocInfo(TypeSourceInfo *TInfo) : Declarator(TInfo) {} diff --git a/include/clang/AST/TypeLoc.h b/include/clang/AST/TypeLoc.h index 81ece1799b..3480681fe1 100644 --- a/include/clang/AST/TypeLoc.h +++ b/include/clang/AST/TypeLoc.h @@ -1115,8 +1115,11 @@ public: const TemplateArgument *Args, TemplateArgumentLocInfo *ArgInfos, SourceLocation Loc) { - for (unsigned i = 0, e = NumArgs; i != e; ++i) + for (unsigned i = 0, e = NumArgs; i != e; ++i) { + // FIXME: We can generate better location info here for type arguments, + // template template arguments, and template template pack expansions (?). ArgInfos[i] = TemplateArgumentLocInfo(); + } } unsigned getExtraLocalDataSize() const { diff --git a/lib/AST/TemplateBase.cpp b/lib/AST/TemplateBase.cpp index de5531f0f7..68e23323ce 100644 --- a/lib/AST/TemplateBase.cpp +++ b/lib/AST/TemplateBase.cpp @@ -292,6 +292,10 @@ void TemplateArgument::print(const PrintingPolicy &Policy, // TemplateArgumentLoc Implementation //===----------------------------------------------------------------------===// +TemplateArgumentLocInfo::TemplateArgumentLocInfo() { + memset(this, 0, sizeof(TemplateArgumentLocInfo)); +} + SourceRange TemplateArgumentLoc::getSourceRange() const { switch (Argument.getKind()) { case TemplateArgument::Expression: @@ -362,11 +366,15 @@ TemplateArgumentLoc::getPackExpansionPattern(SourceLocation &Ellipsis, } case TemplateArgument::Expression: { - Expr *Pattern = cast(Argument.getAsExpr())->getPattern(); + PackExpansionExpr *Expansion + = cast(Argument.getAsExpr()); + Expr *Pattern = Expansion->getPattern(); + Ellipsis = Expansion->getEllipsisLoc(); return TemplateArgumentLoc(Pattern, Pattern); } case TemplateArgument::TemplateExpansion: + Ellipsis = getTemplateEllipsisLoc(); return TemplateArgumentLoc(Argument.getPackExpansionPattern(), getTemplateQualifierRange(), getTemplateNameLoc());