public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "christophm30 at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/104657] array subscript 0 is outside array bounds Date: Wed, 23 Feb 2022 22:17:58 +0000 [thread overview] Message-ID: <bug-104657-4-PuQk2hUdQX@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-104657-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104657 --- Comment #4 from Christoph Müllner <christophm30 at gmail dot com> --- Thanks for mentioning the volatile pointer method. However, the pragma-solution results in better code (fewer instructions and does not require a valid stack pointer). I've used the code below to see what happens on AArch64 and RISC-V 64-bit: #define MEM_ADDR 0xffff8000 void foo_warning(unsigned long v) { volatile unsigned long * p; p = (void*)MEM_ADDR; *p = v; } void foo_warningfree(unsigned long v) { volatile unsigned long * p; p = (void*)MEM_ADDR; #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Warray-bounds" *p = v; #pragma GCC diagnostic pop } void foo_volatile(unsigned long v) { volatile unsigned long * volatile p; p = (void*)MEM_ADDR; *p = v; } AArch64: foo_warning: mov x1, 4294934528 str x0, [x1] ret foo_warningfree: mov x1, 4294934528 str x0, [x1] ret foo_volatile: sub sp, sp, #16 mov x1, 4294934528 str x1, [sp, 8] ldr x1, [sp, 8] str x0, [x1] add sp, sp, 16 ret RISC-V 64-bit: foo_warning: li a5,536866816 slli a5,a5,3 sd a0,0(a5) ret foo_warningfree: li a5,536866816 slli a5,a5,3 sd a0,0(a5) ret foo_volatile: li a5,536866816 addi sp,sp,-16 slli a5,a5,3 sd a5,8(sp) ld a5,8(sp) sd a0,0(a5) addi sp,sp,16 jr ra
next prev parent reply other threads:[~2022-02-23 22:17 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-02-23 10:18 [Bug tree-optimization/104657] New: " christophm30 at gmail dot com 2022-02-23 10:36 ` [Bug tree-optimization/104657] " pinskia at gcc dot gnu.org 2022-02-23 11:14 ` christophm30 at gmail dot com 2022-02-23 18:16 ` msebor at gcc dot gnu.org 2022-02-23 22:17 ` christophm30 at gmail dot com [this message] 2022-02-23 22:35 ` christophm30 at gmail dot com
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-104657-4-PuQk2hUdQX@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).