diff options
author | Hans Wennborg <hans@hanshq.net> | 2015-01-27 23:12:34 +0000 |
---|---|---|
committer | Hans Wennborg <hans@hanshq.net> | 2015-01-27 23:12:34 +0000 |
commit | beb9936b46b8c672e813b3421221c3b788753b9b (patch) | |
tree | c567f728501d7d4169a3c0be6735d86b5fd6386d /lib | |
parent | b16beff99ce9f7672335ec4afd40e29c80a5bfb0 (diff) |
Merging r227251:
------------------------------------------------------------------------
r227251 | rikka | 2015-01-27 14:01:39 -0800 (Tue, 27 Jan 2015) | 17 lines
Fix a think-o in handling ambiguous corrections for a TypoExpr.
Under certain circumstances, the identifier mentioned in the diagnostic
won't match the intended correction even though the replacement
expression and the note pointing to the decl are both correct.
Basically, the TreeTransform assumes the TypoExpr's Consumer points to
the correct TypoCorrection, but the handling of typos that appear to be
ambiguous from the point of view of TransformTypoExpr would cause that
assumption to be violated by altering the Consumer's correction stream.
This fix allows the Consumer's correction stream to be reset to the
right TypoCorrection after successfully resolving the percieved ambiguity.
Included is a fix to suppress correcting the RHS of an assignment to the
LHS of that assignment for non-C++ code, to prevent a regression in
test/SemaObjC/provisional-ivar-lookup.m.
This fixes PR22297.
------------------------------------------------------------------------
git-svn-id: https://llvm.org/svn/llvm-project/cfe/branches/release_36@227266 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 20 | ||||
-rw-r--r-- | lib/Sema/SemaExprCXX.cpp | 11 |
2 files changed, 26 insertions, 5 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 9cb147f878..93b4c30871 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -9457,6 +9457,18 @@ static void checkObjCPointerIntrospection(Sema &S, ExprResult &L, ExprResult &R, } } +static NamedDecl *getDeclFromExpr(Expr *E) { + if (!E) + return nullptr; + if (auto *DRE = dyn_cast<DeclRefExpr>(E)) + return DRE->getDecl(); + if (auto *ME = dyn_cast<MemberExpr>(E)) + return ME->getMemberDecl(); + if (auto *IRE = dyn_cast<ObjCIvarRefExpr>(E)) + return IRE->getDecl(); + return nullptr; +} + /// CreateBuiltinBinOp - Creates a new built-in binary operation with /// operator @p Opc at location @c TokLoc. This routine only supports /// built-in operations; ActOnBinOp handles overloaded operators. @@ -9494,7 +9506,13 @@ ExprResult Sema::CreateBuiltinBinOp(SourceLocation OpLoc, // doesn't handle dependent types properly, so make sure any TypoExprs have // been dealt with before checking the operands. LHS = CorrectDelayedTyposInExpr(LHSExpr); - RHS = CorrectDelayedTyposInExpr(RHSExpr); + RHS = CorrectDelayedTyposInExpr(RHSExpr, [Opc, LHS](Expr *E) { + if (Opc != BO_Assign) + return ExprResult(E); + // Avoid correcting the RHS to the same Expr as the LHS. + Decl *D = getDeclFromExpr(E); + return (D && D == getDeclFromExpr(LHS.get())) ? ExprError() : E; + }); if (!LHS.isUsable() || !RHS.isUsable()) return ExprError(); } diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index 49a579fb76..ca15550768 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -6162,15 +6162,18 @@ public: while (!AmbiguousTypoExprs.empty()) { auto TE = AmbiguousTypoExprs.back(); auto Cached = TransformCache[TE]; - AmbiguousTypoExprs.pop_back(); + auto &State = SemaRef.getTypoExprState(TE); + State.Consumer->saveCurrentPosition(); TransformCache.erase(TE); if (!TryTransform(E).isInvalid()) { - SemaRef.getTypoExprState(TE).Consumer->resetCorrectionStream(); + State.Consumer->resetCorrectionStream(); TransformCache.erase(TE); Res = ExprError(); break; - } else - TransformCache[TE] = Cached; + } + AmbiguousTypoExprs.remove(TE); + State.Consumer->restoreSavedPosition(); + TransformCache[TE] = Cached; } // Ensure that all of the TypoExprs within the current Expr have been found. |