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/98484] New: missing -Wstringop-overflow on a multiply inlined calls from system header
Date: Wed, 30 Dec 2020 22:29:08 +0000	[thread overview]
Message-ID: <bug-98484-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 98484
           Summary: missing -Wstringop-overflow on a multiply inlined
                    calls from system header
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

GCC 11 diagnoses invalid accesses by built-in functions like memcpy made in
inlined calls to functions defined in system headers, but apparently only for a
single level of inlining.  When the function that does the invalid access is
itself called from another inline function it isn't diagnosed.  (I noticed this
while looking into pr98465.)

$ cat b.c && gcc -O2 -S -Wall -fdump-tree-optimized=/dev/stdout b.c
# 1 "a.h" 1 3 4
# 2 "a.h" 3 4
static inline void f0 (void *p)
{
  __builtin_memcpy (p, "12345678", 8);
}

static inline void f1 (void *p)
{
  f0 (p);
}

# 1 "b.c" 1

static inline void f2 (void *p)
{
  f0 (p);
}

extern char a[8];

void g0 (void)
{
  f0 (a + 4);   // missing warning
}

void g1 (void)
{
  f1 (a + 4);   // missing warning
}


void g2 (void)
{
  f2 (a + 4);   // missing warning
}


;; Function g0 (g0, funcdef_no=3, decl_uid=1953, cgraph_uid=4, symbol_order=3)

void g0 ()
{
  <bb 2> [local count: 1073741824]:
  __builtin_memcpy (&MEM <char[8]> [(void *)&a + 4B], "12345678", 8); [tail
call]
  return;

}


In file included from b.c:1:
In function ‘f0’,
    inlined from ‘g0’ at b.c:11:3:
a.h:4:3: warning: ‘__builtin_memcpy’ writing 8 bytes into a region of size 4
overflows the destination [-Wstringop-overflow=]
    4 | 
      |   ^                                  
In file included from a.h:12,
                 from b.c:1:
a.h: In function ‘g0’:
b.c:7:13: note: at offset 4 into destination object ‘a’ of size 8
    7 | 
      |             ^

;; Function g1 (g1, funcdef_no=7, decl_uid=1956, cgraph_uid=5, symbol_order=4)

void g1 ()
{
  <bb 2> [local count: 1073741824]:
  __builtin_memcpy (&MEM <char[8]> [(void *)&a + 4B], "12345678", 8); [tail
call]
  return;

}



;; Function g2 (g2, funcdef_no=9, decl_uid=1959, cgraph_uid=6, symbol_order=5)

void g2 ()
{
  <bb 2> [local count: 1073741824]:
  __builtin_memcpy (&MEM <char[8]> [(void *)&a + 4B], "12345678", 8); [tail
call]
  return;

}

             reply	other threads:[~2020-12-30 22:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-30 22:29 msebor at gcc dot gnu.org [this message]
2020-12-30 22:43 ` [Bug middle-end/98484] missing -Wstringop-overflow on invalid accesses to the same object by distinct functions msebor at gcc dot gnu.org
2021-09-26  9:26 ` pinskia 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-98484-4@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).