From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D52F33858D33; Mon, 9 Oct 2023 23:53:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D52F33858D33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696895598; bh=qAvf1/VOstcpnYS6TnhvEC9QpPvMmraBJ5yixXN/HtE=; h=From:To:Subject:Date:From; b=x5dDNORZ3/z444/o5MbEo+5ByhPpODyfOIE4WIAoTVp6PZPSJVvAVDqt3ctWBk3KM I/CQY8MHFExqE4fo3EoUJgPmzLTW+NCG3dacMRJ8mDhfL5BiLPti0zn1b0F3dNU4Wa H2o8t/lK9P+MNhDrHeTHOWKLw8uDo1d1wRYMZEKU= From: "abbeyj+gcc at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/111750] New: Spurious -Warray-bounds warning when using member function pointers Date: Mon, 09 Oct 2023 23:53:18 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: abbeyj+gcc 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 attachments.created 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D111750 Bug ID: 111750 Summary: Spurious -Warray-bounds warning when using member function pointers Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: abbeyj+gcc at gmail dot com Target Milestone: --- Created attachment 56086 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D56086&action=3Dedit Reproducer The source code below generates a -Warray-bounds warning which I believe is incorrect. Compile with `g++ -c -Wall -O2`. ``` struct MyClass { void my_method(); }; MyClass g; void pre(); inline void FetchValue(MyClass& c, void(MyClass::*func)()) { pre(); (c.*func)(); } int get_int(); inline int Check() { static const int ret =3D get_int(); return ret; } inline void ReadValue(MyClass& c, void(MyClass::*func)()) { Check(); FetchValue(c, func); } void Main() { ReadValue(g, &MyClass::my_method); } ``` This produces: ``` In function 'void FetchValue(MyClass&, void (MyClass::*)())', inlined from 'void ReadValue(MyClass&, void (MyClass::*)())' at :23:15, inlined from 'void Main()' at :27:14: :11:14: warning: array subscript 'int (**)(...)[0]' is partly outsi= de array bounds of 'MyClass [1]' [-Warray-bounds=3D] 11 | (c.*func)(); | ~~~~~~~~~^~ : In function 'void Main()': :5:9: note: object 'g' of size 1 5 | MyClass g; | ^ ``` Godbolt link: https://godbolt.org/z/6YsWd9xhr That this source produces a -Warray-bounds warning is somewhat surprising s= ince it contains no arrays, no array indexing, and no pointer arithmetic. Small changes such as removing the static variable or manually inlining a function into its caller make the warning go away.=20=20 The earliest version that I've been able to reproduce this with is GCC 11.1= and it still reproduces on the trunk version that's currently available on godbolt.org.=