[Sema] Fixes for enum handling for tautological comparison diagnostics
authorRoman Lebedev <lebedev.ri@gmail.com>
Sat, 21 Oct 2017 16:44:03 +0000 (16:44 +0000)
committerRoman Lebedev <lebedev.ri@gmail.com>
Sat, 21 Oct 2017 16:44:03 +0000 (16:44 +0000)
commitca1aaacc325d219318889967087f9f888f1833fe
tree2334352b1dfb58ee21bc3565abc8ec74b861e0a2
parentf45629d2bbdeb48eb8ffb627ce8082b1096e5619
[Sema] Fixes for enum handling for tautological comparison diagnostics

Summary:
As Mattias Eriksson has reported in PR35009, in C, for enums, the underlying type should
be used when checking for the tautological comparison, unlike C++, where the enumerator
values define the value range. So if not in CPlusPlus mode, use the enum underlying type.

Also, i have discovered a problem (a crash) when evaluating tautological-ness of the following comparison:
```
enum A { A_a = 0 };
if (a < 0) // expected-warning {{comparison of unsigned enum expression < 0 is always false}}
return 0;
```
This affects both the C and C++, but after the first fix, only C++ code was affected.
That was also fixed, while preserving (i think?) the proper diagnostic output.

And while there, attempt to enhance the test coverage.
Yes, some tests got moved around, sorry about that :)

Fixes PR35009

Reviewers: aaron.ballman, rsmith, rjmccall

Reviewed By: aaron.ballman

Subscribers: Rakete1111, efriedma, materi, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D39122

llvm-svn: 316268
clang/lib/Sema/SemaChecking.cpp
clang/test/Sema/outof-range-enum-constant-compare.c [new file with mode: 0644]
clang/test/Sema/tautological-constant-enum-compare.c [new file with mode: 0644]
clang/test/Sema/tautological-unsigned-enum-zero-compare.c
clang/test/Sema/tautological-unsigned-enum-zero-compare.cpp