PR13552: Fix the end location of a CXXNewExpr.

Spent longer than reasonable looking for a nice way to test this & decided to
give up for now. Open to suggestions/requests. Richard Smith suggested adding
something to ASTMatchers but it wasn't readily apparent how to test this with
that.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@167507 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
David Blaikie 2012-11-07 00:12:38 +00:00
Родитель 70a0189800
Коммит 530564196f
6 изменённых файлов: 15 добавлений и 26 удалений

Просмотреть файл

@ -1463,8 +1463,8 @@ class CXXNewExpr : public Expr {
/// the source range covering the parenthesized type-id. /// the source range covering the parenthesized type-id.
SourceRange TypeIdParens; SourceRange TypeIdParens;
/// \brief Location of the first token. /// \brief Range of the entire new expression.
SourceLocation StartLoc; SourceRange Range;
/// \brief Source-range of a paren-delimited initializer. /// \brief Source-range of a paren-delimited initializer.
SourceRange DirectInitRange; SourceRange DirectInitRange;
@ -1498,7 +1498,7 @@ public:
SourceRange typeIdParens, Expr *arraySize, SourceRange typeIdParens, Expr *arraySize,
InitializationStyle initializationStyle, Expr *initializer, InitializationStyle initializationStyle, Expr *initializer,
QualType ty, TypeSourceInfo *AllocatedTypeInfo, QualType ty, TypeSourceInfo *AllocatedTypeInfo,
SourceLocation startLoc, SourceRange directInitRange); SourceRange Range, SourceRange directInitRange);
explicit CXXNewExpr(EmptyShell Shell) explicit CXXNewExpr(EmptyShell Shell)
: Expr(CXXNewExprClass, Shell), SubExprs(0) { } : Expr(CXXNewExprClass, Shell), SubExprs(0) { }
@ -1613,13 +1613,13 @@ public:
return SubExprs + Array + hasInitializer() + getNumPlacementArgs(); return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
} }
SourceLocation getStartLoc() const { return StartLoc; } SourceLocation getStartLoc() const { return Range.getBegin(); }
SourceLocation getEndLoc() const; SourceLocation getEndLoc() const { return Range.getEnd(); }
SourceRange getDirectInitRange() const { return DirectInitRange; } SourceRange getDirectInitRange() const { return DirectInitRange; }
SourceRange getSourceRange() const LLVM_READONLY { SourceRange getSourceRange() const LLVM_READONLY {
return SourceRange(getStartLoc(), getEndLoc()); return Range;
} }
static bool classof(const Stmt *T) { static bool classof(const Stmt *T) {

Просмотреть файл

@ -3762,7 +3762,7 @@ public:
SourceLocation PlacementRParen, SourceLocation PlacementRParen,
SourceRange TypeIdParens, Declarator &D, SourceRange TypeIdParens, Declarator &D,
Expr *Initializer); Expr *Initializer);
ExprResult BuildCXXNew(SourceLocation StartLoc, bool UseGlobal, ExprResult BuildCXXNew(SourceRange Range, bool UseGlobal,
SourceLocation PlacementLParen, SourceLocation PlacementLParen,
MultiExprArg PlacementArgs, MultiExprArg PlacementArgs,
SourceLocation PlacementRParen, SourceLocation PlacementRParen,

Просмотреть файл

@ -88,14 +88,14 @@ CXXNewExpr::CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew,
InitializationStyle initializationStyle, InitializationStyle initializationStyle,
Expr *initializer, QualType ty, Expr *initializer, QualType ty,
TypeSourceInfo *allocatedTypeInfo, TypeSourceInfo *allocatedTypeInfo,
SourceLocation startLoc, SourceRange directInitRange) SourceRange Range, SourceRange directInitRange)
: Expr(CXXNewExprClass, ty, VK_RValue, OK_Ordinary, : Expr(CXXNewExprClass, ty, VK_RValue, OK_Ordinary,
ty->isDependentType(), ty->isDependentType(), ty->isDependentType(), ty->isDependentType(),
ty->isInstantiationDependentType(), ty->isInstantiationDependentType(),
ty->containsUnexpandedParameterPack()), ty->containsUnexpandedParameterPack()),
SubExprs(0), OperatorNew(operatorNew), OperatorDelete(operatorDelete), SubExprs(0), OperatorNew(operatorNew), OperatorDelete(operatorDelete),
AllocatedTypeInfo(allocatedTypeInfo), TypeIdParens(typeIdParens), AllocatedTypeInfo(allocatedTypeInfo), TypeIdParens(typeIdParens),
StartLoc(startLoc), DirectInitRange(directInitRange), Range(Range), DirectInitRange(directInitRange),
GlobalNew(globalNew), UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize) { GlobalNew(globalNew), UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize) {
assert((initializer != 0 || initializationStyle == NoInit) && assert((initializer != 0 || initializationStyle == NoInit) &&
"Only NoInit can have no initializer."); "Only NoInit can have no initializer.");
@ -147,18 +147,6 @@ bool CXXNewExpr::shouldNullCheckAllocation(ASTContext &Ctx) const {
castAs<FunctionProtoType>()->isNothrow(Ctx); castAs<FunctionProtoType>()->isNothrow(Ctx);
} }
SourceLocation CXXNewExpr::getEndLoc() const {
switch (getInitializationStyle()) {
case NoInit:
return AllocatedTypeInfo->getTypeLoc().getEndLoc();
case CallInit:
return DirectInitRange.getEnd();
case ListInit:
return getInitializer()->getSourceRange().getEnd();
}
llvm_unreachable("bogus initialization style");
}
// CXXDeleteExpr // CXXDeleteExpr
QualType CXXDeleteExpr::getDestroyedType() const { QualType CXXDeleteExpr::getDestroyedType() const {
const Expr *Arg = getArgument(); const Expr *Arg = getArgument();

Просмотреть файл

@ -987,7 +987,7 @@ Sema::ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal,
if (ParenListExpr *List = dyn_cast_or_null<ParenListExpr>(Initializer)) if (ParenListExpr *List = dyn_cast_or_null<ParenListExpr>(Initializer))
DirectInitRange = List->getSourceRange(); DirectInitRange = List->getSourceRange();
return BuildCXXNew(StartLoc, UseGlobal, return BuildCXXNew(SourceRange(StartLoc, D.getLocEnd()), UseGlobal,
PlacementLParen, PlacementLParen,
PlacementArgs, PlacementArgs,
PlacementRParen, PlacementRParen,
@ -1020,7 +1020,7 @@ static bool isLegalArrayNewInitializer(CXXNewExpr::InitializationStyle Style,
} }
ExprResult ExprResult
Sema::BuildCXXNew(SourceLocation StartLoc, bool UseGlobal, Sema::BuildCXXNew(SourceRange Range, bool UseGlobal,
SourceLocation PlacementLParen, SourceLocation PlacementLParen,
MultiExprArg PlacementArgs, MultiExprArg PlacementArgs,
SourceLocation PlacementRParen, SourceLocation PlacementRParen,
@ -1032,6 +1032,7 @@ Sema::BuildCXXNew(SourceLocation StartLoc, bool UseGlobal,
Expr *Initializer, Expr *Initializer,
bool TypeMayContainAuto) { bool TypeMayContainAuto) {
SourceRange TypeRange = AllocTypeInfo->getTypeLoc().getSourceRange(); SourceRange TypeRange = AllocTypeInfo->getTypeLoc().getSourceRange();
SourceLocation StartLoc = Range.getBegin();
CXXNewExpr::InitializationStyle initStyle; CXXNewExpr::InitializationStyle initStyle;
if (DirectInitRange.isValid()) { if (DirectInitRange.isValid()) {
@ -1407,7 +1408,7 @@ Sema::BuildCXXNew(SourceLocation StartLoc, bool UseGlobal,
TypeIdParens, TypeIdParens,
ArraySize, initStyle, Initializer, ArraySize, initStyle, Initializer,
ResultType, AllocTypeInfo, ResultType, AllocTypeInfo,
StartLoc, DirectInitRange)); Range, DirectInitRange));
} }
/// \brief Checks that a type is suitable as the allocated type /// \brief Checks that a type is suitable as the allocated type

Просмотреть файл

@ -1243,7 +1243,7 @@ void ASTStmtReader::VisitCXXNewExpr(CXXNewExpr *E) {
E->setOperatorDelete(ReadDeclAs<FunctionDecl>(Record, Idx)); E->setOperatorDelete(ReadDeclAs<FunctionDecl>(Record, Idx));
E->AllocatedTypeInfo = GetTypeSourceInfo(Record, Idx); E->AllocatedTypeInfo = GetTypeSourceInfo(Record, Idx);
E->TypeIdParens = ReadSourceRange(Record, Idx); E->TypeIdParens = ReadSourceRange(Record, Idx);
E->StartLoc = ReadSourceLocation(Record, Idx); E->Range = ReadSourceRange(Record, Idx);
E->DirectInitRange = ReadSourceRange(Record, Idx); E->DirectInitRange = ReadSourceRange(Record, Idx);
E->AllocateArgsArray(Reader.getContext(), isArray, NumPlacementArgs, E->AllocateArgsArray(Reader.getContext(), isArray, NumPlacementArgs,

Просмотреть файл

@ -1236,7 +1236,7 @@ void ASTStmtWriter::VisitCXXNewExpr(CXXNewExpr *E) {
Writer.AddDeclRef(E->getOperatorDelete(), Record); Writer.AddDeclRef(E->getOperatorDelete(), Record);
Writer.AddTypeSourceInfo(E->getAllocatedTypeSourceInfo(), Record); Writer.AddTypeSourceInfo(E->getAllocatedTypeSourceInfo(), Record);
Writer.AddSourceRange(E->getTypeIdParens(), Record); Writer.AddSourceRange(E->getTypeIdParens(), Record);
Writer.AddSourceLocation(E->getStartLoc(), Record); Writer.AddSourceRange(E->getSourceRange(), Record);
Writer.AddSourceRange(E->getDirectInitRange(), Record); Writer.AddSourceRange(E->getDirectInitRange(), Record);
for (CXXNewExpr::arg_iterator I = E->raw_arg_begin(), e = E->raw_arg_end(); for (CXXNewExpr::arg_iterator I = E->raw_arg_begin(), e = E->raw_arg_end();
I != e; ++I) I != e; ++I)