public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rogerio at rilhas dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/45265] GCC has an intermittent bug when computing the address of function parameters
Date: Thu, 12 Aug 2010 17:50:00 -0000	[thread overview]
Message-ID: <20100812175015.6812.qmail@sourceware.org> (raw)
In-Reply-To: <bug-45265-19547@http.gcc.gnu.org/bugzilla/>

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 4182 bytes --]



------- Comment #24 from rogerio at rilhas dot com  2010-08-12 17:50 -------
(In reply to comment #20)

I couldn't resist to comming back (you respond very quickly, kudos!, I'm not
used to that! :-)

> Just for fun, I compiled this test case with various levels of optimization. 
> It works fine without optimization or with -O1, but segfaults at -O2 or -O3.

The script I sent you does not request optimizations and segfaults.

> That indicates that the program only works by coincidence, not by design -
> you've made assumptions about how GCC will interpret your sources, and those
> assumptions are wrong.  In this case, your assumption is that "bug_example_2"
> will always be a separate function, and will always be called as a separate
> function, and thus that you can assume some knowledge of the internals of the
> stack layout.

When I don«t request optimizations my interpretation is right. A function
declaration (that doesn't specifically request inline) is a function. I don't
know if C99 says it (probably does, in a C-sense function), but cdecl does.

> The C language does *not* require that a function which is called, be called as
> a separate function, only that the semantics of the call be the same as far as
> the C language requires.  The C language allows GCC to implement that function
> call in any way it chooses - and GCC chooses to implement it without actually
> doing a function call, but by copying the function body to the callee.  At
> least, it does when optimizing.  Without optimization, it *happens* to do what
> you expect.

Compile it like I did in the script (without optimizations) and see it fail.

>  It will also do what you expect if bug_example_2 and bug_example
> are in separate source files - *then* the "cdecl" standard you refer to
> applies, because cross-object calls are limited by the compatibility standards.
> However - if you use gcc to link as well, gcc has the option of optimizing
> those calls *also*.
> So, GCC is "cdecl" compliant because *if* there's a function call, *then* the
> *stack* is laid out the same.  However, the "cdecl" standard does *not* require
> that your program work, because C allows the optimizer to avoid the actual
> function call completely when the callee and caller are in the same scope.

Incorrect, code should not be optimized if I don't request it. If I do I have
to live without cdecl compliance, obviously, as I don't know of any compiler
that has an option like "optimize_as_possible_but_keep_cdecl_always". My point
is for non-optimized code, and that is why I included the scrip I used to build
it.

> Note: you can tell gcc to not inline a function with __attribute__((noinline))
> in which case a call to it is always an actual call to it, but it would be
> easier to just use the standard methods for accessing parameters so that it
> *always* works.

Agreed. But I'm determining the addresses of the parameters just to check GCC's
conformity, remember? So don't you worry about how easy the code is for me, I
will deal with that.

I just tried the attribute and didn't make any difference in the code, and is
still not cdecl. I'm sure it is not a bug in GCC though...

> Also, with full optimization enabled, your code crashes with MSVC also.

Right. As explained, this bug report is about non-optimized code. I also didn't
expect Microsoft's code to not crash if optimized (nor tried it until your
comment).

I don't think I ever mentioned optimizations in this bug report, I did it in
the "variable parameters" bug report bucause that was how I initially got it to
crash and had no way to report it to you (it crashed without optimizations in a
larger program that I could not send to you), but I later sent you a full
report (with snapshots and all in comment #51) a non-optimized version that
crashed. Here I could easilly show it to crash when not optimized, and so I
could live with disabling optimizations to get the addresses to be returned
properly.


> Please file a bug report with Microsoft.

No need. Their code *NEVER* crashes if I don't request optimizations.

This is it, I must resist! Bye!! :-)


-- 


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


  parent reply	other threads:[~2010-08-12 17:50 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-12 14:50 [Bug c++/45265] New: " rogerio at rilhas dot com
2010-08-12 14:52 ` [Bug c++/45265] " rogerio at rilhas dot com
2010-08-12 14:52 ` rogerio at rilhas dot com
2010-08-12 14:54 ` rogerio at rilhas dot com
2010-08-12 15:09 ` jakub at gcc dot gnu dot org
2010-08-12 15:25 ` schwab at linux-m68k dot org
2010-08-12 15:33 ` rogerio at rilhas dot com
2010-08-12 15:34 ` rogerio at rilhas dot com
2010-08-12 15:52 ` redi at gcc dot gnu dot org
2010-08-12 15:52 ` schwab at linux-m68k dot org
2010-08-12 16:00 ` matz at gcc dot gnu dot org
2010-08-12 16:05 ` rogerio at rilhas dot com
2010-08-12 16:09 ` redi at gcc dot gnu dot org
2010-08-12 16:10 ` pinskia at gcc dot gnu dot org
2010-08-12 16:11 ` jakub at gcc dot gnu dot org
2010-08-12 16:15 ` rogerio at rilhas dot com
2010-08-12 16:17 ` redi at gcc dot gnu dot org
2010-08-12 16:18 ` rogerio at rilhas dot com
2010-08-12 16:19 ` rogerio at rilhas dot com
2010-08-12 16:20 ` redi at gcc dot gnu dot org
2010-08-12 16:58 ` dj at redhat dot com
2010-08-12 17:09 ` froydnj at gcc dot gnu dot org
2010-08-12 17:25 ` rogerio at rilhas dot com
2010-08-12 17:25 ` rogerio at rilhas dot com
2010-08-12 17:50 ` rogerio at rilhas dot com [this message]
2010-08-12 17:54 ` redi at gcc dot gnu dot org
2010-08-12 18:04 ` rogerio at rilhas dot com
2010-08-12 18:05 ` matz at gcc dot gnu dot org
2010-08-12 18:08 ` dj at redhat dot com
2010-08-12 18:24 ` rogerio at rilhas dot com
2010-08-12 18:28 ` pinskia at gcc dot gnu dot org
2010-08-12 18:32 ` rogerio at rilhas dot com
2010-08-12 18:39 ` rogerio at rilhas dot com
2010-08-12 18:56 ` matz at gcc dot gnu dot org
2010-08-13 12:14 ` rogerio at rilhas dot com
2010-08-13 13:00 ` matz at gcc dot gnu dot org
2010-08-13 13:14 ` matz at gcc dot gnu dot org
2010-08-13 13:32 ` paolo dot carlini at oracle dot com
2010-08-13 14:47 ` rogerio at rilhas dot com
2010-08-13 14:48 ` rogerio at rilhas dot com
2010-08-13 14:53 ` rogerio at rilhas dot com
2010-08-13 15:18 ` matz at gcc dot gnu dot org
2010-08-13 15:26 ` matz at gcc dot gnu dot org
2010-08-13 16:28 ` rogerio at rilhas dot com
2010-08-13 16:30 ` rogerio at rilhas dot com
2010-08-13 16:33 ` redi at gcc dot gnu dot org
2010-08-13 16:42 ` rogerio at rilhas dot com
2010-08-13 18:00 ` ubizjak at gmail dot com
2010-08-13 21:16 ` rogerio at rilhas dot com
2010-08-13 22:38 ` redi at gcc dot gnu dot org
2010-08-13 22:40 ` redi at gcc dot gnu dot org
2010-08-14  1:26 ` matz at gcc dot gnu dot org
2010-08-14 13:18 ` rogerio at rilhas dot com
2010-08-14 13:55 ` redi at gcc dot gnu dot org
2010-08-14 14:25 ` redi at gcc dot gnu dot org
2010-08-14 14:32 ` rogerio at rilhas dot com
2010-08-14 14:34 ` rogerio at rilhas dot com
2010-08-14 15:09 ` redi at gcc dot gnu dot org
2010-08-14 16:02 ` rogerio at rilhas dot com
2010-08-14 17:11 ` redi at gcc dot gnu dot 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=20100812175015.6812.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).