[PATCH] D39122: [Sema] Fixes for enum handling for tautological comparison diagnostics

Roman Lebedev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 20 06:33:56 PDT 2017


lebedev.ri created this revision.
lebedev.ri added a project: clang.

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


Repository:
  rL LLVM

https://reviews.llvm.org/D39122

Files:
  lib/Sema/SemaChecking.cpp
  test/Sema/outof-range-enum-constant-compare.c
  test/Sema/tautological-constant-enum-compare.c
  test/Sema/tautological-unsigned-enum-zero-compare.c
  test/Sema/tautological-unsigned-enum-zero-compare.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39122.119653.patch
Type: text/x-patch
Size: 44194 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171020/7c8d6533/attachment-0001.bin>


More information about the cfe-commits mailing list