This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/59124] [5/6/7 Regression] Wrong warnings "array subscript is above array bounds"
- From: "ppalka at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 30 Aug 2016 13:18:19 +0000
- Subject: [Bug tree-optimization/59124] [5/6/7 Regression] Wrong warnings "array subscript is above array bounds"
- Auto-submitted: auto-generated
- References: <bug-59124-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59124
--- Comment #42 from Patrick Palka <ppalka at gcc dot gnu.org> ---
(In reply to Szőts Ákos from comment #41)
> A newer example:
>
> int main() {
> bool exists = true;
> int i = 0;
> int sum = 0;
>
> volatile int array_size = 7;
> volatile int array[7];
>
> while (exists)
> {
> for (i = 0; i < array_size - 1; i++)
> {
> if (array[i] == 0) sum += array[i + 1];
> exists = false;
> }
> }
>
> return 0;
> }
>
> Can be reproduced both by v5.3.0 and v6.1.1 with "g++ -O3 -Wall main.cpp".
Isn't this warning valid? By marking array_size as volatile you are telling
the compiler that its value could change at any time. So the loop won't
necessarily terminate once i == 6.