[cfe-commits] r92877 - in /cfe/trunk: lib/Sema/SemaCXXScopeSpec.cpp lib/Sema/SemaDecl.cpp lib/Sema/SemaDeclCXX.cpp lib/Sema/SemaDeclObjC.cpp lib/Sema/SemaExpr.cpp lib/Sema/SemaInit.cpp lib/Sema/SemaTemplate.cpp test/FixIt/typo.c test/FixIt/typo.cpp test/FixIt/typo.m test/Sema/var-redecl.c test/SemaObjC/undef-class-messagin-error.m

Douglas Gregor dgregor at apple.com
Wed Jan 6 16:17:45 PST 2010


Author: dgregor
Date: Wed Jan  6 18:17:44 2010
New Revision: 92877

URL: http://llvm.org/viewvc/llvm-project?rev=92877&view=rev
Log:
Whenever we emit a typo-correction diagnostic, also emit a note
pointing to the declaration that we found that has that name (if it is
unique).

Modified:
    cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp
    cfe/trunk/lib/Sema/SemaDeclObjC.cpp
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/lib/Sema/SemaInit.cpp
    cfe/trunk/lib/Sema/SemaTemplate.cpp
    cfe/trunk/test/FixIt/typo.c
    cfe/trunk/test/FixIt/typo.cpp
    cfe/trunk/test/FixIt/typo.m
    cfe/trunk/test/Sema/var-redecl.c
    cfe/trunk/test/SemaObjC/undef-class-messagin-error.m

Modified: cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp?rev=92877&r1=92876&r2=92877&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp Wed Jan  6 18:17:44 2010
@@ -446,6 +446,10 @@
           << Name << Found.getLookupName()
           << CodeModificationHint::CreateReplacement(Found.getNameLoc(),
                                            Found.getLookupName().getAsString());
+      
+      if (NamedDecl *ND = Found.getAsSingle<NamedDecl>())
+        Diag(ND->getLocation(), diag::note_previous_decl)
+          << ND->getDeclName();
     } else
       Found.clear();
   }

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=92877&r1=92876&r2=92877&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Jan  6 18:17:44 2010
@@ -281,6 +281,9 @@
       else
         llvm_unreachable("could not have corrected a typo here");
 
+      Diag(Result->getLocation(), diag::note_previous_decl)
+        << Result->getDeclName();
+      
       SuggestedType = getTypeName(*Result->getIdentifier(), IILoc, S, SS);
       return true;
     }
@@ -580,6 +583,9 @@
         << Id << IDecl->getDeclName() 
         << CodeModificationHint::CreateReplacement(RecoverLoc, 
                                                    IDecl->getNameAsString());
+      Diag(IDecl->getLocation(), diag::note_previous_decl)
+        << IDecl->getDeclName();
+      
       Id = IDecl->getIdentifier();
     }
   }

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=92877&r1=92876&r2=92877&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Wed Jan  6 18:17:44 2010
@@ -1072,6 +1072,8 @@
               << MemberOrBase << true << R.getLookupName()
               << CodeModificationHint::CreateReplacement(R.getNameLoc(),
                                                R.getLookupName().getAsString());
+            Diag(Member->getLocation(), diag::note_previous_decl)
+              << Member->getDeclName();
 
             return BuildMemberInitializer(Member, (Expr**)Args, NumArgs, IdLoc,
                                           LParenLoc, RParenLoc);

Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=92877&r1=92876&r2=92877&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Wed Jan  6 18:17:44 2010
@@ -142,6 +142,8 @@
           (PrevDecl = R.getAsSingle<ObjCInterfaceDecl>())) {
         Diag(SuperLoc, diag::err_undef_superclass_suggest)
           << SuperName << ClassName << PrevDecl->getDeclName();
+        Diag(PrevDecl->getLocation(), diag::note_previous_decl)
+          << PrevDecl->getDeclName();
       }
     }
 
@@ -335,6 +337,8 @@
           (PDecl = R.getAsSingle<ObjCProtocolDecl>())) {
         Diag(ProtocolId[i].second, diag::err_undeclared_protocol_suggest)
           << ProtocolId[i].first << R.getLookupName();
+        Diag(PDecl->getLocation(), diag::note_previous_decl)
+          << PDecl->getDeclName();
       }
     }
 

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=92877&r1=92876&r2=92877&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Jan  6 18:17:44 2010
@@ -943,7 +943,10 @@
           << SS.getRange()
           << CodeModificationHint::CreateReplacement(R.getNameLoc(),
                                               R.getLookupName().getAsString());
-
+      if (NamedDecl *ND = R.getAsSingle<NamedDecl>())
+        Diag(ND->getLocation(), diag::note_previous_decl)
+          << ND->getDeclName();
+      
       // Tell the callee to try to recover.
       return false;
     }
@@ -2400,6 +2403,9 @@
       << Name << DC << R.getLookupName() << SS.getRange()
       << CodeModificationHint::CreateReplacement(R.getNameLoc(),
                                          R.getLookupName().getAsString());
+    if (NamedDecl *ND = R.getAsSingle<NamedDecl>())
+      SemaRef.Diag(ND->getLocation(), diag::note_previous_decl)
+        << ND->getDeclName();
     return false;
   } else {
     R.clear();
@@ -2881,6 +2887,8 @@
             << IDecl->getDeclName() << MemberName << IV->getDeclName()
             << CodeModificationHint::CreateReplacement(R.getNameLoc(),
                                                        IV->getNameAsString());
+          Diag(IV->getLocation(), diag::note_previous_decl)
+            << IV->getDeclName();          
         }
       }
 
@@ -3060,6 +3068,10 @@
         << MemberName << BaseType << Res.getLookupName()
         << CodeModificationHint::CreateReplacement(R.getNameLoc(),
                                            Res.getLookupName().getAsString());
+      ObjCPropertyDecl *Property = Res.getAsSingle<ObjCPropertyDecl>();
+      Diag(Property->getLocation(), diag::note_previous_decl)
+        << Property->getDeclName();          
+
       return LookupMemberExpr(Res, BaseExpr, IsArrow, OpLoc, SS,
                               FirstQualifierInScope, ObjCImpDecl);
     }

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=92877&r1=92876&r2=92877&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Wed Jan  6 18:17:44 2010
@@ -1302,6 +1302,9 @@
             << FieldName << CurrentObjectType << R.getLookupName()
             << CodeModificationHint::CreateReplacement(D->getFieldLoc(),
                                                R.getLookupName().getAsString());
+          SemaRef.Diag(ReplacementField->getLocation(), 
+                       diag::note_previous_decl)
+            << ReplacementField->getDeclName();
         } else {
           SemaRef.Diag(D->getFieldLoc(), diag::err_field_designator_unknown)
             << FieldName << CurrentObjectType;

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=92877&r1=92876&r2=92877&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Wed Jan  6 18:17:44 2010
@@ -219,6 +219,9 @@
             << Name << Found.getLookupName()
             << CodeModificationHint::CreateReplacement(Found.getNameLoc(),
                                           Found.getLookupName().getAsString());
+        if (TemplateDecl *Template = Found.getAsSingle<TemplateDecl>())
+          Diag(Template->getLocation(), diag::note_previous_decl)
+            << Template->getDeclName();
       } else
         Found.clear();
     } else {

Modified: cfe/trunk/test/FixIt/typo.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/typo.c?rev=92877&r1=92876&r2=92877&view=diff

==============================================================================
--- cfe/trunk/test/FixIt/typo.c (original)
+++ cfe/trunk/test/FixIt/typo.c Wed Jan  6 18:17:44 2010
@@ -5,13 +5,14 @@
 };
 
 struct Rectangle {
-  struct Point top_left, bottom_right;
+  struct Point top_left, // expected-note{{'top_left' declared here}}
+               bottom_right;
 };
 
 enum Color { Red, Green, Blue };
 
 struct Window {
-  struct Rectangle bounds;
+  struct Rectangle bounds; // expected-note{{'bounds' declared here}}
   enum Color color;
 };
 

Modified: cfe/trunk/test/FixIt/typo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/typo.cpp?rev=92877&r1=92876&r2=92877&view=diff

==============================================================================
--- cfe/trunk/test/FixIt/typo.cpp (original)
+++ cfe/trunk/test/FixIt/typo.cpp Wed Jan  6 18:17:44 2010
@@ -1,15 +1,15 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
 // RUN: %clang_cc1 -fsyntax-only -fixit -o - %s | %clang_cc1 -fsyntax-only -pedantic -Werror -x c++ -
 namespace std {
-  template<typename T> class basic_string { 
-    int find(const char *substr);
-    static const int npos = -1;
+  template<typename T> class basic_string { // expected-note 2{{'basic_string' declared here}}
+    int find(const char *substr); // expected-note{{'find' declared here}}
+    static const int npos = -1; // expected-note{{'npos' declared here}}
   };
 
-  typedef basic_string<char> string;
+  typedef basic_string<char> string; // expected-note 2{{'string' declared here}}
 }
 
-namespace otherstd {
+namespace otherstd { // expected-note 2{{'otherstd' declared here}}
   using namespace std;
 }
 
@@ -36,7 +36,7 @@
 
 struct Base { };
 struct Derived : public Base {
-  int member;
+  int member; // expected-note 3{{'member' declared here}}
 
   Derived() : base(), // expected-error{{initializer 'base' does not name a non-static data member or base class; did you mean the base class 'Base'?}}
               ember() { } // expected-error{{initializer 'ember' does not name a non-static data member or base class; did you mean the member 'member'?}}

Modified: cfe/trunk/test/FixIt/typo.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/typo.m?rev=92877&r1=92876&r2=92877&view=diff

==============================================================================
--- cfe/trunk/test/FixIt/typo.m (original)
+++ cfe/trunk/test/FixIt/typo.m Wed Jan  6 18:17:44 2010
@@ -12,24 +12,24 @@
 }
 
 @protocol P1
- at property int *sprop;
+ at property int *sprop; // expected-note{{'sprop' declared here}}
 @end
 
 @interface A
 {
-  int his_ivar;
+  int his_ivar; // expected-note 2{{'his_ivar' declared here}}
   float wibble;
 }
 
- at property int his_prop;
+ at property int his_prop; // expected-note{{'his_prop' declared here}}
 @end
 
 @interface B : A <P1>
 {
-  int her_ivar;
+  int her_ivar; // expected-note 2{{'her_ivar' declared here}}
 }
 
- at property int her_prop;
+ at property int her_prop; // expected-note{{'her_prop' declared here}}
 - (void)inst_method1:(int)a;
 + (void)class_method1;
 @end
@@ -60,13 +60,13 @@
   [NSstring method:17]; // expected-error{{use of undeclared identifier 'NSstring'; did you mean 'NSString'?}}
 }
 
- at interface Collide
+ at interface Collide // expected-note{{'Collide' declared here}}
 {
 @public
-  int value;
+  int value; // expected-note{{'value' declared here}}
 }
 
- at property int value;
+ at property int value; // expected-note{{'value' declared here}}
 @end
 
 @implementation Collide
@@ -81,7 +81,7 @@
 @interface Derived : Collid // expected-error{{cannot find interface declaration for 'Collid', superclass of 'Derived'; did you mean 'Collide'?}}
 @end
 
- at protocol NetworkSocket
+ at protocol NetworkSocket // expected-note{{'NetworkSocket' declared here}}
 - (int)send:(void*)buffer bytes:(int)bytes;
 @end
 

Modified: cfe/trunk/test/Sema/var-redecl.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/var-redecl.c?rev=92877&r1=92876&r2=92877&view=diff

==============================================================================
--- cfe/trunk/test/Sema/var-redecl.c (original)
+++ cfe/trunk/test/Sema/var-redecl.c Wed Jan  6 18:17:44 2010
@@ -50,7 +50,7 @@
   }
 }
 
-void g18(void) {
+void g18(void) { // expected-note{{'g18' declared here}}
   extern int g19;
 }
 int *p=&g19; // expected-error{{use of undeclared identifier 'g19'}} \

Modified: cfe/trunk/test/SemaObjC/undef-class-messagin-error.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/undef-class-messagin-error.m?rev=92877&r1=92876&r2=92877&view=diff

==============================================================================
--- cfe/trunk/test/SemaObjC/undef-class-messagin-error.m (original)
+++ cfe/trunk/test/SemaObjC/undef-class-messagin-error.m Wed Jan  6 18:17:44 2010
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
 
- at interface _Child
+ at interface _Child // expected-note{{'_Child' declared here}}
 + (int) flashCache;
 @end
 





More information about the cfe-commits mailing list