Remove NDEBUG-controlled extra data from

TemplateArgumentLocInfo. Unfortunately, this means that we lose some
internal consistency checking when building a debug Clang. However,
having data structures change size/layout depending on NDEBUG causes
pain for clients of the Clang API.

llvm-svn: 120706
This commit is contained in:
Douglas Gregor 2010-12-02 16:14:14 +00:00
parent 9af3787244
commit 8cd9feb277
2 changed files with 5 additions and 91 deletions

View File

@ -283,42 +283,15 @@ private:
} Template;
};
#ifndef NDEBUG
enum Kind {
K_None,
K_TypeSourceInfo,
K_Expression,
K_Template
} Kind;
#endif
public:
TemplateArgumentLocInfo()
: Expression(0)
#ifndef NDEBUG
, Kind(K_None)
#endif
{}
TemplateArgumentLocInfo() : Expression(0) {}
TemplateArgumentLocInfo(TypeSourceInfo *TInfo)
: Declarator(TInfo)
#ifndef NDEBUG
, Kind(K_TypeSourceInfo)
#endif
{}
TemplateArgumentLocInfo(TypeSourceInfo *TInfo) : Declarator(TInfo) {}
TemplateArgumentLocInfo(Expr *E)
: Expression(E)
#ifndef NDEBUG
, Kind(K_Expression)
#endif
{}
TemplateArgumentLocInfo(Expr *E) : Expression(E) {}
TemplateArgumentLocInfo(SourceRange QualifierRange,
SourceLocation TemplateNameLoc)
#ifndef NDEBUG
: Kind(K_Template)
#endif
{
Template.QualifierRange[0] = QualifierRange.getBegin().getRawEncoding();
Template.QualifierRange[1] = QualifierRange.getEnd().getRawEncoding();
@ -326,49 +299,22 @@ public:
}
TypeSourceInfo *getAsTypeSourceInfo() const {
assert(Kind == K_TypeSourceInfo);
return Declarator;
}
Expr *getAsExpr() const {
assert(Kind == K_Expression);
return Expression;
}
SourceRange getTemplateQualifierRange() const {
assert(Kind == K_Template);
return SourceRange(
SourceLocation::getFromRawEncoding(Template.QualifierRange[0]),
SourceLocation::getFromRawEncoding(Template.QualifierRange[1]));
}
SourceLocation getTemplateNameLoc() const {
assert(Kind == K_Template);
return SourceLocation::getFromRawEncoding(Template.TemplateNameLoc);
}
#ifndef NDEBUG
void validateForArgument(const TemplateArgument &Arg) {
switch (Arg.getKind()) {
case TemplateArgument::Type:
assert(Kind == K_TypeSourceInfo);
break;
case TemplateArgument::Expression:
case TemplateArgument::Declaration:
assert(Kind == K_Expression);
break;
case TemplateArgument::Template:
assert(Kind == K_Template);
break;
case TemplateArgument::Integral:
case TemplateArgument::Pack:
assert(Kind == K_None);
break;
case TemplateArgument::Null:
llvm_unreachable("source info for null template argument?");
}
}
#endif
};
/// Location wrapper for a TemplateArgument. TemplateArgument is to

View File

@ -1013,9 +1013,6 @@ public:
return getTypePtr()->getNumArgs();
}
void setArgLocInfo(unsigned i, TemplateArgumentLocInfo AI) {
#ifndef NDEBUG
AI.validateForArgument(getTypePtr()->getArg(i));
#endif
getArgInfos()[i] = AI;
}
TemplateArgumentLocInfo getArgLocInfo(unsigned i) const {
@ -1061,34 +1058,8 @@ public:
const TemplateArgument *Args,
TemplateArgumentLocInfo *ArgInfos,
SourceLocation Loc) {
for (unsigned i = 0, e = NumArgs; i != e; ++i) {
TemplateArgumentLocInfo Info;
#ifndef NDEBUG
// If asserts are enabled, be sure to initialize the argument
// loc with the right kind of pointer.
switch (Args[i].getKind()) {
case TemplateArgument::Expression:
case TemplateArgument::Declaration:
Info = TemplateArgumentLocInfo((Expr*) 0);
break;
case TemplateArgument::Type:
Info = TemplateArgumentLocInfo((TypeSourceInfo*) 0);
break;
case TemplateArgument::Template:
Info = TemplateArgumentLocInfo(SourceRange(Loc), Loc);
break;
case TemplateArgument::Integral:
case TemplateArgument::Pack:
case TemplateArgument::Null:
// K_None is fine.
break;
}
#endif
ArgInfos[i] = Info;
}
for (unsigned i = 0, e = NumArgs; i != e; ++i)
ArgInfos[i] = TemplateArgumentLocInfo();
}
unsigned getExtraLocalDataSize() const {
@ -1384,9 +1355,6 @@ public:
}
void setArgLocInfo(unsigned i, TemplateArgumentLocInfo AI) {
#ifndef NDEBUG
AI.validateForArgument(getTypePtr()->getArg(i));
#endif
getArgInfos()[i] = AI;
}
TemplateArgumentLocInfo getArgLocInfo(unsigned i) const {