[cfe-commits] r124833 - in /cfe/trunk: lib/Basic/DiagnosticIDs.cpp test/Index/fix-its.c tools/c-index-test/c-index-test.c

Douglas Gregor dgregor at apple.com
Thu Feb 3 15:41:12 PST 2011


Author: dgregor
Date: Thu Feb  3 17:41:12 2011
New Revision: 124833

URL: http://llvm.org/viewvc/llvm-project?rev=124833&view=rev
Log:
If any Fix-Its attached to a diagnostic have invalid source locations
or source locations that refer into a macro instantiation, delete all
of the Fix-Its on that diagnostic.

Added:
    cfe/trunk/test/Index/fix-its.c
Modified:
    cfe/trunk/lib/Basic/DiagnosticIDs.cpp
    cfe/trunk/tools/c-index-test/c-index-test.c

Modified: cfe/trunk/lib/Basic/DiagnosticIDs.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/DiagnosticIDs.cpp?rev=124833&r1=124832&r2=124833&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/DiagnosticIDs.cpp (original)
+++ cfe/trunk/lib/Basic/DiagnosticIDs.cpp Thu Feb  3 17:41:12 2011
@@ -560,6 +560,19 @@
       Diag.SetDelayedDiagnostic(diag::fatal_too_many_errors);
   }
 
+  // If we have any Fix-Its, make sure that all of the Fix-Its point into
+  // source locations that aren't macro instantiations. If any point into
+  // macro instantiations, remove all of the Fix-Its.
+  for (unsigned I = 0, N = Diag.NumFixItHints; I != N; ++I) {
+    const FixItHint &FixIt = Diag.FixItHints[I];
+    if (FixIt.RemoveRange.isInvalid() ||
+        FixIt.RemoveRange.getBegin().isMacroID() ||
+        FixIt.RemoveRange.getEnd().isMacroID()) {
+      Diag.NumFixItHints = 0;
+      break;
+    }    
+  }
+  
   // Finally, report it.
   Diag.Client->HandleDiagnostic((Diagnostic::Level)DiagLevel, Info);
   if (Diag.Client->IncludeInDiagnosticCounts()) {

Added: cfe/trunk/test/Index/fix-its.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/fix-its.c?rev=124833&view=auto
==============================================================================
--- cfe/trunk/test/Index/fix-its.c (added)
+++ cfe/trunk/test/Index/fix-its.c Thu Feb  3 17:41:12 2011
@@ -0,0 +1,18 @@
+// RUN: c-index-test -test-load-source all -fspell-checking %s 2> %t  
+// RUN: FileCheck %s < %t
+struct X {
+  int wibble;
+};
+
+#define MACRO(X) X
+
+void f(struct X *x) {
+  // CHECK: error: no member named 'wobble' in 'struct X'; did you mean 'wibble'?
+  // CHECK-NOT: FIX-IT
+  // CHECK: note: 'wibble' declared here
+  MACRO(x->wobble = 17);
+  // CHECK: error: no member named 'wabble' in 'struct X'; did you mean 'wibble'?
+  // CHECK: FIX-IT: Replace [17:6 - 17:12] with "wibble"
+  // CHECK: note: 'wibble' declared here
+  x->wabble = 17;
+}

Modified: cfe/trunk/tools/c-index-test/c-index-test.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/c-index-test.c?rev=124833&r1=124832&r2=124833&view=diff
==============================================================================
--- cfe/trunk/tools/c-index-test/c-index-test.c (original)
+++ cfe/trunk/tools/c-index-test/c-index-test.c Thu Feb  3 17:41:12 2011
@@ -683,7 +683,7 @@
   Idx = clang_createIndex(/* excludeDeclsFromPCH */
                           (!strcmp(filter, "local") || 
                            !strcmp(filter, "local-display"))? 1 : 0,
-                          /* displayDiagnosics=*/1);
+                          /* displayDiagnosics=*/0);
 
   if (parse_remapped_files(argc, argv, 0, &unsaved_files, &num_unsaved_files)) {
     clang_disposeIndex(Idx);





More information about the cfe-commits mailing list