diff options
author | Richard Trieu <rtrieu@google.com> | 2019-09-21 03:02:26 +0000 |
---|---|---|
committer | Richard Trieu <rtrieu@google.com> | 2019-09-21 03:02:26 +0000 |
commit | dbb59f794229857ec4acc86f12f3f9172ec253f6 (patch) | |
tree | 25a8129b9adbbe158f87e6d84c477f5c5fae9f51 /test/Sema | |
parent | ca66650e21db892f1acb156d9f1d082591c0eaac (diff) | |
download | clang-dbb59f794229857ec4acc86f12f3f9172ec253f6.tar.gz |
Merge and improve code that detects same value in comparisons.
-Wtautological-overlap-compare and self-comparison from -Wtautological-compare
relay on detecting the same operand in different locations. Previously, each
warning had it's own operand checker. Now, both are merged together into
one function that each can call. The function also now looks through member
access and array accesses.
Differential Revision: https://reviews.llvm.org/D66045
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@372453 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Sema')
-rw-r--r-- | test/Sema/warn-overlap.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/test/Sema/warn-overlap.c b/test/Sema/warn-overlap.c index d72e60755d..066312591c 100644 --- a/test/Sema/warn-overlap.c +++ b/test/Sema/warn-overlap.c @@ -158,3 +158,17 @@ int no_warning(unsigned x) { return x >= 0 || x == 1; // no warning since "x >= 0" is caught by a different tautological warning. } + +struct A { + int x; + int y; +}; + +int struct_test(struct A a) { + return a.x > 5 && a.y < 1; // no warning, different variables + + return a.x > 5 && a.x < 1; + // expected-warning@-1{{overlapping comparisons always evaluate to false}} + return a.y == 1 || a.y != 1; + // expected-warning@-1{{overlapping comparisons always evaluate to true}} +} |