public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug tree-optimization/104341] New: Bogus -Werror=array-bounds since r12-2582-gb9cbf8c9e0bc72f5 @ 2022-02-02 9:44 marxin at gcc dot gnu.org 2022-02-02 9:58 ` [Bug tree-optimization/104341] " pinskia at gcc dot gnu.org ` (2 more replies) 0 siblings, 3 replies; 4+ messages in thread From: marxin at gcc dot gnu.org @ 2022-02-02 9:44 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104341 Bug ID: 104341 Summary: Bogus -Werror=array-bounds since r12-2582-gb9cbf8c9e0bc72f5 Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: marxin at gcc dot gnu.org CC: msebor at gcc dot gnu.org Target Milestone: --- Reduced from qemu package: $ cat acpi.i int memcpy_src_u_0_0, acpi_sx_zsdt_acpi; char acpi_sx_zsdt_buf_0_0; static void *memcpy2(void *dest, void *, int) { void *__trans_tmp_2 = dest; union { int u32[2]; } *dest_u = __trans_tmp_2; dest_u->u32[0] = memcpy_src_u_0_0; return 0; } void copy_from_user(void *dest) { long __trans_tmp_4 = (long)dest, __trans_tmp_3 = __trans_tmp_4; memcpy2((void *)__trans_tmp_3, 0, 0); } int acpi_sx_zsdt() { copy_from_user(&acpi_sx_zsdt_acpi); return acpi_sx_zsdt_buf_0_0; } $ gcc acpi.i -c -Werror=array-bounds -O2 In function ‘memcpy2’, inlined from ‘copy_from_user’ at acpi.i:13:3, inlined from ‘acpi_sx_zsdt’ at acpi.i:16:3: acpi.i:8:18: error: array subscript ‘union <anonymous>[0]’ is partly outside array bounds of ‘int[1]’ [-Werror=array-bounds] 8 | dest_u->u32[0] = memcpy_src_u_0_0; | ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~ acpi.i: In function ‘acpi_sx_zsdt’: acpi.i:1:23: note: object ‘acpi_sx_zsdt_acpi’ of size 4 1 | int memcpy_src_u_0_0, acpi_sx_zsdt_acpi; | ^~~~~~~~~~~~~~~~~ cc1: some warnings being treated as errors ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug tree-optimization/104341] Bogus -Werror=array-bounds since r12-2582-gb9cbf8c9e0bc72f5 2022-02-02 9:44 [Bug tree-optimization/104341] New: Bogus -Werror=array-bounds since r12-2582-gb9cbf8c9e0bc72f5 marxin at gcc dot gnu.org @ 2022-02-02 9:58 ` pinskia at gcc dot gnu.org 2022-02-02 10:25 ` [Bug tree-optimization/104341] [12 Regression] " rguenth at gcc dot gnu.org 2022-03-08 0:03 ` msebor at gcc dot gnu.org 2 siblings, 0 replies; 4+ messages in thread From: pinskia at gcc dot gnu.org @ 2022-02-02 9:58 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104341 Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Target Milestone|--- |12.0 Keywords| |diagnostic ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug tree-optimization/104341] [12 Regression] Bogus -Werror=array-bounds since r12-2582-gb9cbf8c9e0bc72f5 2022-02-02 9:44 [Bug tree-optimization/104341] New: Bogus -Werror=array-bounds since r12-2582-gb9cbf8c9e0bc72f5 marxin at gcc dot gnu.org 2022-02-02 9:58 ` [Bug tree-optimization/104341] " pinskia at gcc dot gnu.org @ 2022-02-02 10:25 ` rguenth at gcc dot gnu.org 2022-03-08 0:03 ` msebor at gcc dot gnu.org 2 siblings, 0 replies; 4+ messages in thread From: rguenth at gcc dot gnu.org @ 2022-02-02 10:25 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104341 Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Last reconfirmed| |2022-02-02 Status|UNCONFIRMED |NEW Ever confirmed|0 |1 --- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> --- Confirmed. acpi_sx_zsdt_acpi is large enough (but not large enough to hold the union type so techincally undefined) ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug tree-optimization/104341] [12 Regression] Bogus -Werror=array-bounds since r12-2582-gb9cbf8c9e0bc72f5 2022-02-02 9:44 [Bug tree-optimization/104341] New: Bogus -Werror=array-bounds since r12-2582-gb9cbf8c9e0bc72f5 marxin at gcc dot gnu.org 2022-02-02 9:58 ` [Bug tree-optimization/104341] " pinskia at gcc dot gnu.org 2022-02-02 10:25 ` [Bug tree-optimization/104341] [12 Regression] " rguenth at gcc dot gnu.org @ 2022-03-08 0:03 ` msebor at gcc dot gnu.org 2 siblings, 0 replies; 4+ messages in thread From: msebor at gcc dot gnu.org @ 2022-03-08 0:03 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104341 Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Resolution|--- |DUPLICATE Status|NEW |RESOLVED --- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> --- By using a larger type to access a smaller object the code violates the strict aliasing rule, and this instance of the warning for it is intended. The problem can be reduced to the following test case where GCC points out the aliasing violation by -Wincompatible-pointer-types, besides also issuing -Warray-bounds. The warning could stand to be rephrased to make the problem clearer and moved under the -Wstrict-alising option (which would also avoid it in code bases like the Linux kernel that use -fno-strict-aliasing). I submitted a patch to do all that last March in an effort to resolve pr98503 of which this effectively a duplicate, but the reviewer declined to approve it. $ cat pr104341.c && gcc -O2 -S -Wall pr104341.c int acpi_sx_zsdt_acpi; void f (void) { union { int u32[2]; } *d = &acpi_sx_zsdt_acpi; d->u32[0] = 0; } pr104341.c: In function ‘f’: pr104341.c:7:10: warning: initialization of ‘union <anonymous> *’ from incompatible pointer type ‘int *’ [-Wincompatible-pointer-types] 7 | } *d = &acpi_sx_zsdt_acpi; | ^ pr104341.c:9:4: warning: array subscript ‘union <anonymous>[0]’ is partly outside array bounds of ‘int[1]’ [-Warray-bounds] 9 | d->u32[0] = 0; | ^~ pr104341.c:1:5: note: object ‘acpi_sx_zsdt_acpi’ of size 4 1 | int acpi_sx_zsdt_acpi; | ^~~~~~~~~~~~~~~~~ *** This bug has been marked as a duplicate of bug 98503 *** ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-03-08 0:03 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2022-02-02 9:44 [Bug tree-optimization/104341] New: Bogus -Werror=array-bounds since r12-2582-gb9cbf8c9e0bc72f5 marxin at gcc dot gnu.org 2022-02-02 9:58 ` [Bug tree-optimization/104341] " pinskia at gcc dot gnu.org 2022-02-02 10:25 ` [Bug tree-optimization/104341] [12 Regression] " rguenth at gcc dot gnu.org 2022-03-08 0:03 ` msebor at gcc dot gnu.org
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).