From e159a3ced4c54b539c165b1cc26424fa0b34d53e Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Mon, 8 Feb 2021 15:04:48 +0100 Subject: [Syntax] Remove a strict valid source location assertion for TypeLoc. The EndLoc of a type loc can be invalid for broken code. Also extend the existing test to support error code with `error-ok` annotation. Differential Revision: https://reviews.llvm.org/D96261 --- clang/lib/Tooling/Syntax/BuildTree.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'clang/lib/Tooling/Syntax/BuildTree.cpp') diff --git a/clang/lib/Tooling/Syntax/BuildTree.cpp b/clang/lib/Tooling/Syntax/BuildTree.cpp index 62573b6..a5cb293 100644 --- a/clang/lib/Tooling/Syntax/BuildTree.cpp +++ b/clang/lib/Tooling/Syntax/BuildTree.cpp @@ -294,11 +294,12 @@ static SourceRange getDeclaratorRange(const SourceManager &SM, TypeLoc T, SourceRange Initializer) { SourceLocation Start = GetStartLoc().Visit(T); SourceLocation End = T.getEndLoc(); - assert(End.isValid()); if (Name.isValid()) { if (Start.isInvalid()) Start = Name; - if (SM.isBeforeInTranslationUnit(End, Name)) + // End of TypeLoc could be invalid if the type is invalid, fallback to the + // NameLoc. + if (End.isInvalid() || SM.isBeforeInTranslationUnit(End, Name)) End = Name; } if (Initializer.isValid()) { -- cgit v1.1