public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "pinskia at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug ipa/102061] New: .constprop gets exposed in warning message
Date: Wed, 25 Aug 2021 10:35:05 +0000	[thread overview]
Message-ID: <bug-102061-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 102061
           Summary: .constprop gets exposed in warning message
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: enhancement
          Priority: P3
         Component: ipa
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
                CC: marxin at gcc dot gnu.org
  Target Milestone: ---

Take:

static inline void
foo (char *p)
{
  __builtin___memcpy_chk (p, "abc", 3, __builtin_object_size (p, 0));
}
static void
bar (char *p) __attribute__((noinline));
static void
bar (char *p)
{
  foo (p);
}
void f(char*) __attribute__((noipa));
char buf[2];
void
baz (void) __attribute__((noinline));
void
baz (void)
{
  bar (buf);
  f(buf);
}

void f(char*)
{}

int main(void)
{
    baz();
}

---- CUT ---
Compile the C program with "-O2 -Wall", we get:
In function 'foo',
    inlined from 'bar.constprop' at <source>:12:3:
<source>:5:3: warning: '__builtin___memcpy_chk' forming offset 2 is out of the
bounds [0, 2] of object 'buf' with type 'char[2]' [-Warray-bounds]
    5 |   __builtin___memcpy_chk (p, "abc", 3, __builtin_object_size (p, 0));
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>: In function 'bar.constprop':
<source>:15:6: note: 'buf' declared here
   15 | char buf[2];
      |      ^~~

See how bar.constprop is exposed. That is an internal details.
Note compiling it with the C++ front-end we get:
    inlined from 'void bar(char*)' at <source>:12:7:


And then compiling with -flto again we get the bar.constprop.

But really we should add another note saying where the clone was created from.

             reply	other threads:[~2021-08-25 10:35 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-25 10:35 pinskia at gcc dot gnu.org [this message]
2021-08-25 15:42 ` [Bug ipa/102061] " msebor at gcc dot gnu.org
2021-08-26  8:26 ` rguenth at gcc dot gnu.org
2024-06-23 23:00 ` sjames 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-102061-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).