From: Eli Friedman Date: Mon, 22 Jul 2013 23:09:39 +0000 (+0000) Subject: Don't emit open-paren fixit without close-paren. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4e16bf2511ab335cfcf74a273332ad7c00a786de;p=clang Don't emit open-paren fixit without close-paren. getLocForEndOfToken() isn't guaranteed to succeed; if it doesn't, make sure we do something sane. Fixes PR16673. I'm not sure how to write a testcase for this short of grepping through the diagnostic output. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186889 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 2c933147f4..16b5e3cf00 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -7392,6 +7392,8 @@ static void diagnoseLogicalNotOnLHSofComparison(Sema &S, ExprResult &LHS, SourceLocation FirstOpen = SubExpr->getLocStart(); SourceLocation FirstClose = RHS.get()->getLocEnd(); FirstClose = S.getPreprocessor().getLocForEndOfToken(FirstClose); + if (FirstClose.isInvalid()) + FirstOpen = SourceLocation(); S.Diag(UO->getOperatorLoc(), diag::note_logical_not_fix) << FixItHint::CreateInsertion(FirstOpen, "(") << FixItHint::CreateInsertion(FirstClose, ")"); @@ -7400,6 +7402,8 @@ static void diagnoseLogicalNotOnLHSofComparison(Sema &S, ExprResult &LHS, SourceLocation SecondOpen = LHS.get()->getLocStart(); SourceLocation SecondClose = LHS.get()->getLocEnd(); SecondClose = S.getPreprocessor().getLocForEndOfToken(SecondClose); + if (SecondClose.isInvalid()) + SecondOpen = SourceLocation(); S.Diag(UO->getOperatorLoc(), diag::note_logical_not_silence_with_parens) << FixItHint::CreateInsertion(SecondOpen, "(") << FixItHint::CreateInsertion(SecondClose, ")");