public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/99578] New: gcc-11 -Warray-bounds or -Wstringop-overread warning when accessing a pointer from integer literal
@ 2021-03-13 14:23 arnd at linaro dot org
  2021-03-13 20:40 ` [Bug c/99578] " msebor at gcc dot gnu.org
                   ` (41 more replies)
  0 siblings, 42 replies; 43+ messages in thread
From: arnd at linaro dot org @ 2021-03-13 14:23 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99578

            Bug ID: 99578
           Summary: gcc-11 -Warray-bounds or -Wstringop-overread warning
                    when accessing a pointer from integer literal
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: arnd at linaro dot org
  Target Milestone: ---

This snippet from the Linux kernel reads a data structure from an
architecturally defined location in memory into a local copy:

struct sharpsl_param_info {
  unsigned int comadj_keyword;
};
extern struct sharpsl_param_info sharpsl_param;
typedef unsigned long __kernel_size_t;
extern void * memcpy(void *, const void *, __kernel_size_t);
void sharpsl_save_param(void)
{
 memcpy(&sharpsl_param, (void *)(0xe8ffc000), sizeof(struct
sharpsl_param_info));
}

With gcc-11, this now triggers a -Wstringop-overread warning on x86:

arch/arm/common/sharpsl_param.i: In function ‘sharpsl_save_param’:
arch/arm/common/sharpsl_param.i:11:2: warning: ‘memcpy’ reading 4 bytes from a
region of size 0 [-Wstringop-overread]
   11 |  memcpy(&sharpsl_param, (void *)(0xe8ffc000), sizeof(struct
sharpsl_param_info));


I tried to reproduce this on godbolt.org, which apparently has a slightly
different snapshot version and instead produces -Warray-bounds warning for the
same input: https://godbolt.org/z/ve6h6b

I could not find a way to avoid this warning, other than turning off the entire
warning option globally or with a pragma. Accessing a pointer from a literal
integer value is not too unusual in the kernel and should not cause a warning.

^ permalink raw reply	[flat|nested] 43+ messages in thread

end of thread, other threads:[~2022-03-30  8:16 UTC | newest]

Thread overview: 43+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-13 14:23 [Bug c/99578] New: gcc-11 -Warray-bounds or -Wstringop-overread warning when accessing a pointer from integer literal arnd at linaro dot org
2021-03-13 20:40 ` [Bug c/99578] " msebor at gcc dot gnu.org
2021-03-13 21:40 ` arnd at linaro dot org
2021-03-13 22:38 ` arnd at linaro dot org
2021-03-14  0:57 ` [Bug middle-end/99578] " msebor at gcc dot gnu.org
2021-03-14 11:54 ` arnd at linaro dot org
2021-03-14 21:25 ` arnd at linaro dot org
2021-03-15  8:38 ` rguenth at gcc dot gnu.org
2021-03-15 19:57 ` msebor at gcc dot gnu.org
2021-03-15 20:24 ` msebor at gcc dot gnu.org
2021-04-21 19:34 ` pinskia at gcc dot gnu.org
2021-04-28 16:11 ` msebor at gcc dot gnu.org
2021-05-01 15:08 ` andi-gcc at firstfloor dot org
2021-05-19 15:07 ` msebor at gcc dot gnu.org
2021-05-19 18:01 ` andrew.cooper3 at citrix dot com
2021-05-19 19:19 ` andrew.cooper3 at citrix dot com
2021-05-19 20:48 ` msebor at gcc dot gnu.org
2021-05-30 23:40 ` msebor at gcc dot gnu.org
2021-08-24 16:03 ` pinskia at gcc dot gnu.org
2021-09-14 18:46 ` [Bug middle-end/99578] [11/12 Regression] " pinskia at gcc dot gnu.org
2021-12-19 11:36 ` pinskia at gcc dot gnu.org
2021-12-21 13:53 ` pmenzel+gcc at molgen dot mpg.de
2022-01-14 15:57 ` pmenzel+gcc at molgen dot mpg.de
2022-01-21 13:18 ` rguenth at gcc dot gnu.org
2022-02-23 10:36 ` pinskia at gcc dot gnu.org
2022-02-23 12:53 ` jakub at gcc dot gnu.org
2022-02-23 16:50 ` msebor at gcc dot gnu.org
2022-02-23 16:57 ` jakub at gcc dot gnu.org
2022-02-23 17:55 ` msebor at gcc dot gnu.org
2022-03-07 19:30 ` pinskia at gcc dot gnu.org
2022-03-07 20:53 ` goswin-v-b at web dot de
2022-03-16 19:49 ` kees at outflux dot net
2022-03-16 21:15 ` msebor at gcc dot gnu.org
2022-03-16 23:10 ` jwerner at chromium dot org
2022-03-17 10:49 ` redi at gcc dot gnu.org
2022-03-17 10:53 ` redi at gcc dot gnu.org
2022-03-17 12:52 ` jakub at gcc dot gnu.org
2022-03-18 18:02 ` cvs-commit at gcc dot gnu.org
2022-03-18 18:05 ` [Bug middle-end/99578] [11 " jakub at gcc dot gnu.org
2022-03-19 11:02 ` goswin-v-b at web dot de
2022-03-29  5:54 ` cvs-commit at gcc dot gnu.org
2022-03-30  8:04 ` marxin at gcc dot gnu.org
2022-03-30  8:16 ` jakub 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).