airbus-seclab / c-compiler-security

Security-related flags and options for C compilers
https://airbus-seclab.github.io/c-compiler-security/
Creative Commons Attribution Share Alike 4.0 International
181 stars 16 forks source link

clang + -Wtautological-constant-in-range-compare #9

Closed szennou closed 3 years ago

szennou commented 3 years ago

Don't understand how the definition you give relies with the term "tautology" that refers to predicates that are always true

trou commented 3 years ago

Indeed, the examples are not obvious. From the test file:

int ints(long a, unsigned long b) {
  enum EnumA {A};
  enum EnumB {B};
  enum EnumC {C = 0x10000};
[...]
         (a < (unsigned long) B) +  // expected-warning {{comparison of unsigned expression < 0 is always false}}
[...]
         (C == (unsigned short) b) + // expected-warning {{comparison of constant 'C' (65536) with expression of type 'unsigned short' is always false}}