Update VerifyDiagnosticConsumer to only get directives during parsing.
The old behavior was to re-scan any files (like modules) where we may have
directives but won't actually be parsing during the -verify invocation.
Now, we keep the old behavior in Debug builds as a sanity check (though
modules are a known entity), and expect all legitimate directives to come
from comments seen by the preprocessor.
This also affects the ARC migration tool, which captures diagnostics in
order to filter some out. This change adds an explicit cleanup to
CaptureDiagnosticsConsumer in order to let its sub-consumer handle the
real end of diagnostics.
This was originally split into four patches, but the tests do not run
cleanly without all four, so I've combined them into one commit.
Patches by Andy Gibbs, with slight modifications from me.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161650 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/ARCMT/verify.m b/test/ARCMT/verify.m
new file mode 100644
index 0000000..9110fe6
--- /dev/null
+++ b/test/ARCMT/verify.m
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -arcmt-check -verify %s
+// RUN: %clang_cc1 -arcmt-check -verify %t.invalid 2>&1 | FileCheck %s
+
+#if 0
+// expected-error {{should be ignored}}
+#endif
+
+#error should not be ignored
+// expected-error@-1 {{should not be ignored}}
+
+// CHECK: error: 'error' diagnostics seen but not expected:
+// CHECK-NEXT: (frontend): error reading '{{.*}}verify.m.tmp.invalid'
+// CHECK-NEXT: 1 error generated.
diff --git a/test/ASTMerge/function.c b/test/ASTMerge/function.c
index f97ecee..320bca2 100644
--- a/test/ASTMerge/function.c
+++ b/test/ASTMerge/function.c
@@ -1,9 +1,15 @@
// RUN: %clang_cc1 -emit-pch -o %t.1.ast %S/Inputs/function1.c
// RUN: %clang_cc1 -emit-pch -o %t.2.ast %S/Inputs/function2.c
// RUN: %clang_cc1 -ast-merge %t.1.ast -ast-merge %t.2.ast -fsyntax-only %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -ast-merge %t.1.ast -ast-merge %t.2.ast -fsyntax-only -verify %s
// CHECK: function2.c:3:6: error: external function 'f1' declared with incompatible types in different translation units ('void (Int, double)' vs. 'void (int, float)')
// CHECK: function1.c:2:6: note: declared here with type 'void (int, float)'
// CHECK: function2.c:5:6: error: external function 'f3' declared with incompatible types in different translation units ('void (int)' vs. 'void (void)')
// CHECK: function1.c:4:6: note: declared here with type 'void (void)'
// CHECK: 2 errors generated
+
+// expected-error@3 {{external function 'f1' declared with incompatible types}}
+// expected-note@2 {{declared here}}
+// expected-error@5 {{external function 'f3' declared with incompatible types}}
+// expected-note@4 {{declared here}}
diff --git a/test/Frontend/verify.c b/test/Frontend/verify.c
index 59a441d..f8d0f42 100644
--- a/test/Frontend/verify.c
+++ b/test/Frontend/verify.c
@@ -108,3 +108,18 @@
// CHECK5-NEXT: 2 errors generated.
#endif
+#if 0
+// RUN: %clang_cc1 -verify %t.invalid 2>&1 | FileCheck -check-prefix=CHECK6 %s
+
+// CHECK6: error: 'error' diagnostics seen but not expected:
+// CHECK6-NEXT: (frontend): error reading '{{.*}}verify.c.tmp.invalid'
+// CHECK6-NEXT: 1 error generated.
+
+// RUN: echo -e '//expected-error@2{{1}}\n#error 2' | %clang_cc1 -verify 2>&1 | FileCheck -check-prefix=CHECK7 %s
+
+// CHECK7: error: 'error' diagnostics expected but not seen:
+// CHECK7-NEXT: Line 2 (directive at <stdin>:1): 1
+// CHECK7-NEXT: error: 'error' diagnostics seen but not expected:
+// CHECK7-NEXT: Line 2: 2
+// CHECK7-NEXT: 2 errors generated.
+#endif
diff --git a/test/Frontend/verify2.c b/test/Frontend/verify2.c
new file mode 100644
index 0000000..a1c7975
--- /dev/null
+++ b/test/Frontend/verify2.c
@@ -0,0 +1,19 @@
+#if 0
+// RUN: %clang_cc1 -verify %s 2>&1 | FileCheck %s
+
+// Please note that all comments are inside "#if 0" blocks so that
+// VerifyDiagnosticConsumer sees no comments while processing this
+// test-case.
+#endif
+
+#include "verify2.h"
+#error source
+
+#if 0
+// expected-error {{should be ignored}}
+
+// CHECK: error: 'error' diagnostics seen but not expected:
+// CHECK-NEXT: Line 1: header
+// CHECK-NEXT: Line 10: source
+// CHECK-NEXT: 2 errors generated.
+#endif
diff --git a/test/Frontend/verify2.h b/test/Frontend/verify2.h
new file mode 100644
index 0000000..8acbf6e
--- /dev/null
+++ b/test/Frontend/verify2.h
@@ -0,0 +1,5 @@
+#error header
+
+#if 0
+// expected-error {{should be ignored}}
+#endif
diff --git a/test/Modules/Inputs/category_right.h b/test/Modules/Inputs/category_right.h
index d993b50..812a840 100644
--- a/test/Modules/Inputs/category_right.h
+++ b/test/Modules/Inputs/category_right.h
@@ -8,5 +8,5 @@
-(void)right2;
@end
-@interface Foo(Duplicate) // expected-warning {{duplicate definition of category}}
+@interface Foo(Duplicate)
@end
diff --git a/test/Modules/lookup.cpp b/test/Modules/lookup.cpp
index 9839035..70d2107 100644
--- a/test/Modules/lookup.cpp
+++ b/test/Modules/lookup.cpp
@@ -5,6 +5,8 @@
#define IMPORT(X) @__experimental_modules_import X
IMPORT(lookup_right_cxx);
+// in lookup_left.hpp: expected-warning@3 {{weak identifier 'weak_identifier' never declared}}
+
void test(int i, float f) {
// unqualified lookup
f0(&i);
diff --git a/test/Modules/objc-categories.m b/test/Modules/objc-categories.m
index 340f279..b267592 100644
--- a/test/Modules/objc-categories.m
+++ b/test/Modules/objc-categories.m
@@ -12,6 +12,7 @@
// in category_left.h: expected-note {{previous definition}}
+// in category_right.h: expected-warning@11 {{duplicate definition of category}}
@interface Foo(Source)
-(void)source;