From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 67B1D3858415; Sun, 19 Sep 2021 11:02:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 67B1D3858415 From: "cazfi74 at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/102405] New: Loop index limited by a function return value considered to result in too big array subscript Date: Sun, 19 Sep 2021 11:02:43 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: cazfi74 at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 19 Sep 2021 11:02:43 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102405 Bug ID: 102405 Summary: Loop index limited by a function return value considered to result in too big array subscript Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: cazfi74 at gmail dot com Target Milestone: --- For a code where for-loop terminates before index variable gets value 25*8, compiler gives a warning that the variable/8 used as array subscript has va= lue of 25 and is thus above array bounds. Warning (turned to an error by -Werror): In function 'pick_random_tech_to_lose', inlined from 'update_bulbs' at ../../../src/server/techtools.c:621:42: ../../../src/server/techtools.c:674:271: error: array subscript 25 is above array bounds of 'unsigned char[25]' [-Werror=3Darray-bounds] 674 | if (BV_ISSET(eligible_techs, i)) { |=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20 =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20 ^=20=20=20=20=20=20=20=20=20=20 In file included from ../../../src/common/player.h:31, from ../../../src/common/game.h:36, from ../../../src/server/techtools.c:27: ../../../src/common/tech.h: In function 'update_bulbs': ../../../src/common/tech.h:144:32: note: while referencing 'vec' 144 | BV_DEFINE(bv_techs, A_LAST); | ^=20=20 cc1: all warnings being treated as errors The code compiles fine with gcc-11 (and number of earlier versions). It has failed for some weeks with the Debian's gcc-12 development snapshot, with latest update just today: $ /usr/lib/gcc-snapshot/bin/gcc --version gcc (Debian 20210918-1) 12.0.0 20210918 (experimental) [master r12-3644-g7afcb534239] Copyright (C) 2021 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. The loop termination is determined by a function call, like this: 'for (; _index < advance_count(); _index++) {' If 'advance_count()' is replaced by '(25*8)', it compiles fine. The compiler doesn't know what values advance_count() can return (it's implemented in a different source file) - the compile fails even if it's implemented as simp= le 'return 25*8;' There's a lot of macro magic around in the original code (if you think that= the warning is what one should get from the attached .i, then the bug is probab= ly preprocessor side) The command line: /usr/lib/gcc-snapshot/bin/gcc -v -save-temps -DHAVE_CONFIG_H -I. -I../../../src/server -I../gen_headers -I../../../src/ai -I../../../src/ai/classic -I../../../src/common -I../../../src/common/aicore -I../../../src/common/scriptcore -I../../../src/utility -I../../../src/server/advisors -I../../../src/server/generator -I../../../src/server/scripting -DLOCALEDIR=3D"/usr/local/share/locale" -DBINDIR=3D"/usr/local/bin" -DFC_CONF_PATH=3D"/usr/local/etc/freeciv" -DDEFAULT_DATA_PATH=3D".:data:~/.freeciv/2.6:/usr/local/share/freeciv" -DDEFAULT_SAVE_PATH=3D".:~/.freeciv/saves" -DDEFAULT_SCENARIO_PATH=3D".:data/scenarios:~/.freeciv/2.6/scenarios:~/.fre= eciv/scenarios:/usr/local/share/freeciv/scenarios" -Wall -Wpointer-arith -Wcast-align -Werror -Wmissing-prototypes -Wmissing-declarations -Wformat -Wformat-security -Wnested-externs -Wshadow -Wold-style-declaration -Wno-tautological-compare -Wno-nonnull-compare -g -= O2 -MT techtools.lo -MD -MP -MF .deps/techtools.Tpo -c ../../../src/server/techtools.c -o techtools.o=