]> granicus.if.org Git - clang/commitdiff
If any Fix-Its attached to a diagnostic have invalid source locations
authorDouglas Gregor <dgregor@apple.com>
Thu, 3 Feb 2011 23:41:12 +0000 (23:41 +0000)
committerDouglas Gregor <dgregor@apple.com>
Thu, 3 Feb 2011 23:41:12 +0000 (23:41 +0000)
or source locations that refer into a macro instantiation, delete all
of the Fix-Its on that diagnostic.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124833 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Basic/DiagnosticIDs.cpp
test/Index/fix-its.c [new file with mode: 0644]
tools/c-index-test/c-index-test.c

index 8efeb6897d0f6b56fe58fc5a95db52c7f5f2ca38..8725e7f9c0ccce47882928ae95502219a08893b3 100644 (file)
@@ -560,6 +560,19 @@ bool DiagnosticIDs::ProcessDiag(Diagnostic &Diag) const {
       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()) {
diff --git a/test/Index/fix-its.c b/test/Index/fix-its.c
new file mode 100644 (file)
index 0000000..d82f299
--- /dev/null
@@ -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;
+}
index 8c87d3765194fa034a7ac74276b7cb83d3fd6aed..d4e567d9e26ae0d4cbd9f07a5b55796518c062c0 100644 (file)
@@ -683,7 +683,7 @@ int perform_test_load_source(int argc, const char **argv,
   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);