This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/53871] Please warn about endless loops if they are obvious
- From: "pinskia at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 30 Dec 2015 20:02:09 +0000
- Subject: [Bug c/53871] Please warn about endless loops if they are obvious
- Auto-submitted: auto-generated
- References: <bug-53871-4 at http dot gcc dot gnu dot org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53871
--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to David Binderman from comment #6)
> Derived from the current Linux kernel:
>
> // i never changes, so the code loops forever.
>
> extern int f2( int);
>
> void f1()
> {
> int i = 0;
>
> do {
> int n = f2( i);
>
> if (n < 0 || n > 10)
> break;
> } while (i < 8);
> }
>
> $ ~/gcc/results/bin/gcc -c -g -O2 -Wall -Wextra dec30b.cc
> $
The above loop is not so obvious an infinite loop at all. Since f2 is not
declared as pure/const, GCC can think the return value changes without the
argument changing. So the example in comment #6 is not an obvious example :).