diff options
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/Frontend/diagnostics-order.c | 6 | ||||
-rw-r--r-- | clang/test/Frontend/verify-prefixes.c | 118 | ||||
-rw-r--r-- | clang/test/Sema/tautological-unsigned-enum-zero-compare.c | 174 | ||||
-rw-r--r-- | clang/test/Sema/tautological-unsigned-enum-zero-compare.cpp | 269 | ||||
-rw-r--r-- | clang/test/Sema/tautological-unsigned-zero-compare.c | 125 |
5 files changed, 180 insertions, 512 deletions
diff --git a/clang/test/Frontend/diagnostics-order.c b/clang/test/Frontend/diagnostics-order.c index e557fc631de..37c0cd90d15 100644 --- a/clang/test/Frontend/diagnostics-order.c +++ b/clang/test/Frontend/diagnostics-order.c @@ -2,9 +2,11 @@ // Previously, these diagnostics were grouped by diagnostic level with all // notes last. // -// RUN: not %clang_cc1 -O999 -std=bogus %s 2> %t +// RUN: not %clang_cc1 -O999 -std=bogus -verify=-foo %s 2> %t // RUN: FileCheck < %t %s // -// CHECK: warning: optimization level '-O999' is not supported +// CHECK: error: invalid value '-foo' in '-verify=' +// CHECK-NEXT: note: -verify prefixes must start with a letter and contain only alphanumeric characters, hyphens, and underscores +// CHECK-NEXT: warning: optimization level '-O999' is not supported // CHECK-NEXT: error: invalid value 'bogus' in '-std=bogus' // CHECK-NEXT: note: use {{.*}} for {{.*}} standard diff --git a/clang/test/Frontend/verify-prefixes.c b/clang/test/Frontend/verify-prefixes.c new file mode 100644 index 00000000000..c5b545cf84c --- /dev/null +++ b/clang/test/Frontend/verify-prefixes.c @@ -0,0 +1,118 @@ +#if GC +# define GCONST const +#else +# define GCONST +#endif + +// gconst-note@8 {{variable 'glb' declared const here}} +GCONST int glb = 5; + + +// Check various correct prefix spellings and combinations. +// +// RUN: %clang_cc1 -DGC -verify=gconst %s +// RUN: %clang_cc1 -Wcast-qual -DLC -verify=lconst %s +// RUN: %clang_cc1 -DSC -verify=expected %s +// RUN: %clang_cc1 -DSC -verify %s +// RUN: %clang_cc1 -DSC -verify -verify %s +// RUN: %clang_cc1 -verify=nconst %s +// RUN: %clang_cc1 -verify=n-const %s +// RUN: %clang_cc1 -verify=n_const %s +// RUN: %clang_cc1 -verify=NConst %s +// RUN: %clang_cc1 -verify=NConst2 %s +// RUN: %clang_cc1 -Wcast-qual -DGC -DLC -verify=gconst,lconst %s +// RUN: %clang_cc1 -Wcast-qual -DGC -DLC -DSC -verify=gconst,lconst,expected %s +// RUN: %clang_cc1 -Wcast-qual -DGC -DLC -verify=gconst -verify=lconst %s +// RUN: %clang_cc1 -Wcast-qual -DGC -DLC -DSC -verify=gconst,lconst -verify %s +// RUN: %clang_cc1 -DGC -DSC -verify -verify=gconst -verify %s +// +// Duplicate prefixes. +// RUN: %clang_cc1 -Wcast-qual -DGC -DLC -verify=gconst,lconst,gconst %s +// RUN: %clang_cc1 -DGC -verify=gconst -verify=gconst,gconst %s +// RUN: %clang_cc1 -DSC -verify=expected -verify=expected %s +// RUN: %clang_cc1 -DSC -verify -verify=expected %s +// +// Various tortured cases: multiple directives with different prefixes per +// line, prefixes used as comments, prefixes prefixing prefixes, and prefixes +// with special suffixes. +// RUN: %clang_cc1 -Wcast-qual -DLC -verify=foo %s +// RUN: %clang_cc1 -DSC -verify=bar %s +// RUN: %clang_cc1 -Wcast-qual -DLC -DSC -verify=foo,bar %s +// RUN: %clang_cc1 -Wcast-qual -DLC -DSC -verify=bar,foo %s +// RUN: %clang_cc1 -DSC -verify=foo-bar %s +// RUN: %clang_cc1 -Wcast-qual -DLC -verify=bar-foo %s +// RUN: %clang_cc1 -Wcast-qual -DLC -DSC -verify=foo,foo-bar %s +// RUN: %clang_cc1 -Wcast-qual -DLC -DSC -verify=foo-bar,foo %s +// RUN: %clang_cc1 -Wcast-qual -DLC -DSC -verify=bar,bar-foo %s +// RUN: %clang_cc1 -Wcast-qual -DLC -DSC -verify=bar-foo,bar %s +// RUN: %clang_cc1 -Wcast-qual -DLC -DSC -verify=foo-bar,bar-foo %s +// RUN: %clang_cc1 -DSC -verify=foo-warning %s +// RUN: %clang_cc1 -Wcast-qual -DLC -verify=bar-warning-re %s +// RUN: %clang_cc1 -Wcast-qual -DLC -DSC -verify=foo,foo-warning %s +// RUN: %clang_cc1 -Wcast-qual -DLC -DSC -verify=foo-warning,foo %s +// RUN: %clang_cc1 -Wcast-qual -DLC -DSC -verify=bar,bar-warning-re %s +// RUN: %clang_cc1 -Wcast-qual -DLC -DSC -verify=bar-warning-re,bar %s + + +// Check invalid prefixes. Check that there's no additional output, which +// might indicate that diagnostic verification became enabled even though it +// was requested incorrectly. Check that prefixes are reported in command-line +// order. +// +// RUN: not %clang_cc1 -verify=5abc,-xy,foo,_k -verify='#a,b$' %s 2> %t +// RUN: FileCheck --check-prefixes=ERR %s < %t +// +// ERR-NOT: {{.}} +// ERR: error: invalid value '5abc' in '-verify=' +// ERR-NEXT: note: -verify prefixes must start with a letter and contain only alphanumeric characters, hyphens, and underscores +// ERR-NEXT: error: invalid value '-xy' in '-verify=' +// ERR-NEXT: note: -verify prefixes must start with a letter and contain only alphanumeric characters, hyphens, and underscores +// ERR-NEXT: error: invalid value '_k' in '-verify=' +// ERR-NEXT: note: -verify prefixes must start with a letter and contain only alphanumeric characters, hyphens, and underscores +// ERR-NEXT: error: invalid value '#a' in '-verify=' +// ERR-NEXT: note: -verify prefixes must start with a letter and contain only alphanumeric characters, hyphens, and underscores +// ERR-NEXT: error: invalid value 'b$' in '-verify=' +// ERR-NEXT: note: -verify prefixes must start with a letter and contain only alphanumeric characters, hyphens, and underscores +// ERR-NOT: {{.}} + + +// Check that our test code actually has expected diagnostics when there's no +// -verify. +// +// RUN: not %clang_cc1 -Wcast-qual -DGC -DLC -DSC %s 2> %t +// RUN: FileCheck --check-prefix=ALL %s < %t +// +// ALL: cannot assign to variable 'glb' with const-qualified type 'const int' +// ALL: variable 'glb' declared const here +// ALL: cast from 'const int *' to 'int *' drops const qualifier +// ALL: initializing 'int *' with an expression of type 'const int *' discards qualifiers + + +#if LC +# define LCONST const +#else +# define LCONST +#endif + +#if SC +# define SCONST const +#else +# define SCONST +#endif + +void foo() { + LCONST int loc = 5; + SCONST static int sta = 5; + // We don't actually expect 1-2 occurrences of this error. We're just + // checking the parsing. + glb = 6; // gconst-error1-2 {{cannot assign to variable 'glb' with const-qualified type 'const int'}} + *(int*)(&loc) = 6; // lconst-warning {{cast from 'const int *' to 'int *' drops const qualifier}} + ; // Code, comments, and many directives with different prefixes per line, including cases where some prefixes (foo and bar) prefix others (such as foo-bar and bar-foo), such that some prefixes appear as normal comments and some have special suffixes (-warning and -re): foo-warning@-1 {{cast from 'const int *' to 'int *' drops const qualifier}} foo-bar-warning@+1 {{initializing 'int *' with an expression of type 'const int *' discards qualifiers}} foo-warning-warning@+1 {{initializing 'int *' with an expression of type 'const int *' discards qualifiers}} bar-warning-re-warning@-1 {{cast from 'const int *' to 'int *' drops const qualifier}} bar-foo-warning@-1 {{cast from 'const int *' to 'int *' drops const qualifier}} bar-warning@+1 {{initializing 'int *' with an expression of type 'const int *' discards qualifiers}} + int *p = &sta; // expected-warning {{initializing 'int *' with an expression of type 'const int *' discards qualifiers}} +} + +// nconst-no-diagnostics +// n-const-no-diagnostics +// n_const-no-diagnostics +// NConst-no-diagnostics +// NConst2-no-diagnostics diff --git a/clang/test/Sema/tautological-unsigned-enum-zero-compare.c b/clang/test/Sema/tautological-unsigned-enum-zero-compare.c index 43b768433db..a32cfcd8329 100644 --- a/clang/test/Sema/tautological-unsigned-enum-zero-compare.c +++ b/clang/test/Sema/tautological-unsigned-enum-zero-compare.c @@ -1,6 +1,10 @@ -// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only -DUNSIGNED -verify %s -// RUN: %clang_cc1 -triple=x86_64-pc-win32 -fsyntax-only -DSIGNED -verify %s -// RUN: %clang_cc1 -triple=x86_64-pc-win32 -fsyntax-only -Wno-tautological-unsigned-enum-zero-compare -verify %s +// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only \ +// RUN: -verify=unsigned,unsigned-signed %s +// RUN: %clang_cc1 -triple=x86_64-pc-win32 -fsyntax-only \ +// RUN: -verify=unsigned-signed %s +// RUN: %clang_cc1 -triple=x86_64-pc-win32 -fsyntax-only \ +// RUN: -Wno-tautological-unsigned-enum-zero-compare \ +// RUN: -verify=silence %s // Okay, this is where it gets complicated. // Then default enum sigdness is target-specific. @@ -12,175 +16,38 @@ int main() { enum B { B_a = -1 }; enum B b; -#ifdef UNSIGNED - if (a < 0) // expected-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}} - return 0; - if (a <= 0) - return 0; - if (0 > a) // expected-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}} - return 0; - if (0 < a) - return 0; - - 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) - 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) // 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; -#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; - - 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) - 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) // 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; -#else - // expected-no-diagnostics + // silence-no-diagnostics - if (a < 0) + 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) + if (0 <= a) // unsigned-warning {{comparison of 0 <= unsigned enum expression is always true}} return 0; if (a <= 0) return 0; - if (0 > a) + if (0 > a) // unsigned-warning {{comparison of 0 > unsigned enum expression is always false}} return 0; - if (a >= 0) + if (a >= 0) // unsigned-warning {{comparison of unsigned enum expression >= 0 is always true}} return 0; if (0 < a) return 0; - if (a < 0U) + 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) + 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) + if (0U > a) // unsigned-signed-warning {{comparison of 0 > unsigned enum expression is always false}} return 0; - if (a >= 0U) + if (a >= 0U) // unsigned-signed-warning {{comparison of unsigned enum expression >= 0 is always true}} return 0; if (0U < a) return 0; @@ -202,23 +69,22 @@ int main() { if (0 < b) return 0; - if (b < 0U) + 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) + 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) + if (0U > b) // unsigned-signed-warning {{comparison of 0 > unsigned enum expression is always false}} return 0; - if (b >= 0U) + if (b >= 0U) // unsigned-signed-warning {{comparison of unsigned enum expression >= 0 is always true}} return 0; if (0U < b) return 0; -#endif if (a == 0) return 0; diff --git a/clang/test/Sema/tautological-unsigned-enum-zero-compare.cpp b/clang/test/Sema/tautological-unsigned-enum-zero-compare.cpp index 5577b68b5eb..a733b6edfc0 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 @@ int main() { 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 @@ int main() { // 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}} - 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; -#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}} + 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; -#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 @@ int test() { 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; diff --git a/clang/test/Sema/tautological-unsigned-zero-compare.c b/clang/test/Sema/tautological-unsigned-zero-compare.c index e0611cb4002..b9ea02a731a 100644 --- a/clang/test/Sema/tautological-unsigned-zero-compare.c +++ b/clang/test/Sema/tautological-unsigned-zero-compare.c @@ -1,7 +1,7 @@ -// RUN: %clang_cc1 -fsyntax-only -DTEST -verify %s -// RUN: %clang_cc1 -fsyntax-only -Wno-tautological-unsigned-zero-compare -verify %s -// RUN: %clang_cc1 -fsyntax-only -DTEST -verify -x c++ %s -// RUN: %clang_cc1 -fsyntax-only -Wno-tautological-unsigned-zero-compare -verify -x c++ %s +// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -Wno-tautological-unsigned-zero-compare -verify=silence %s +// RUN: %clang_cc1 -fsyntax-only -verify -x c++ %s +// RUN: %clang_cc1 -fsyntax-only -Wno-tautological-unsigned-zero-compare -verify=silence -x c++ %s unsigned uvalue(void); signed int svalue(void); @@ -13,13 +13,8 @@ template<typename T> void TFunc() { // Make sure that we do warn for normal variables in template functions ! unsigned char c = svalue(); -#ifdef TEST if (c < 0) // expected-warning {{comparison of unsigned expression < 0 is always false}} return; -#else - if (c < 0) - return; -#endif if (c < macro(0)) return; @@ -39,7 +34,8 @@ int main() unsigned un = uvalue(); -#ifdef TEST + // silence-no-diagnostics + if (un == 0) return 0; if (un != 0) @@ -91,65 +87,10 @@ int main() return 0; if (0UL >= un) return 0; -#else -// expected-no-diagnostics - if (un == 0) - return 0; - if (un != 0) - return 0; - if (un < 0) - return 0; - if (un <= 0) - return 0; - if (un > 0) - return 0; - if (un >= 0) - return 0; - - if (0 == un) - return 0; - if (0 != un) - return 0; - if (0 < un) - return 0; - if (0 <= un) - return 0; - if (0 > un) - return 0; - if (0 >= un) - return 0; - - if (un == 0UL) - return 0; - if (un != 0UL) - return 0; - if (un < 0UL) - return 0; - if (un <= 0UL) - return 0; - if (un > 0UL) - return 0; - if (un >= 0UL) - return 0; - - if (0UL == un) - return 0; - if (0UL != un) - return 0; - if (0UL < un) - return 0; - if (0UL <= un) - return 0; - if (0UL > un) - return 0; - if (0UL >= un) - return 0; -#endif signed int a = svalue(); -#ifdef TEST if (a == 0) return 0; if (a != 0) @@ -201,60 +142,6 @@ int main() return 0; if (0UL >= a) return 0; -#else -// expected-no-diagnostics - if (a == 0) - return 0; - if (a != 0) - return 0; - if (a < 0) - return 0; - if (a <= 0) - return 0; - if (a > 0) - return 0; - if (a >= 0) - return 0; - - if (0 == a) - return 0; - if (0 != a) - return 0; - if (0 < a) - return 0; - if (0 <= a) - return 0; - if (0 > a) - return 0; - if (0 >= a) - return 0; - - if (a == 0UL) - return 0; - if (a != 0UL) - return 0; - if (a < 0UL) - return 0; - if (a <= 0UL) - return 0; - if (a > 0UL) - return 0; - if (a >= 0UL) - return 0; - - if (0UL == a) - return 0; - if (0UL != a) - return 0; - if (0UL < a) - return 0; - if (0UL <= a) - return 0; - if (0UL > a) - return 0; - if (0UL >= a) - return 0; -#endif float fl = 0; |