[cfe-commits] r153962 - in /cfe/trunk: include/clang/Sema/TypoCorrection.h lib/Sema/SemaDecl.cpp lib/Sema/SemaLookup.cpp test/FixIt/typo-crash.cpp

Kaelyn Uhrain rikka at google.com
Tue Apr 3 11:20:11 PDT 2012


Author: rikka
Date: Tue Apr  3 13:20:11 2012
New Revision: 153962

URL: http://llvm.org/viewvc/llvm-project?rev=153962&view=rev
Log:
Replace the workaround from r153445 with a proper fix.

Infinite recursion was happening when DiagnoseInvalidRedeclaration
called ActOnFunctionDeclarator to check if a typo correction works when
the correction was just to the nested-name-specifier because the wrong
DeclContext was being passed in. Unlike a number of functions
surrounding typo correction, the DeclContext passed in for a function is
the context of the function name after applying any nested name
specifiers, not the lexical DeclContext where the
function+nested-name-specifier appears.

Modified:
    cfe/trunk/include/clang/Sema/TypoCorrection.h
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/lib/Sema/SemaLookup.cpp
    cfe/trunk/test/FixIt/typo-crash.cpp

Modified: cfe/trunk/include/clang/Sema/TypoCorrection.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/TypoCorrection.h?rev=153962&r1=153961&r2=153962&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/TypoCorrection.h (original)
+++ cfe/trunk/include/clang/Sema/TypoCorrection.h Tue Apr  3 13:20:11 2012
@@ -205,7 +205,7 @@
       : WantTypeSpecifiers(true), WantExpressionKeywords(true),
         WantCXXNamedCasts(true), WantRemainingKeywords(true),
         WantObjCSuper(false),
-        IsObjCIvarLookup(false), AllowAddedQualifier(true) {}
+        IsObjCIvarLookup(false) {}
 
   virtual ~CorrectionCandidateCallback() {}
 
@@ -239,10 +239,6 @@
   // Temporary hack for the one case where a CorrectTypoContext enum is used
   // when looking up results.
   bool IsObjCIvarLookup;
-  
-  /// \brief Whether to allow this typo correction to add a 
-  /// nested-name-specifier.
-  bool AllowAddedQualifier;
 };
 
 /// @brief Simple template class for restricting typo correction candidates

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=153962&r1=153961&r2=153962&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Apr  3 13:20:11 2012
@@ -4500,14 +4500,7 @@
 class DifferentNameValidatorCCC : public CorrectionCandidateCallback {
  public:
   DifferentNameValidatorCCC(CXXRecordDecl *Parent)
-      : ExpectedParent(Parent ? Parent->getCanonicalDecl() : 0) {
-    // Don't allow any additional qualification.
-    // FIXME: It would be nice to perform this additional qualification. 
-    // However, DiagnoseInvalidRedeclaration is unable to handle the 
-    // qualification, because it doesn't know how to pass the corrected
-    // nested-name-specifier through to ActOnFunctionDeclarator.
-    AllowAddedQualifier = false;
-  }
+      : ExpectedParent(Parent ? Parent->getCanonicalDecl() : 0) {}
 
   virtual bool ValidateCandidate(const TypoCorrection &candidate) {
     if (candidate.getEditDistance() == 0)
@@ -4596,12 +4589,11 @@
     // TODO: Refactor ActOnFunctionDeclarator so that we can call only the
     // pieces need to verify the typo-corrected C++ declaraction and hopefully
     // eliminate the need for the parameter pack ExtraArgs.
-    Result = SemaRef.ActOnFunctionDeclarator(ExtraArgs.S, ExtraArgs.D,
-                                             NewFD->getDeclContext(),
-                                             NewFD->getTypeSourceInfo(),
-                                             Previous,
-                                             ExtraArgs.TemplateParamLists,
-                                             ExtraArgs.AddToScope);
+    Result = SemaRef.ActOnFunctionDeclarator(
+        ExtraArgs.S, ExtraArgs.D,
+        Correction.getCorrectionDecl()->getDeclContext(),
+        NewFD->getTypeSourceInfo(), Previous, ExtraArgs.TemplateParamLists,
+        ExtraArgs.AddToScope);
     if (Trap.hasErrorOccurred()) {
       // Pretend the typo correction never occurred
       ExtraArgs.D.SetIdentifier(Name.getAsIdentifierInfo(),

Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=153962&r1=153961&r2=153962&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Tue Apr  3 13:20:11 2012
@@ -3815,7 +3815,7 @@
   // Determine whether we are going to search in the various namespaces for
   // corrections.
   bool SearchNamespaces
-    = getLangOpts().CPlusPlus && CCC.AllowAddedQualifier && 
+    = getLangOpts().CPlusPlus &&
       (IsUnqualifiedLookup || (QualifiedDC && QualifiedDC->isNamespace()));
   
   if (IsUnqualifiedLookup || SearchNamespaces) {

Modified: cfe/trunk/test/FixIt/typo-crash.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/typo-crash.cpp?rev=153962&r1=153961&r2=153962&view=diff
==============================================================================
--- cfe/trunk/test/FixIt/typo-crash.cpp (original)
+++ cfe/trunk/test/FixIt/typo-crash.cpp Tue Apr  3 13:20:11 2012
@@ -19,11 +19,11 @@
     namespace B {
       typedef short   T;
         
-      T global();
+      T global(); // expected-note {{'A::B::global' declared here}}
     }
   }
 
   using namespace A::B;
 
-  T A::global(); // expected-error{{out-of-line definition of 'global' does not match any declaration in namespace 'PR12297::A'}}
+  T A::global(); // expected-error {{out-of-line definition of 'global' does not match any declaration in namespace 'PR12297::A'; did you mean 'A::B::global'?}}
 }





More information about the cfe-commits mailing list