https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80087
Bug ID: 80087
Summary: missing -Wtautological-compare with non-constant
operands
Product: gcc
Version: 7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
The test case below, reduced from bug 80048, shows that GCC diagnoses only
trivial cases of pointless comparisons. Enhancing the warning to (also) run
later, with the benefit of data flow analysis, as opposed to during parsing,
would make it possible to diagnose some of these less obvious bugs.
$ cat a.c && gcc -O2 -S -Wall -Wextra -Wpedantic a.c
void f (int);
void f1 (int n)
{
if (n != n) // warning, ok
f (n);
int i = n;
if (i != n) // missing warning
f (i);
for (int i = n; i != n; ++i) // missing warning
f (i);
}
struct S { int *a, *b; };
void f2 (struct S *s)
{
for (int *p = s->a; p != s->a; ++p) // missing warning
f (*p);
}
a.c: In function ‘f1’:
a.c:5:9: warning: self-comparison always evaluates to false
[-Wtautological-compare]
if (n != n) // warning, ok
^~