public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/50460] [4.7 Regression] __builtin___strcpy_chk/__builtin_object_size don't work
Date: Sun, 25 Sep 2011 11:24:00 -0000	[thread overview]
Message-ID: <bug-50460-4-ttC5Mv7GD6@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-50460-4@http.gcc.gnu.org/bugzilla/>

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50460

--- Comment #5 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-09-25 11:11:21 UTC ---
(In reply to comment #4)
> Looking at:
> const char *str1 = "JIHGFEDCBA";
> #define strcpy(x,y) __builtin___strcpy_chk (x, y, __builtin_object_size (x, 1))
> 
> int
> f1 (void)
> {
>   struct A { char buf1[9]; char buf2[1]; } a;
>   strcpy (a.buf1 + (0 + 4), str1 + 5);
>   return 0;
> }
> 
> int
> f2 (void)
> {
>   struct A { char buf1[9]; char buf2[1]; } a;
>   strcpy ((char *) &a + (0 + 4), str1 + 5);
>   return 0;
> }
> 
> int
> f3 (void)
> {
>   struct A { char buf1[9]; char buf2[1]; } a;
>   char *p = (char *) &a;
>   strcpy (p + (0 + 4), str1 + 5);
>   return 0;
> }
> 
> int
> f4 (void)
> {
>   struct A { char buf0; char buf1[9]; char buf2[1]; } a;
>   char *p = (char *) &a;
>   strcpy (p + (0 + 5), str1 + 5);
>   return 0;
> }
> 
> int
> f5 (void)
> {
>   struct A { char buf0; char buf1[9]; char buf2[1]; } a;
>   strcpy ((char *) &a + (0 + 5), str1 + 5);
>   return 0;
> }
> 
> with GCC 4.4, seems we have always reconstructed it into &a.buf1[4].
> So likely we want to reconstruct it from the MEM_REF in the *.objsz pass then.
> If there is union involved, we probably want to reconstruct it to the
> alternative with the largest possible __builtin_object_size (X, 1) resp.
> smallest possible __builtin_object_size (X, 3).

I'm not sure.  What's the C / fortify difference of a.buf1 + 9 vs. a.buf2?
Both would be MEM[&a, 9].  I suppose we didn't re-construct array-refs in
4.4 from

 void *p = a.buf1;
 char *q = p + 4;

so, did we fail with 4.4 here, too?


  parent reply	other threads:[~2011-09-25 11:12 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-20  8:16 [Bug middle-end/50460] New: " hjl.tools at gmail dot com
2011-09-20 10:49 ` [Bug middle-end/50460] " jakub at gcc dot gnu.org
2011-09-20 13:47 ` hjl.tools at gmail dot com
2011-09-22 22:06 ` rguenth at gcc dot gnu.org
2011-09-23  8:34 ` jakub at gcc dot gnu.org
2011-09-25 11:24 ` rguenth at gcc dot gnu.org [this message]
2011-09-26  9:14 ` jakub at gcc dot gnu.org
2011-09-28 12:29 ` rguenth at gcc dot gnu.org
2011-09-28 13:52 ` rguenth at gcc dot gnu.org
2011-09-28 14:01 ` rguenth 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-50460-4-ttC5Mv7GD6@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).