[VerifyDiagnosticConsumer] support -verify=<prefixes>
This mimics FileCheck's --check-prefixes option.
The default prefix is "expected". That is, "-verify" is equivalent to
"-verify=expected".
The goal is to permit exercising a single test suite source file with different
compiler options producing different sets of diagnostics. While cpp can be
combined with the existing -verify to accomplish the same goal, source is often
easier to maintain when it's not cluttered with preprocessor directives or
duplicate passages of code. For example, this patch also rewrites some existing
clang tests to demonstrate the benefit of this feature.
Patch by Joel E. Denny, thanks!
Differential Revision: https://reviews.llvm.org/D39694
llvm-svn: 320908
diff --git a/clang/test/Sema/tautological-unsigned-enum-zero-compare.cpp b/clang/test/Sema/tautological-unsigned-enum-zero-compare.cpp
index 5577b68..a733b6e 100644
--- a/clang/test/Sema/tautological-unsigned-enum-zero-compare.cpp
+++ b/clang/test/Sema/tautological-unsigned-enum-zero-compare.cpp
@@ -1,6 +1,12 @@
-// RUN: %clang_cc1 -std=c++11 -triple=x86_64-pc-linux-gnu -fsyntax-only -DUNSIGNED -verify %s
-// RUN: %clang_cc1 -std=c++11 -triple=x86_64-pc-win32 -fsyntax-only -DSIGNED -verify %s
-// RUN: %clang_cc1 -std=c++11 -triple=x86_64-pc-win32 -fsyntax-only -DSILENCE -Wno-tautological-unsigned-enum-zero-compare -verify %s
+// RUN: %clang_cc1 -std=c++11 -triple=x86_64-pc-linux-gnu -fsyntax-only \
+// RUN: -verify=unsigned,unsigned-signed %s
+// RUN: %clang_cc1 -std=c++11 -triple=x86_64-pc-win32 -fsyntax-only \
+// RUN: -verify=unsigned-signed %s
+// RUN: %clang_cc1 -std=c++11 -triple=x86_64-pc-win32 -fsyntax-only \
+// RUN: -Wno-tautological-unsigned-enum-zero-compare \
+// RUN: -verify=silence %s
+
+// silence-no-diagnostics
int main() {
// On Windows, all enumerations have a fixed underlying type, which is 'int'
@@ -16,71 +22,72 @@
enum C : signed { C_foo = 0, C_bar, };
enum C c;
-#ifdef UNSIGNED
- if (a < 0) // expected-warning {{comparison of unsigned enum expression < 0 is always false}}
+ if (a < 0) // unsigned-warning {{comparison of unsigned enum expression < 0 is always false}}
return 0;
if (0 >= a)
return 0;
if (a > 0)
return 0;
- if (0 <= a) // expected-warning {{comparison of 0 <= unsigned enum expression is always true}}
+ if (0 <= a) // unsigned-warning {{comparison of 0 <= unsigned enum expression is always true}}
return 0;
if (a <= 0)
return 0;
- if (0 > a) // expected-warning {{comparison of 0 > unsigned enum expression is always false}}
+ if (0 > a) // unsigned-warning {{comparison of 0 > unsigned enum expression is always false}}
return 0;
- if (a >= 0) // expected-warning {{comparison of unsigned enum expression >= 0 is always true}}
+ if (a >= 0) // unsigned-warning {{comparison of unsigned enum expression >= 0 is always true}}
return 0;
if (0 < a)
return 0;
- if (a < 0U) // expected-warning {{comparison of unsigned enum expression < 0 is always false}}
+ // FIXME: As below, the issue here is that the enumeration is promoted to
+ // unsigned.
+ if (a < 0U) // unsigned-signed-warning {{comparison of unsigned enum expression < 0 is always false}}
return 0;
if (0U >= a)
return 0;
if (a > 0U)
return 0;
- if (0U <= a) // expected-warning {{comparison of 0 <= unsigned enum expression is always true}}
+ if (0U <= a) // unsigned-signed-warning {{comparison of 0 <= unsigned enum expression is always true}}
return 0;
if (a <= 0U)
return 0;
- if (0U > a) // expected-warning {{comparison of 0 > unsigned enum expression is always false}}
+ if (0U > a) // unsigned-signed-warning {{comparison of 0 > unsigned enum expression is always false}}
return 0;
- if (a >= 0U) // expected-warning {{comparison of unsigned enum expression >= 0 is always true}}
+ if (a >= 0U) // unsigned-signed-warning {{comparison of unsigned enum expression >= 0 is always true}}
return 0;
if (0U < a)
return 0;
- if (b < 0) // expected-warning {{comparison of unsigned enum expression < 0 is always false}}
+ if (b < 0) // unsigned-signed-warning {{comparison of unsigned enum expression < 0 is always false}}
return 0;
if (0 >= b)
return 0;
if (b > 0)
return 0;
- if (0 <= b) // expected-warning {{comparison of 0 <= unsigned enum expression is always true}}
+ if (0 <= b) // unsigned-signed-warning {{comparison of 0 <= unsigned enum expression is always true}}
return 0;
if (b <= 0)
return 0;
- if (0 > b) // expected-warning {{comparison of 0 > unsigned enum expression is always false}}
+ if (0 > b) // unsigned-signed-warning {{comparison of 0 > unsigned enum expression is always false}}
return 0;
- if (b >= 0) // expected-warning {{comparison of unsigned enum expression >= 0 is always true}}
+ if (b >= 0) // unsigned-signed-warning {{comparison of unsigned enum expression >= 0 is always true}}
return 0;
if (0 < b)
return 0;
- if (b < 0U) // expected-warning {{comparison of unsigned enum expression < 0 is always false}}
+ if (b < 0U) // unsigned-signed-warning {{comparison of unsigned enum expression < 0 is always false}}
return 0;
if (0U >= b)
return 0;
if (b > 0U)
return 0;
- if (0U <= b) // expected-warning {{comparison of 0 <= unsigned enum expression is always true}}
+ if (0U <= b) // unsigned-signed-warning {{comparison of 0 <= unsigned enum expression is always true}}
return 0;
if (b <= 0U)
return 0;
- if (0U > b) // expected-warning {{comparison of 0 > unsigned enum expression is always false}}
+ if (0U > b) // unsigned-signed-warning {{comparison of 0 > unsigned enum expression is always false}}
return 0;
- if (b >= 0U) // expected-warning {{comparison of unsigned enum expression >= 0 is always true}}
+ if (b >= 0U) // unsigned-signed-warning {{comparison of unsigned enum expression >= 0 is always true}}
return 0;
if (0U < b)
return 0;
@@ -104,230 +111,22 @@
// FIXME: These diagnostics are terrible. The issue here is that the signed
// enumeration value was promoted to an unsigned type.
- if (c < 0U) // expected-warning {{comparison of unsigned enum expression < 0 is always false}}
+ if (c < 0U) // unsigned-signed-warning {{comparison of unsigned enum expression < 0 is always false}}
return 0;
if (0U >= c)
return 0;
if (c > 0U)
return 0;
- if (0U <= c) // expected-warning {{comparison of 0 <= unsigned enum expression is always true}}
+ if (0U <= c) // unsigned-signed-warning {{comparison of 0 <= unsigned enum expression is always true}}
return 0;
if (c <= 0U)
return 0;
- if (0U > c) // expected-warning {{comparison of 0 > unsigned enum expression is always false}}
+ if (0U > c) // unsigned-signed-warning {{comparison of 0 > unsigned enum expression is always false}}
return 0;
- if (c >= 0U) // expected-warning {{comparison of unsigned enum expression >= 0 is always true}}
+ if (c >= 0U) // unsigned-signed-warning {{comparison of unsigned enum expression >= 0 is always true}}
return 0;
if (0U < c)
return 0;
-#elif defined(SIGNED)
- if (a < 0)
- return 0;
- if (0 >= a)
- return 0;
- if (a > 0)
- return 0;
- if (0 <= a)
- return 0;
- if (a <= 0)
- return 0;
- if (0 > a)
- return 0;
- if (a >= 0)
- return 0;
- if (0 < a)
- return 0;
-
- // FIXME: As above, the issue here is that the enumeration is promoted to
- // unsigned.
- if (a < 0U) // expected-warning {{comparison of unsigned enum expression < 0 is always false}}
- return 0;
- if (0U >= a)
- return 0;
- if (a > 0U)
- return 0;
- if (0U <= a) // expected-warning {{comparison of 0 <= unsigned enum expression is always true}}
- return 0;
- if (a <= 0U)
- return 0;
- if (0U > a) // expected-warning {{comparison of 0 > unsigned enum expression is always false}}
- return 0;
- if (a >= 0U) // expected-warning {{comparison of unsigned enum expression >= 0 is always true}}
- return 0;
- if (0U < a)
- return 0;
-
- if (b < 0) // expected-warning {{comparison of unsigned enum expression < 0 is always false}}
- return 0;
- if (0 >= b)
- return 0;
- if (b > 0)
- return 0;
- if (0 <= b) // expected-warning {{comparison of 0 <= unsigned enum expression is always true}}
- return 0;
- if (b <= 0)
- return 0;
- if (0 > b) // expected-warning {{comparison of 0 > unsigned enum expression is always false}}
- return 0;
- if (b >= 0) // expected-warning {{comparison of unsigned enum expression >= 0 is always true}}
- return 0;
- if (0 < b)
- return 0;
-
- if (b < 0U) // expected-warning {{comparison of unsigned enum expression < 0 is always false}}
- return 0;
- if (0U >= b)
- return 0;
- if (b > 0U)
- return 0;
- if (0U <= b) // expected-warning {{comparison of 0 <= unsigned enum expression is always true}}
- return 0;
- if (b <= 0U)
- return 0;
- if (0U > b) // expected-warning {{comparison of 0 > unsigned enum expression is always false}}
- return 0;
- if (b >= 0U) // expected-warning {{comparison of unsigned enum expression >= 0 is always true}}
- return 0;
- if (0U < b)
- return 0;
-
- if (c < 0)
- return 0;
- if (0 >= c)
- return 0;
- if (c > 0)
- return 0;
- if (0 <= c)
- return 0;
- if (c <= 0)
- return 0;
- if (0 > c)
- return 0;
- if (c >= 0)
- return 0;
- if (0 < c)
- return 0;
-
- if (c < 0U) // expected-warning {{comparison of unsigned enum expression < 0 is always false}}
- return 0;
- if (0U >= c)
- return 0;
- if (c > 0U)
- return 0;
- if (0U <= c) // expected-warning {{comparison of 0 <= unsigned enum expression is always true}}
- return 0;
- if (c <= 0U)
- return 0;
- if (0U > c) // expected-warning {{comparison of 0 > unsigned enum expression is always false}}
- return 0;
- if (c >= 0U) // expected-warning {{comparison of unsigned enum expression >= 0 is always true}}
- return 0;
- if (0U < c)
- return 0;
-#else
- // expected-no-diagnostics
- if (a < 0)
- return 0;
- if (0 >= a)
- return 0;
- if (a > 0)
- return 0;
- if (0 <= a)
- return 0;
- if (a <= 0)
- return 0;
- if (0 > a)
- return 0;
- if (a >= 0)
- return 0;
- if (0 < a)
- return 0;
-
- if (a < 0U)
- return 0;
- if (0U >= a)
- return 0;
- if (a > 0U)
- return 0;
- if (0U <= a)
- return 0;
- if (a <= 0U)
- return 0;
- if (0U > a)
- return 0;
- if (a >= 0U)
- return 0;
- if (0U < a)
- return 0;
-
- if (b < 0)
- return 0;
- if (0 >= b)
- return 0;
- if (b > 0)
- return 0;
- if (0 <= b)
- return 0;
- if (b <= 0)
- return 0;
- if (0 > b)
- return 0;
- if (b >= 0)
- return 0;
- if (0 < b)
- return 0;
-
- if (b < 0U)
- return 0;
- if (0U >= b)
- return 0;
- if (b > 0U)
- return 0;
- if (0U <= b)
- return 0;
- if (b <= 0U)
- return 0;
- if (0U > b)
- return 0;
- if (b >= 0U)
- return 0;
- if (0U < b)
- return 0;
-
- if (c < 0)
- return 0;
- if (0 >= c)
- return 0;
- if (c > 0)
- return 0;
- if (0 <= c)
- return 0;
- if (c <= 0)
- return 0;
- if (0 > c)
- return 0;
- if (c >= 0)
- return 0;
- if (0 < c)
- return 0;
-
- if (c < 0U)
- return 0;
- if (0U >= c)
- return 0;
- if (c > 0U)
- return 0;
- if (0U <= c)
- return 0;
- if (c <= 0U)
- return 0;
- if (0U > c)
- return 0;
- if (c >= 0U)
- return 0;
- if (0U < c)
- return 0;
-#endif
return 1;
}
@@ -340,11 +139,7 @@
enum A a;
// used to crash in llvm::APSInt::getMaxValue()
-#ifndef SILENCE
- if (a < 0) // expected-warning {{comparison of unsigned enum expression < 0 is always false}}
-#else
- if (a > 0)
-#endif
+ if (a < 0) // unsigned-signed-warning {{comparison of unsigned enum expression < 0 is always false}}
return 0;
return 1;