summaryrefslogtreecommitdiffstats
path: root/clang/test/Sema/tautological-constant-compare.c
diff options
context:
space:
mode:
authorHans Wennborg <hans@hanshq.net>2017-12-08 16:54:08 +0000
committerHans Wennborg <hans@hanshq.net>2017-12-08 16:54:08 +0000
commit5791ce77baa8eeba268bffb40a2757bea1de8741 (patch)
treea972435d546cace39619740f74d647ba69591818 /clang/test/Sema/tautological-constant-compare.c
parent19d460b066d755f188c03b28a4063d3d0c32a89a (diff)
downloadbcm5719-llvm-5791ce77baa8eeba268bffb40a2757bea1de8741.tar.gz
bcm5719-llvm-5791ce77baa8eeba268bffb40a2757bea1de8741.zip
Revert "Unify implementation of our two different flavours of -Wtautological-compare."
> Unify implementation of our two different flavours of -Wtautological-compare. > > In so doing, fix a handful of remaining bugs where we would report false > positives or false negatives if we promote a signed value to an unsigned type > for the comparison. This caused a new warning in Chromium: ../../base/trace_event/trace_log.cc:1545:29: error: comparison of constant 64 with expression of type 'unsigned int' is always true [-Werror,-Wtautological-constant-out-of-range-compare] DCHECK(handle.event_index < TraceBufferChunk::kTraceBufferChunkSize); ~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The 'unsigned int' is really a 6-bit bitfield, which is why it's always less than 64. I thought we didn't use to warn (with out-of-range-compare) when comparing against the boundaries of a type? llvm-svn: 320162
Diffstat (limited to 'clang/test/Sema/tautological-constant-compare.c')
-rw-r--r--clang/test/Sema/tautological-constant-compare.c65
1 files changed, 6 insertions, 59 deletions
diff --git a/clang/test/Sema/tautological-constant-compare.c b/clang/test/Sema/tautological-constant-compare.c
index 02a8c6d0f05..b9ade2a2db4 100644
--- a/clang/test/Sema/tautological-constant-compare.c
+++ b/clang/test/Sema/tautological-constant-compare.c
@@ -94,17 +94,15 @@ int main()
if (-32768 >= s)
return 0;
- // Note: both sides are promoted to unsigned long prior to the comparison, so
- // it is perfectly possible for a short to compare greater than 32767UL.
if (s == 32767UL)
return 0;
if (s != 32767UL)
return 0;
if (s < 32767UL)
return 0;
- if (s <= 32767UL)
+ if (s <= 32767UL) // expected-warning {{comparison 'short' <= 32767 is always true}}
return 0;
- if (s > 32767UL)
+ if (s > 32767UL) // expected-warning {{comparison 'short' > 32767 is always false}}
return 0;
if (s >= 32767UL)
return 0;
@@ -113,66 +111,13 @@ int main()
return 0;
if (32767UL != s)
return 0;
- if (32767UL < s)
+ if (32767UL < s) // expected-warning {{comparison 32767 < 'short' is always false}}
return 0;
if (32767UL <= s)
return 0;
if (32767UL > s)
return 0;
- if (32767UL >= s)
- return 0;
-
- if (s == 0UL)
- return 0;
- if (s != 0UL)
- return 0;
- if (s < 0UL) // expected-warning {{comparison of unsigned expression < 0 is always false}}
- return 0;
- if (s <= 0UL)
- return 0;
- if (s > 0UL)
- return 0;
- if (s >= 0UL) // expected-warning {{comparison of unsigned expression >= 0 is always true}}
- return 0;
-
- if (0UL == s)
- return 0;
- if (0UL != s)
- return 0;
- if (0UL < s)
- return 0;
- if (0UL <= s) // expected-warning {{comparison of 0 <= unsigned expression is always true}}
- return 0;
- if (0UL > s) // expected-warning {{comparison of 0 > unsigned expression is always false}}
- return 0;
- if (0UL >= s)
- return 0;
-
- enum { ULONG_MAX = (2UL * (unsigned long)__LONG_MAX__ + 1UL) };
- if (s == 2UL * (unsigned long)__LONG_MAX__ + 1UL)
- return 0;
- if (s != 2UL * (unsigned long)__LONG_MAX__ + 1UL)
- return 0;
- if (s < 2UL * (unsigned long)__LONG_MAX__ + 1UL)
- return 0;
- if (s <= 2UL * (unsigned long)__LONG_MAX__ + 1UL) // expected-warning-re {{comparison 'short' <= {{.*}} is always true}}
- return 0;
- if (s > 2UL * (unsigned long)__LONG_MAX__ + 1UL) // expected-warning-re {{comparison 'short' > {{.*}} is always false}}
- return 0;
- if (s >= 2UL * (unsigned long)__LONG_MAX__ + 1UL)
- return 0;
-
- if (2UL * (unsigned long)__LONG_MAX__ + 1UL == s)
- return 0;
- if (2UL * (unsigned long)__LONG_MAX__ + 1UL != s)
- return 0;
- if (2UL * (unsigned long)__LONG_MAX__ + 1UL < s) // expected-warning-re {{comparison {{.*}} < 'short' is always false}}
- return 0;
- if (2UL * (unsigned long)__LONG_MAX__ + 1UL <= s)
- return 0;
- if (2UL * (unsigned long)__LONG_MAX__ + 1UL > s)
- return 0;
- if (2UL * (unsigned long)__LONG_MAX__ + 1UL >= s) // expected-warning-re {{comparison {{.*}} >= 'short' is always true}}
+ if (32767UL >= s) // expected-warning {{comparison 32767 >= 'short' is always true}}
return 0;
// FIXME: assumes two's complement
@@ -336,6 +281,8 @@ int main()
if (0 >= s)
return 0;
+ // However the comparison with 0U would warn
+
unsigned short us = value();
#ifdef TEST
OpenPOWER on IntegriCloud