public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "msebor at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/97027] missing warning on buffer overflow storing a larger scalar into a smaller array
Date: Tue, 13 Oct 2020 16:55:01 +0000	[thread overview]
Message-ID: <bug-97027-4-mHK8SDQMx5@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-97027-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
Another test case.  Of the buffer overflow in the four functions in it, only a
subset is diagnosed.  The subset depends on the form of the assignment in the
IL which in turn changes from target to target.  The output below is for
aarch64 which is different for x86_64.

$ cat xx.c && gcc -O2 -S -fdump-tree-optimized=/dev/stdout xx.c
void f16 (char c)
{
  typedef __attribute__ ((__vector_size__ (16))) char C16;

  extern char a16[16];
  void *p = a16 + 1;
  *(C16*)p = (C16){ c };
}

void f32 (char c)
{
  typedef __attribute__ ((__vector_size__ (32))) char C32;

  extern char a32[32];
  void *p = a32 + 1;
  *(C32*)p = (C32){ c };
}

void f64 (char c)
{
  typedef __attribute__ ((__vector_size__ (64))) char C64;

  extern char a64[64];
  void *p = a64 + 1;
  *(C64*)p = (C64){ c };
}

void f128 (char c)
{
  typedef __attribute__ ((__vector_size__ (128))) char C128;

  extern char a128[128];
  void *p = a128 + 1;
  *(C128*)p = (C128){ c };
}


;; Function f16 (f16, funcdef_no=0, decl_uid=3585, cgraph_uid=1,
symbol_order=0)

f16 (char c)
{
  vector(16) char _1;

  <bb 2> [local count: 1073741824]:
  _1 = {c_2(D)};
  MEM[(C16 *)&a16 + 1B] = _1;
  return;

}



;; Function f32 (f32, funcdef_no=1, decl_uid=3593, cgraph_uid=2,
symbol_order=1)

f32 (char c)
{
  vector(32) char _1;

  <bb 2> [local count: 1073741824]:
  _1 = {c_2(D)};
  MEM[(C32 *)&a32 + 1B] = _1;
  return;

}



;; Function f64 (f64, funcdef_no=2, decl_uid=3601, cgraph_uid=3,
symbol_order=2)

f64 (char c)
{
  vector(64) char _1;

  <bb 2> [local count: 1073741824]:
  _1 = {c_2(D)};
  MEM[(C64 *)&a64 + 1B] = _1;
  return;

}


xx.c: In function 'f128':
xx.c:34:13: warning: writing 1 byte into a region of size 0
[-Wstringop-overflow=]
   34 |   *(C128*)p = (C128){ c };
      |   ~~~~~~~~~~^~~~~~~~~~~~~
xx.c:32:15: note: at offset 128 to object 'a128' with size 128 declared here
   32 |   extern char a128[128];
      |               ^~~~

;; Function f128 (f128, funcdef_no=3, decl_uid=3609, cgraph_uid=4,
symbol_order=3)

f128 (char c)
{
  <bb 2> [local count: 1073741824]:
  BIT_FIELD_REF <MEM[(C128 *)&a128 + 1B], 8, 0> = c_2(D);
  MEM <unsigned long> [(C128 *)&a128 + 2B] = 0;
  MEM <unsigned long> [(C128 *)&a128 + 10B] = 0;
  MEM <unsigned long> [(C128 *)&a128 + 18B] = 0;
  MEM <unsigned long> [(C128 *)&a128 + 26B] = 0;
  MEM <unsigned long> [(C128 *)&a128 + 34B] = 0;
  MEM <unsigned long> [(C128 *)&a128 + 42B] = 0;
  MEM <unsigned long> [(C128 *)&a128 + 50B] = 0;
  MEM <unsigned long> [(C128 *)&a128 + 58B] = 0;
  MEM <unsigned long> [(C128 *)&a128 + 66B] = 0;
  MEM <unsigned long> [(C128 *)&a128 + 74B] = 0;
  MEM <unsigned long> [(C128 *)&a128 + 82B] = 0;
  MEM <unsigned long> [(C128 *)&a128 + 90B] = 0;
  MEM <unsigned long> [(C128 *)&a128 + 98B] = 0;
  MEM <unsigned long> [(C128 *)&a128 + 106B] = 0;
  MEM <unsigned long> [(C128 *)&a128 + 114B] = 0;
  MEM <unsigned int> [(C128 *)&a128 + 122B] = 0;
  MEM <unsigned short> [(C128 *)&a128 + 126B] = 0;
  BIT_FIELD_REF <MEM[(C128 *)&a128 + 1B], 8, 1016> = 0;
  return;

}

  parent reply	other threads:[~2020-10-13 16:55 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-11 21:10 [Bug middle-end/97027] New: " msebor at gcc dot gnu.org
2020-10-13 16:53 ` [Bug middle-end/97027] " msebor at gcc dot gnu.org
2020-10-13 16:55 ` msebor at gcc dot gnu.org [this message]
2020-10-13 19:07 ` msebor at gcc dot gnu.org
2021-07-07 20:14 ` cvs-commit at gcc dot gnu.org
2021-07-07 20:30 ` msebor at gcc dot gnu.org
2021-07-09 17:38 ` msebor at gcc dot gnu.org
2021-07-09 17:54 ` msebor at gcc dot gnu.org
2021-07-13 19:27 ` msebor at gcc dot gnu.org
2021-07-13 19:27 ` msebor at gcc dot gnu.org
2021-07-15  9:22 ` clyon at gcc dot gnu.org
2021-07-15 19:16 ` cvs-commit at gcc dot gnu.org
2021-07-15 19:22 ` msebor at gcc dot gnu.org

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-97027-4-mHK8SDQMx5@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: link
Be 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).