[llvm-branch-commits] [cfe-branch] r227266 - Merging r227251:

Hans Wennborg hans at hanshq.net
Tue Jan 27 15:12:34 PST 2015


Author: hans
Date: Tue Jan 27 17:12:34 2015
New Revision: 227266

URL: http://llvm.org/viewvc/llvm-project?rev=227266&view=rev
Log:
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.
------------------------------------------------------------------------

Modified:
    cfe/branches/release_36/   (props changed)
    cfe/branches/release_36/include/clang/Sema/SemaInternal.h
    cfe/branches/release_36/lib/Sema/SemaExpr.cpp
    cfe/branches/release_36/lib/Sema/SemaExprCXX.cpp
    cfe/branches/release_36/test/SemaCXX/typo-correction-delayed.cpp

Propchange: cfe/branches/release_36/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jan 27 17:12:34 2015
@@ -1,4 +1,4 @@
 /cfe/branches/type-system-rewrite:134693-134817
-/cfe/trunk:226008,226049,226136,226282,226624,226707,226754,226863,226877,227062,227220
+/cfe/trunk:226008,226049,226136,226282,226624,226707,226754,226863,226877,227062,227220,227251
 /cfe/trunk/test:170344
 /cfe/trunk/test/SemaTemplate:126920

Modified: cfe/branches/release_36/include/clang/Sema/SemaInternal.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_36/include/clang/Sema/SemaInternal.h?rev=227266&r1=227265&r2=227266&view=diff
==============================================================================
--- cfe/branches/release_36/include/clang/Sema/SemaInternal.h (original)
+++ cfe/branches/release_36/include/clang/Sema/SemaInternal.h Tue Jan 27 17:12:34 2015
@@ -101,7 +101,7 @@ public:
                          DeclContext *MemberContext,
                          bool EnteringContext)
       : Typo(TypoName.getName().getAsIdentifierInfo()), CurrentTCIndex(0),
-        SemaRef(SemaRef), S(S),
+        SavedTCIndex(0), SemaRef(SemaRef), S(S),
         SS(SS ? llvm::make_unique<CXXScopeSpec>(*SS) : nullptr),
         CorrectionValidator(std::move(CCC)), MemberContext(MemberContext),
         Result(SemaRef, TypoName, LookupKind),
@@ -187,6 +187,17 @@ public:
            CurrentTCIndex >= ValidatedCorrections.size();
   }
 
+  /// \brief Save the current position in the correction stream (overwriting any
+  /// previously saved position).
+  void saveCurrentPosition() {
+    SavedTCIndex = CurrentTCIndex;
+  }
+
+  /// \brief Restore the saved position in the correction stream.
+  void restoreSavedPosition() {
+    CurrentTCIndex = SavedTCIndex;
+  }
+
   ASTContext &getContext() const { return SemaRef.Context; }
   const LookupResult &getLookupResult() const { return Result; }
 
@@ -267,6 +278,7 @@ private:
 
   SmallVector<TypoCorrection, 4> ValidatedCorrections;
   size_t CurrentTCIndex;
+  size_t SavedTCIndex;
 
   Sema &SemaRef;
   Scope *S;

Modified: cfe/branches/release_36/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_36/lib/Sema/SemaExpr.cpp?rev=227266&r1=227265&r2=227266&view=diff
==============================================================================
--- cfe/branches/release_36/lib/Sema/SemaExpr.cpp (original)
+++ cfe/branches/release_36/lib/Sema/SemaExpr.cpp Tue Jan 27 17:12:34 2015
@@ -9457,6 +9457,18 @@ static void checkObjCPointerIntrospectio
   }
 }
 
+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(Sour
     // 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();
   }

Modified: cfe/branches/release_36/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_36/lib/Sema/SemaExprCXX.cpp?rev=227266&r1=227265&r2=227266&view=diff
==============================================================================
--- cfe/branches/release_36/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/branches/release_36/lib/Sema/SemaExprCXX.cpp Tue Jan 27 17:12:34 2015
@@ -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.

Modified: cfe/branches/release_36/test/SemaCXX/typo-correction-delayed.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_36/test/SemaCXX/typo-correction-delayed.cpp?rev=227266&r1=227265&r2=227266&view=diff
==============================================================================
--- cfe/branches/release_36/test/SemaCXX/typo-correction-delayed.cpp (original)
+++ cfe/branches/release_36/test/SemaCXX/typo-correction-delayed.cpp Tue Jan 27 17:12:34 2015
@@ -165,3 +165,13 @@ namespace PR22250 {
 // expected-error at +1 {{expected ';' after top level declarator}}
 int getenv_s(size_t *y, char(&z)) {}
 }
+
+namespace PR22297 {
+double pow(double x, double y);
+struct TimeTicks {
+  static void Now();  // expected-note {{'Now' declared here}}
+};
+void f() {
+  TimeTicks::now();  // expected-error {{no member named 'now' in 'PR22297::TimeTicks'; did you mean 'Now'?}}
+}
+}





More information about the llvm-branch-commits mailing list