From: Abramo Bagnara Date: Thu, 18 Oct 2012 08:29:37 +0000 (+0000) Subject: Fixed some corner cases due to implicit int TypeLoc and simplified the logic. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=278eafa2cd8296f8128d13c6466a0ace3d03a872;p=clang Fixed some corner cases due to implicit int TypeLoc and simplified the logic. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@166174 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/TypeLoc.cpp b/lib/AST/TypeLoc.cpp index c9c084ab83..58c4cbd00c 100644 --- a/lib/AST/TypeLoc.cpp +++ b/lib/AST/TypeLoc.cpp @@ -98,27 +98,38 @@ void TypeLoc::initializeImpl(ASTContext &Context, TypeLoc TL, SourceLocation TypeLoc::getBeginLoc() const { TypeLoc Cur = *this; + TypeLoc LeftMost = Cur; while (true) { switch (Cur.getTypeLocClass()) { + case Elaborated: + LeftMost = Cur; + break; case FunctionProto: - if (cast(&Cur)->getTypePtr()->hasTrailingReturn()) - return Cur.getLocalSourceRange().getBegin(); + if (cast(&Cur)->getTypePtr()->hasTrailingReturn()) { + LeftMost = Cur; + break; + } + /* Fall through */ + case FunctionNoProto: + case ConstantArray: + case DependentSizedArray: + case IncompleteArray: + case VariableArray: + // FIXME: Currently QualifiedTypeLoc does not have a source range + case Qualified: Cur = Cur.getNextTypeLoc(); - assert(!Cur.isNull()); continue; - - // FIXME: Currently QualifiedTypeLoc does not have a source range - // case Qualified: - case Elaborated: - return Cur.getLocalSourceRange().getBegin(); - default: - if (Cur.getNextTypeLoc().isNull()) - return Cur.getLocalSourceRange().getBegin(); + if (!Cur.getLocalSourceRange().getBegin().isInvalid()) + LeftMost = Cur; Cur = Cur.getNextTypeLoc(); + if (Cur.isNull()) + break; continue; } // switch + break; } // while + return LeftMost.getLocalSourceRange().getBegin(); } SourceLocation TypeLoc::getEndLoc() const {