From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 596723858415; Wed, 6 Oct 2021 16:51:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 596723858415 From: "aldyh at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/102631] -Wmaybe-uninitialized cannot see through a series of PHIs Date: Wed, 06 Oct 2021 16:51:12 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: aldyh at gcc dot gnu.org 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: Message-ID: In-Reply-To: References: 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: Wed, 06 Oct 2021 16:51:12 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102631 --- Comment #3 from Aldy Hernandez --- (In reply to Aldy Hernandez from comment #2) > Created attachment 51562 [details] > similar problem on aarch64 bootstrap $ ./cc1plus calls-aarch64.ii -O2 -quiet -Wall In function =E2=80=98void mark_stack_region_used(poly_uint64, poly_uint64)= =E2=80=99, inlined from =E2=80=98rtx_def* emit_library_call_value_1(int, rtx, rtx, libcall_type, machine_mode, int, rtx_mode_t*)=E2=80=99 at /home/aldyh/src/gcc/gcc/calls.c:4536:29: /home/aldyh/src/gcc/gcc/calls.c:206:26: warning: =E2=80=98const_upper=E2=80= =99 may be used uninitialized in this function [-Wmaybe-uninitialized] 206 | stack_usage_map[i] =3D 1; | ~~~~~~~~~~~~~~~~~~~^~~ /home/aldyh/src/gcc/gcc/calls.c: In function =E2=80=98rtx_def* emit_library_call_value_1(int, rtx, rtx, libcall_type, machine_mode, int, rtx_mode_t*)=E2=80=99: /home/aldyh/src/gcc/gcc/calls.c:202:30: note: =E2=80=98const_upper=E2=80=99= was declared here 202 | unsigned HOST_WIDE_INT const_lower, const_upper; | ^~~~~~~~~~~ As I've described here: https://gcc.gnu.org/pipermail/gcc-patches/2021-October/581045.html If you take the calls.ii file from the aarch64 bootstrap and break on the warning, you can see that the uninitalized use is for const_upper_3934 here: [local count: 315357954]: # const_upper_3934 =3D PHI if (_881 !=3D 0) goto ; [50.00%] else goto ; [50.00%] [local count: 157678977]: if (const_upper_3934 > _6699) goto ; [89.00%] else goto ; [11.00%] [local count: 17344687]: [local count: 157678977]: goto ; [100.00%] [local count: 140334290]: stack_usage_map.481_3930 =3D stack_usage_map; _6441 =3D const_upper_3934 - _6699; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PROBLEMATIC READ HERE ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ _4819 =3D stack_usage_map.481_3930 + _6699; __builtin_memset (_4819, 1, _6441); goto ; [11.00%] const_upper_3934 could be undefined if it comes from BB101 (const_upper_3937(D)), but it only gets read for _881 !=3D 0, so it shouldn't warn. This looks very similar. The source is here, which is obviously properly guarded: static void mark_stack_region_used (poly_uint64 lower_bound, poly_uint64 upper_bound) { unsigned HOST_WIDE_INT const_lower, const_upper; const_lower =3D constant_lower_bound (lower_bound); if (upper_bound.is_constant (&const_upper)) for (unsigned HOST_WIDE_INT i =3D const_lower; i < const_upper; ++i) stack_usage_map[i] =3D 1; else stack_usage_watermark =3D MIN (stack_usage_watermark, const_lower); }=