public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/45249] Indirect variable parameters sometimes cause segmentation fault
Date: Wed, 11 Aug 2010 22:27:00 -0000	[thread overview]
Message-ID: <20100811222727.27095.qmail@sourceware.org> (raw)
In-Reply-To: <bug-45249-19547@http.gcc.gnu.org/bugzilla/>



------- Comment #36 from rguenth at gcc dot gnu dot org  2010-08-11 22:27 -------
(In reply to comment #35)
> (In reply to comment #33)
> > Yes GCC implements that ABI and &argument will get you the address of that
> > argument.
> 
> If that is so then the format parameter will be placed at some address X, param
> 1 at address X+4, param 2 at address X+8, and param 3 at X+12. Figure 3-48
> shows these addresses to be very predictable and well defined. It is very
> important for you to follow this reasoning, as this makes all the difference.
> This is what makes X an array of 4 entries, and not simply an array of 1
> isolated entry.

It doesn't make it an array in the C sense.

> > But that does not deter from that &argument will produce an array of
> > size 1 rather than what you want which is the rest of the arguments too.
> 
> Can you backup your claim that "&argument will produce an array of size 1"? Can
> you even backup the claim that &argument "produces" any array at all? As I
> showed using C99, the & just produces a value X (an address which can be
> travelled without boundary issues), so C99 shows that "&argument" does not
> "produce" an array, nor allocates storage for a 1-entry copy of "argument" at
> some unpredictable address Y (C99 clearly states that &a retuns "address of a",
> not "address of copy of a"). So I don't see how you could ever backup your
> claim with any standard, but I'm open to be surprised by your creativity! :-)
> 
> Based on C99 const char** PTR4=&format will set PTR4 to X. It's all good as
> long as PTR4 contains the value X. As C99 defines this, GCC doesn't have the
> option to copy the "format" to some random address Y and return it when I ask
> for "&format". It simply should not do this. I've backed this claim with C99
> text that states that & operator is the address of the item, not the address of
> a copy of the item invented by the compiler.
> 
> I also showed you in C99 that PTR4[0] accesses the 4 bytes of address X, and
> I've backed up my claim (based on C99) that PTR4[1] will access the 4 bytes at
> X+4 (i.e the 4 bytes of param 1), and that there is no "size of array
> limitation" specified in C99. Similarly, PTR4[2] will access the 4 bytes at
> X+8, (i.e the 4 bytes of param 2), and so on. I've clearly backed up this with
> C99.
> 
> So, all this is backed up. Can you refute the reasoning up to this point with
> any C99 reference? Or a reference to any other standard for that matter?

&X gives you an address of X which happens to be on the stack.  Following
parameters happen to be in adjacent stack slots.  Still C does not give
you a way to access adjacent parameters by doing pointer arithmetic on
&X.  &X does _not_ get you access to anything like a "stack" as there is
no such concept in the C language.  In

foo (int x, int y, int z)

there are only x, y and z.  There is no array of parameters, the only
"arrays" are that of implicit size 1 at locations &x, &y and &z which
allows you to compute &x + 1 (but not dereference that pointer).


-- 


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


  parent reply	other threads:[~2010-08-11 22:27 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-10 21:55 [Bug c++/45249] New: " rogerio at rilhas dot com
2010-08-10 22:03 ` [Bug c++/45249] " rogerio at rilhas dot com
2010-08-10 22:04 ` rogerio at rilhas dot com
2010-08-10 22:04 ` rogerio at rilhas dot com
2010-08-10 22:07 ` pinskia at gcc dot gnu dot org
2010-08-10 22:33 ` rogerio at rilhas dot com
2010-08-10 22:36 ` rogerio at rilhas dot com
2010-08-10 23:08 ` pinskia at gcc dot gnu dot org
2010-08-11  0:55 ` rogerio at rilhas dot com
2010-08-11  0:58 ` pinskia at gcc dot gnu dot org
2010-08-11  1:57 ` rogerio at rilhas dot com
2010-08-11  3:52 ` pinskia at gcc dot gnu dot org
2010-08-11 11:21 ` rogerio at rilhas dot com
2010-08-11 11:21 ` rogerio at rilhas dot com
2010-08-11 11:22 ` rogerio at rilhas dot com
2010-08-11 11:37 ` rguenth at gcc dot gnu dot org
2010-08-11 11:41 ` rguenth at gcc dot gnu dot org
2010-08-11 11:55 ` redi at gcc dot gnu dot org
2010-08-11 13:12 ` rogerio at rilhas dot com
2010-08-11 14:10 ` redi at gcc dot gnu dot org
2010-08-11 16:11 ` matz at gcc dot gnu dot org
2010-08-11 17:04 ` rogerio at rilhas dot com
2010-08-11 17:15 ` rogerio at rilhas dot com
2010-08-11 17:49 ` pinskia at gcc dot gnu dot org
2010-08-11 17:57 ` redi at gcc dot gnu dot org
2010-08-11 19:51 ` rogerio at rilhas dot com
2010-08-11 19:54 ` pinskia at gcc dot gnu dot org
2010-08-11 20:04 ` rogerio at rilhas dot com
2010-08-11 20:07 ` rogerio at rilhas dot com
2010-08-11 20:33 ` rguenth at gcc dot gnu dot org
2010-08-11 20:58 ` rogerio at rilhas dot com
2010-08-11 21:02 ` pinskia at gcc dot gnu dot org
2010-08-11 21:12 ` rogerio at rilhas dot com
2010-08-11 21:16 ` pinskia at gcc dot gnu dot org
2010-08-11 21:27 ` redi at gcc dot gnu dot org
2010-08-11 22:17 ` rogerio at rilhas dot com
2010-08-11 22:27 ` rguenth at gcc dot gnu dot org [this message]
2010-08-11 22:31 ` rguenth at gcc dot gnu dot org
2010-08-11 22:35 ` rogerio at rilhas dot com
2010-08-11 22:37 ` rogerio at rilhas dot com
2010-08-11 22:48 ` rguenth at gcc dot gnu dot org
2010-08-11 22:50 ` rogerio at rilhas dot com
2010-08-11 22:51 ` rogerio at rilhas dot com
2010-08-11 22:52 ` rogerio at rilhas dot com
2010-08-11 22:53 ` rogerio at rilhas dot com
2010-08-11 22:54 ` rogerio at rilhas dot com
2010-08-11 22:54 ` rogerio at rilhas dot com
2010-08-11 22:55 ` rogerio at rilhas dot com
2010-08-11 22:58 ` pinskia at gcc dot gnu dot org
2010-08-11 23:22 ` rogerio at rilhas dot com
2010-08-11 23:43 ` rogerio at rilhas dot com
2010-08-12  2:08 ` rogerio at rilhas dot com
2010-08-12  2:10 ` rogerio at rilhas dot com
2010-08-12  2:11 ` rogerio at rilhas dot com
2010-08-12  2:12 ` rogerio at rilhas dot com
2010-08-12  2:13 ` rogerio at rilhas dot com
2010-08-12  8:20 ` jakub at gcc dot gnu dot org
2010-08-12 10:17 ` rogerio at rilhas dot com
2010-08-12 10:18 ` paolo dot carlini at oracle dot com

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=20100811222727.27095.qmail@sourceware.org \
    --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).