r222465 - Ensure all TypoExprs are diagnosed by the tree transform.

Kaelyn Takata rikka at google.com
Thu Nov 20 14:06:44 PST 2014


Author: rikka
Date: Thu Nov 20 16:06:44 2014
New Revision: 222465

URL: http://llvm.org/viewvc/llvm-project?rev=222465&view=rev
Log:
Ensure all TypoExprs are diagnosed by the tree transform.

If there is more than one TypoExpr within the expr being transformed and
any but the last TypoExpr seen don't have any viable candidates, the
tree transform will be aborted early and the remaining TypoExprs are
never seen and hence never diagnosed. This adds a simple
RecursiveASTVisitor to find all of the TypoExprs to be diagnosed in the
case where typo correction of the entire expr fails (and the result of
the tree transform is an ExprError).

Modified:
    cfe/trunk/lib/Sema/SemaExprCXX.cpp
    cfe/trunk/test/SemaCXX/typo-correction-delayed.cpp
    cfe/trunk/test/SemaTemplate/crash-10438657.cpp

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=222465&r1=222464&r2=222465&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Thu Nov 20 16:06:44 2014
@@ -5976,6 +5976,18 @@ static ExprResult attemptRecovery(Sema &
 }
 
 namespace {
+class FindTypoExprs : public RecursiveASTVisitor<FindTypoExprs> {
+  llvm::SmallSetVector<TypoExpr *, 2> &TypoExprs;
+
+public:
+  explicit FindTypoExprs(llvm::SmallSetVector<TypoExpr *, 2> &TypoExprs)
+      : TypoExprs(TypoExprs) {}
+  bool VisitTypoExpr(TypoExpr *TE) {
+    TypoExprs.insert(TE);
+    return true;
+  }
+};
+
 class TransformTypos : public TreeTransform<TransformTypos> {
   typedef TreeTransform<TransformTypos> BaseTransform;
 
@@ -6084,6 +6096,10 @@ public:
         break;
     }
 
+    // Ensure that all of the TypoExprs within the current Expr have been found.
+    if (!res.isUsable())
+      FindTypoExprs(TypoExprs).TraverseStmt(E);
+
     EmitAllDiagnostics();
 
     return res;

Modified: cfe/trunk/test/SemaCXX/typo-correction-delayed.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/typo-correction-delayed.cpp?rev=222465&r1=222464&r2=222465&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/typo-correction-delayed.cpp (original)
+++ cfe/trunk/test/SemaCXX/typo-correction-delayed.cpp Thu Nov 20 16:06:44 2014
@@ -42,3 +42,9 @@ public:
 void testMemberExpr(Foo *f) {
   f->TestIt();  // expected-error {{no member named 'TestIt' in 'Foo'; did you mean 'textIt'?}}
 }
+
+void callee(double, double);
+void testNoCandidates() {
+  callee(xxxxxx,   // expected-error-re {{use of undeclared identifier 'xxxxxx'{{$}}}}
+         zzzzzz);  // expected-error-re {{use of undeclared identifier 'zzzzzz'{{$}}}}
+}

Modified: cfe/trunk/test/SemaTemplate/crash-10438657.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/crash-10438657.cpp?rev=222465&r1=222464&r2=222465&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/crash-10438657.cpp (original)
+++ cfe/trunk/test/SemaTemplate/crash-10438657.cpp Thu Nov 20 16:06:44 2014
@@ -1,6 +1,6 @@
 // RUN: not %clang_cc1 -fsyntax-only %s 2> %t
 // RUN: FileCheck %s < %t
-// CHECK: 9 errors
+// CHECK: 10 errors
 template<typename _CharT>
 class collate : public locale::facet {
 





More information about the cfe-commits mailing list