Change VerifyDiagnosticConsumer so that it *must* contain at least one "expected-*" directive.  As a result, for test-cases that are not expected to generate any diagnostics, an additional directive "expected-no-diagnostics" has been implemented which can then be included in such test-cases.  This new directive may not be used in conjunction with any other "expected-*" directive.

This change was initially proposed as a solution to the problem highlighted by check-in r164677, i.e. that -verify will not cause a test-case failure where the compile command does not actually reference the file.

Patch reviewed by David Blaikie.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@166281 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/Frontend/verify.c b/test/Frontend/verify.c
index 8b4edc5..062e6bd 100644
--- a/test/Frontend/verify.c
+++ b/test/Frontend/verify.c
@@ -111,9 +111,10 @@
 #if 0
 // RUN: %clang_cc1 -verify %t.invalid 2>&1 | FileCheck -check-prefix=CHECK6 %s
 
-//      CHECK6: error: 'error' diagnostics seen but not expected:
+//      CHECK6: error: no expected directives found: consider use of 'expected-no-diagnostics'
+// CHECK6-NEXT: error: 'error' diagnostics seen but not expected:
 // CHECK6-NEXT:   (frontend): error reading '{{.*}}verify.c.tmp.invalid'
-// CHECK6-NEXT: 1 error generated.
+// CHECK6-NEXT: 2 errors generated.
 
 // RUN: echo -e '//expected-error@2{{1}}\n#error 2' | %clang_cc1 -verify 2>&1 | FileCheck -check-prefix=CHECK7 %s
 
diff --git a/test/Frontend/verify2.c b/test/Frontend/verify2.c
index a1c7975..04f80ad 100644
--- a/test/Frontend/verify2.c
+++ b/test/Frontend/verify2.c
@@ -3,7 +3,7 @@
 
 // Please note that all comments are inside "#if 0" blocks so that
 // VerifyDiagnosticConsumer sees no comments while processing this
-// test-case.
+// test-case (and hence no expected-* directives).
 #endif
 
 #include "verify2.h"
@@ -12,8 +12,9 @@
 #if 0
 // expected-error {{should be ignored}}
 
-//      CHECK: error: 'error' diagnostics seen but not expected:
+//      CHECK: error: no expected directives found: consider use of 'expected-no-diagnostics'
+// CHECK-NEXT: error: 'error' diagnostics seen but not expected:
 // CHECK-NEXT:   Line 1: header
 // CHECK-NEXT:   Line 10: source
-// CHECK-NEXT: 2 errors generated.
+// CHECK-NEXT: 3 errors generated.
 #endif
diff --git a/test/Frontend/verify3.c b/test/Frontend/verify3.c
new file mode 100644
index 0000000..0705b4b
--- /dev/null
+++ b/test/Frontend/verify3.c
@@ -0,0 +1,41 @@
+// This test-case runs several sub-tests on -verify to ensure that correct
+// diagnostics are generated in relation to the mis-use and non-use of the
+// 'expected-no-diagnostics' directive.
+
+// RUN: %clang_cc1 -DTEST1 -verify %s 2>&1 | FileCheck -check-prefix=CHECK1 %s
+#ifdef TEST1
+// expected-no-diagnostics
+// expected-note {{}}
+
+//      CHECK1: error: 'error' diagnostics seen but not expected:
+// CHECK1-NEXT:   Line 8: expected directive cannot follow 'expected-no-diagnostics' directive
+// CHECK1-NEXT: 1 error generated.
+#endif
+
+// RUN: %clang_cc1 -DTEST2 -verify %s 2>&1 | FileCheck -check-prefix=CHECK2 %s
+#ifdef TEST2
+#warning X
+// expected-warning@-1 {{X}}
+// expected-no-diagnostics
+
+//      CHECK2: error: 'error' diagnostics seen but not expected:
+// CHECK2-NEXT:   Line 19: 'expected-no-diagnostics' directive cannot follow other expected directives
+// CHECK2-NEXT: 1 error generated.
+#endif
+
+// RUN: %clang_cc1 -DTEST3 -verify %s 2>&1 | FileCheck -check-prefix=CHECK3 %s
+// RUN: %clang_cc1 -verify 2>&1 | FileCheck -check-prefix=CHECK3 %s
+#ifdef TEST3
+// no directives
+
+//      CHECK3: error: no expected directives found: consider use of 'expected-no-diagnostics'
+// CHECK3-NEXT: 1 error generated.
+#endif
+
+// RUN: %clang_cc1 -E -DTEST4 -verify %s 2>&1 | FileCheck -check-prefix=CHECK4 %s
+#ifdef TEST4
+#warning X
+// expected-warning@-1 {{X}}
+
+// CHECK4-NOT: error: no expected directives found: consider use of 'expected-no-diagnostics'
+#endif