This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/69359] Warn about constant comparisons between pointers and arrays
- From: "fw at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 20 Jan 2016 12:16:43 +0000
- Subject: [Bug tree-optimization/69359] Warn about constant comparisons between pointers and arrays
- Auto-submitted: auto-generated
- References: <bug-69359-4 at http dot gcc dot gnu dot org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69359
--- Comment #2 from Florian Weimer <fw at gcc dot gnu.org> ---
(In reply to Jakub Jelinek from comment #1)
> I'd find warning about p <= weird, warning about p < a makes sense, as well
> as e.g.
> int g (void)
> {
> int a[3], b;
> int *p = f (a, &b);
> return (p < a)
> + (p < &a[0])
> + (p > &a[3])
> + (p < &b)
> + (p > &b + 1);
> }
> Not a stage4 material though.
Agreed.
>From my perspective, p <= a is suspicious for the same reason why u <= 0 for an
unsigned variable u is suspicious. If the range of the variable is limited and
the condition can only be true if there is equality, why not use == instead of
<=? <= suggests that the programmer expected something to happen in the code
which is impossible, which could point to a logic bug or illegal program, and I
think it is fine to warn in such cases.