[cfe-commits] r167507 - in /cfe/trunk: include/clang/AST/ExprCXX.h include/clang/Sema/Sema.h lib/AST/ExprCXX.cpp lib/Sema/SemaExprCXX.cpp lib/Serialization/ASTReaderStmt.cpp lib/Serialization/ASTWriterStmt.cpp

David Blaikie dblaikie at gmail.com
Wed Nov 7 09:20:54 PST 2012


> Here is a patch for a unit test. Please commit it if it is okay.

That's great - thanks for the help (I was erroneously looking in the
ASTMatcher tests instead of the AST tests when I went searching for a
way to test this). Committed in r167538 (with a minor tweak - naming
the test "ArrayRange" rather than just "Range" to make it clear what
specific case it was testing).

For future reference it's usually easier if you send svn style patches
(that can be applied with patch -p0) than git style a/b/ patches. You
can change your git config to do this by default with:

[diff]
        noprefix = true

> On Wed, Nov 7, 2012 at 10:12 AM, David Blaikie <dblaikie at gmail.com> wrote:
>> Author: dblaikie
>> Date: Tue Nov  6 18:12:38 2012
>> New Revision: 167507
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=167507&view=rev
>> Log:
>> 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.
>>
>> Modified:
>>     cfe/trunk/include/clang/AST/ExprCXX.h
>>     cfe/trunk/include/clang/Sema/Sema.h
>>     cfe/trunk/lib/AST/ExprCXX.cpp
>>     cfe/trunk/lib/Sema/SemaExprCXX.cpp
>>     cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
>>     cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
>>
>> Modified: cfe/trunk/include/clang/AST/ExprCXX.h
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprCXX.h?rev=167507&r1=167506&r2=167507&view=diff
>> ==============================================================================
>> --- cfe/trunk/include/clang/AST/ExprCXX.h (original)
>> +++ cfe/trunk/include/clang/AST/ExprCXX.h Tue Nov  6 18:12:38 2012
>> @@ -1463,8 +1463,8 @@
>>    /// the source range covering the parenthesized type-id.
>>    SourceRange TypeIdParens;
>>
>> -  /// \brief Location of the first token.
>> -  SourceLocation StartLoc;
>> +  /// \brief Range of the entire new expression.
>> +  SourceRange Range;
>>
>>    /// \brief Source-range of a paren-delimited initializer.
>>    SourceRange DirectInitRange;
>> @@ -1498,7 +1498,7 @@
>>               SourceRange typeIdParens, Expr *arraySize,
>>               InitializationStyle initializationStyle, Expr *initializer,
>>               QualType ty, TypeSourceInfo *AllocatedTypeInfo,
>> -             SourceLocation startLoc, SourceRange directInitRange);
>> +             SourceRange Range, SourceRange directInitRange);
>>    explicit CXXNewExpr(EmptyShell Shell)
>>      : Expr(CXXNewExprClass, Shell), SubExprs(0) { }
>>
>> @@ -1613,13 +1613,13 @@
>>      return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
>>    }
>>
>> -  SourceLocation getStartLoc() const { return StartLoc; }
>> -  SourceLocation getEndLoc() const;
>> +  SourceLocation getStartLoc() const { return Range.getBegin(); }
>> +  SourceLocation getEndLoc() const { return Range.getEnd(); }
>>
>>    SourceRange getDirectInitRange() const { return DirectInitRange; }
>>
>>    SourceRange getSourceRange() const LLVM_READONLY {
>> -    return SourceRange(getStartLoc(), getEndLoc());
>> +    return Range;
>>    }
>>
>>    static bool classof(const Stmt *T) {
>>
>> Modified: cfe/trunk/include/clang/Sema/Sema.h
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=167507&r1=167506&r2=167507&view=diff
>> ==============================================================================
>> --- cfe/trunk/include/clang/Sema/Sema.h (original)
>> +++ cfe/trunk/include/clang/Sema/Sema.h Tue Nov  6 18:12:38 2012
>> @@ -3762,7 +3762,7 @@
>>                           SourceLocation PlacementRParen,
>>                           SourceRange TypeIdParens, Declarator &D,
>>                           Expr *Initializer);
>> -  ExprResult BuildCXXNew(SourceLocation StartLoc, bool UseGlobal,
>> +  ExprResult BuildCXXNew(SourceRange Range, bool UseGlobal,
>>                           SourceLocation PlacementLParen,
>>                           MultiExprArg PlacementArgs,
>>                           SourceLocation PlacementRParen,
>>
>> Modified: cfe/trunk/lib/AST/ExprCXX.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprCXX.cpp?rev=167507&r1=167506&r2=167507&view=diff
>> ==============================================================================
>> --- cfe/trunk/lib/AST/ExprCXX.cpp (original)
>> +++ cfe/trunk/lib/AST/ExprCXX.cpp Tue Nov  6 18:12:38 2012
>> @@ -88,14 +88,14 @@
>>                         InitializationStyle initializationStyle,
>>                         Expr *initializer, QualType ty,
>>                         TypeSourceInfo *allocatedTypeInfo,
>> -                       SourceLocation startLoc, SourceRange directInitRange)
>> +                       SourceRange Range, SourceRange directInitRange)
>>    : Expr(CXXNewExprClass, ty, VK_RValue, OK_Ordinary,
>>           ty->isDependentType(), ty->isDependentType(),
>>           ty->isInstantiationDependentType(),
>>           ty->containsUnexpandedParameterPack()),
>>      SubExprs(0), OperatorNew(operatorNew), OperatorDelete(operatorDelete),
>>      AllocatedTypeInfo(allocatedTypeInfo), TypeIdParens(typeIdParens),
>> -    StartLoc(startLoc), DirectInitRange(directInitRange),
>> +    Range(Range), DirectInitRange(directInitRange),
>>      GlobalNew(globalNew), UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize) {
>>    assert((initializer != 0 || initializationStyle == NoInit) &&
>>           "Only NoInit can have no initializer.");
>> @@ -147,18 +147,6 @@
>>      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
>>  QualType CXXDeleteExpr::getDestroyedType() const {
>>    const Expr *Arg = getArgument();
>>
>> Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=167507&r1=167506&r2=167507&view=diff
>> ==============================================================================
>> --- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
>> +++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Tue Nov  6 18:12:38 2012
>> @@ -987,7 +987,7 @@
>>    if (ParenListExpr *List = dyn_cast_or_null<ParenListExpr>(Initializer))
>>      DirectInitRange = List->getSourceRange();
>>
>> -  return BuildCXXNew(StartLoc, UseGlobal,
>> +  return BuildCXXNew(SourceRange(StartLoc, D.getLocEnd()), UseGlobal,
>>                       PlacementLParen,
>>                       PlacementArgs,
>>                       PlacementRParen,
>> @@ -1020,7 +1020,7 @@
>>  }
>>
>>  ExprResult
>> -Sema::BuildCXXNew(SourceLocation StartLoc, bool UseGlobal,
>> +Sema::BuildCXXNew(SourceRange Range, bool UseGlobal,
>>                    SourceLocation PlacementLParen,
>>                    MultiExprArg PlacementArgs,
>>                    SourceLocation PlacementRParen,
>> @@ -1032,6 +1032,7 @@
>>                    Expr *Initializer,
>>                    bool TypeMayContainAuto) {
>>    SourceRange TypeRange = AllocTypeInfo->getTypeLoc().getSourceRange();
>> +  SourceLocation StartLoc = Range.getBegin();
>>
>>    CXXNewExpr::InitializationStyle initStyle;
>>    if (DirectInitRange.isValid()) {
>> @@ -1407,7 +1408,7 @@
>>                                          TypeIdParens,
>>                                          ArraySize, initStyle, Initializer,
>>                                          ResultType, AllocTypeInfo,
>> -                                        StartLoc, DirectInitRange));
>> +                                        Range, DirectInitRange));
>>  }
>>
>>  /// \brief Checks that a type is suitable as the allocated type
>>
>> Modified: cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderStmt.cpp?rev=167507&r1=167506&r2=167507&view=diff
>> ==============================================================================
>> --- cfe/trunk/lib/Serialization/ASTReaderStmt.cpp (original)
>> +++ cfe/trunk/lib/Serialization/ASTReaderStmt.cpp Tue Nov  6 18:12:38 2012
>> @@ -1243,7 +1243,7 @@
>>    E->setOperatorDelete(ReadDeclAs<FunctionDecl>(Record, Idx));
>>    E->AllocatedTypeInfo = GetTypeSourceInfo(Record, Idx);
>>    E->TypeIdParens = ReadSourceRange(Record, Idx);
>> -  E->StartLoc = ReadSourceLocation(Record, Idx);
>> +  E->Range = ReadSourceRange(Record, Idx);
>>    E->DirectInitRange = ReadSourceRange(Record, Idx);
>>
>>    E->AllocateArgsArray(Reader.getContext(), isArray, NumPlacementArgs,
>>
>> Modified: cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterStmt.cpp?rev=167507&r1=167506&r2=167507&view=diff
>> ==============================================================================
>> --- cfe/trunk/lib/Serialization/ASTWriterStmt.cpp (original)
>> +++ cfe/trunk/lib/Serialization/ASTWriterStmt.cpp Tue Nov  6 18:12:38 2012
>> @@ -1236,7 +1236,7 @@
>>    Writer.AddDeclRef(E->getOperatorDelete(), Record);
>>    Writer.AddTypeSourceInfo(E->getAllocatedTypeSourceInfo(), Record);
>>    Writer.AddSourceRange(E->getTypeIdParens(), Record);
>> -  Writer.AddSourceLocation(E->getStartLoc(), Record);
>> +  Writer.AddSourceRange(E->getSourceRange(), Record);
>>    Writer.AddSourceRange(E->getDirectInitRange(), Record);
>>    for (CXXNewExpr::arg_iterator I = E->raw_arg_begin(), e = E->raw_arg_end();
>>         I != e; ++I)
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits



More information about the cfe-commits mailing list