public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug regression/24556]  New: gcc can't inline functions using setjmp
@ 2005-10-27  8:53 samuel dot thibault at ens-lyon dot org
  2005-10-27 13:37 ` [Bug regression/24556] " pinskia at gcc dot gnu dot org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: samuel dot thibault at ens-lyon dot org @ 2005-10-27  8:53 UTC (permalink / raw)
  To: gcc-bugs

Hi,

We have a thread library which can't be optimized as much as before, because
-starting from gcc 3.4- functions calling setjmp can not be inlined. Our
problem is with our switchto function:

void switchto(task_t *cur, task_t *next) {
        if (cur!=next) {
                if (setjmp(cur->buf) == 1)
                        return;
                longjmp(next->buf, 1);
        }
}

We would really prefer _not_ to have to define this as a macro for getting it
correctly inlined in every function that calls it.

Is there a really strong reason for not inlining such function ?

Regards,
Samuel


-- 
           Summary: gcc can't inline functions using setjmp
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: regression
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: samuel dot thibault at ens-lyon dot org


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


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug regression/24556] gcc can't inline functions using setjmp
  2005-10-27  8:53 [Bug regression/24556] New: gcc can't inline functions using setjmp samuel dot thibault at ens-lyon dot org
@ 2005-10-27 13:37 ` pinskia at gcc dot gnu dot org
  2005-10-27 13:45 ` samuel dot thibault at ens-lyon dot org
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-10-27 13:37 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2005-10-27 13:37 -------
This is not a bug as if you inline it, the place setjmp goes to could be not
where you want to goto.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug regression/24556] gcc can't inline functions using setjmp
  2005-10-27  8:53 [Bug regression/24556] New: gcc can't inline functions using setjmp samuel dot thibault at ens-lyon dot org
  2005-10-27 13:37 ` [Bug regression/24556] " pinskia at gcc dot gnu dot org
@ 2005-10-27 13:45 ` samuel dot thibault at ens-lyon dot org
  2005-10-27 14:11 ` rguenth at gcc dot gnu dot org
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: samuel dot thibault at ens-lyon dot org @ 2005-10-27 13:45 UTC (permalink / raw)
  To: gcc-bugs

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



------- Comment #2 from samuel dot thibault at ens-lyon dot org  2005-10-27 13:45 -------
Subject: Re:  gcc can't inline functions using setjmp


pinskia at gcc dot gnu dot org, le Thu 27 Oct 2005 13:37:32 -0000, a écrit :
> This is not a bug as if you inline it, the place setjmp goes to could be not
> where you want to goto.

I don't understand that. I did google before submitting the bug and couldn't
find anything that would prevent our code from working. Something I could find
is

jmp_buf buf;
inline f() {
        if (setjmp(buf));
}

g() {
        f();
        longjmp(buf);
}

Of course _this_ is wrong, since f() is terminated when longjmp occurs.

But in our code, switch_to() is _never_ terminated when longjmp goes to it, so
I don't see any issue.


-- 


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


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug regression/24556] gcc can't inline functions using setjmp
  2005-10-27  8:53 [Bug regression/24556] New: gcc can't inline functions using setjmp samuel dot thibault at ens-lyon dot org
  2005-10-27 13:37 ` [Bug regression/24556] " pinskia at gcc dot gnu dot org
  2005-10-27 13:45 ` samuel dot thibault at ens-lyon dot org
@ 2005-10-27 14:11 ` rguenth at gcc dot gnu dot org
  2005-10-28  0:21 ` samuel dot thibault at ens-lyon dot org
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2005-10-27 14:11 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from rguenth at gcc dot gnu dot org  2005-10-27 14:11 -------
I believe it should be safe to inline, as inlining can only make a previously
invalid use of sjlj valid, but not the other way around.


-- 


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


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug regression/24556] gcc can't inline functions using setjmp
  2005-10-27  8:53 [Bug regression/24556] New: gcc can't inline functions using setjmp samuel dot thibault at ens-lyon dot org
                   ` (2 preceding siblings ...)
  2005-10-27 14:11 ` rguenth at gcc dot gnu dot org
@ 2005-10-28  0:21 ` samuel dot thibault at ens-lyon dot org
  2005-10-28  0:37 ` pinskia at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: samuel dot thibault at ens-lyon dot org @ 2005-10-28  0:21 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from samuel dot thibault at ens-lyon dot org  2005-10-28 00:21 -------
Well, there is indeed an issue: the address of some local variables might be
passed to other functions and then be modified in an external way between
setjmp() and longjmp(), and if some local variables are still in registers when
setjmp is executed, longjmp will restore the value they had _before_ setjmp.
This is expected when using sjlj. Now, inlining a function makes the caller be
hit by this issue too, which is no good.

But gcc might check that at the time setjmp() is called no caller automatic
variables are in registers, or it might even automatically consider them as
volatile in the callee (just like it does for extern variables, I guess, since
these _must_ have the value as of the time longjmp() was called).

So yes, inlining functions that use sjlj makes sense and can be implemented,
this is a opened bug, not a feature (btw, the error message is "sorry,
unimplemented: function 'switchto' can never be inlined because it uses
setjmp", not "go read longjmp() documentation").


-- 

samuel dot thibault at ens-lyon dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |


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


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug regression/24556] gcc can't inline functions using setjmp
  2005-10-27  8:53 [Bug regression/24556] New: gcc can't inline functions using setjmp samuel dot thibault at ens-lyon dot org
                   ` (3 preceding siblings ...)
  2005-10-28  0:21 ` samuel dot thibault at ens-lyon dot org
@ 2005-10-28  0:37 ` pinskia at gcc dot gnu dot org
  2005-10-28  0:47 ` samuel dot thibault at ens-lyon dot org
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-10-28  0:37 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from pinskia at gcc dot gnu dot org  2005-10-28 00:37 -------
(In reply to comment #4)
That is not really GCC's fault.
Let me look into why setjmp was caused not to inline, there was a reason.


-- 


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


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug regression/24556] gcc can't inline functions using setjmp
  2005-10-27  8:53 [Bug regression/24556] New: gcc can't inline functions using setjmp samuel dot thibault at ens-lyon dot org
                   ` (4 preceding siblings ...)
  2005-10-28  0:37 ` pinskia at gcc dot gnu dot org
@ 2005-10-28  0:47 ` samuel dot thibault at ens-lyon dot org
  2005-10-28  1:40 ` [Bug middle-end/24556] " pinskia at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: samuel dot thibault at ens-lyon dot org @ 2005-10-28  0:47 UTC (permalink / raw)
  To: gcc-bugs

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



------- Comment #6 from samuel dot thibault at ens-lyon dot org  2005-10-28 00:47 -------
Subject: Re:  gcc can't inline functions using setjmp

pinskia at gcc dot gnu dot org, le Fri 28 Oct 2005 00:37:47 -0000, a écrit :
> Let me look into why setjmp was caused not to inline, there was a reason.

It seems that historically, the "How inlined are inlined functions?"
thread starting at 03 Dec 1999
http://gcc.gnu.org/ml/gcc/1999-12n/msg00056.html
triggered the patch
http://gcc.gnu.org/ml/gcc-patches/1999-12n/msg00142.html
but that's the issue I just explained


-- 


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


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug middle-end/24556] gcc can't inline functions using setjmp
  2005-10-27  8:53 [Bug regression/24556] New: gcc can't inline functions using setjmp samuel dot thibault at ens-lyon dot org
                   ` (5 preceding siblings ...)
  2005-10-28  0:47 ` samuel dot thibault at ens-lyon dot org
@ 2005-10-28  1:40 ` pinskia at gcc dot gnu dot org
  2005-10-28  8:27 ` samuel dot thibault at ens-lyon dot org
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-10-28  1:40 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from pinskia at gcc dot gnu dot org  2005-10-28 01:39 -------
So this is not a bug.  Closing as won't fix.  You found the issue and the docs
for setjmp are really clear.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
          Component|regression                  |middle-end
         Resolution|                            |WONTFIX


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


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug middle-end/24556] gcc can't inline functions using setjmp
  2005-10-27  8:53 [Bug regression/24556] New: gcc can't inline functions using setjmp samuel dot thibault at ens-lyon dot org
                   ` (6 preceding siblings ...)
  2005-10-28  1:40 ` [Bug middle-end/24556] " pinskia at gcc dot gnu dot org
@ 2005-10-28  8:27 ` samuel dot thibault at ens-lyon dot org
  2005-10-28 14:18 ` pinskia at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: samuel dot thibault at ens-lyon dot org @ 2005-10-28  8:27 UTC (permalink / raw)
  To: gcc-bugs

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



------- Comment #8 from samuel dot thibault at ens-lyon dot org  2005-10-28 08:27 -------
Subject: Re:  gcc can't inline functions using setjmp

pinskia at gcc dot gnu dot org, le Fri 28 Oct 2005 01:39:59 -0000, a écrit :
> So this is not a bug.

Yes this is a bug. The docs for setjmp are really clear about the fact
automatic variables of the callee might be thrashed, but that doesn't
entail that the callee can't be inlined. Gcc doesn't implement anything
for getting semantic right, but it is feasible, I explained how. So it
is a bug.

But you don't want to fix it. Too bad for us.
I thought that "An Inline Function is As Fast As a Macro". It is not.
<grin>


-- 


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


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug middle-end/24556] gcc can't inline functions using setjmp
  2005-10-27  8:53 [Bug regression/24556] New: gcc can't inline functions using setjmp samuel dot thibault at ens-lyon dot org
                   ` (7 preceding siblings ...)
  2005-10-28  8:27 ` samuel dot thibault at ens-lyon dot org
@ 2005-10-28 14:18 ` pinskia at gcc dot gnu dot org
  2005-10-28 16:22 ` rguenth at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-10-28 14:18 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from pinskia at gcc dot gnu dot org  2005-10-28 14:18 -------
(In reply to comment #8)
> Yes this is a bug. The docs for setjmp are really clear about the fact
> automatic variables of the callee might be thrashed, but that doesn't
> entail that the callee can't be inlined. Gcc doesn't implement anything
> for getting semantic right, but it is feasible, I explained how. So it
> is a bug.

Actually there is no easy way to implement that as the information about what
function is inlined where is lost very early on.


-- 


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


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug middle-end/24556] gcc can't inline functions using setjmp
  2005-10-27  8:53 [Bug regression/24556] New: gcc can't inline functions using setjmp samuel dot thibault at ens-lyon dot org
                   ` (8 preceding siblings ...)
  2005-10-28 14:18 ` pinskia at gcc dot gnu dot org
@ 2005-10-28 16:22 ` rguenth at gcc dot gnu dot org
  2005-10-28 16:23 ` rguenth at gcc dot gnu dot org
  2006-04-05 13:48 ` rguenth at gcc dot gnu dot org
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2005-10-28 16:22 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from rguenth at gcc dot gnu dot org  2005-10-28 16:22 -------
I'll re-open this issue as we might indeed follow users advice if he declared
the function inline.  We only should avoid inlining functions calling setjmp
that are not declared inline.  I'll be putting this on my list of things to
look at.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|WONTFIX                     |


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


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug middle-end/24556] gcc can't inline functions using setjmp
  2005-10-27  8:53 [Bug regression/24556] New: gcc can't inline functions using setjmp samuel dot thibault at ens-lyon dot org
                   ` (9 preceding siblings ...)
  2005-10-28 16:22 ` rguenth at gcc dot gnu dot org
@ 2005-10-28 16:23 ` rguenth at gcc dot gnu dot org
  2006-04-05 13:48 ` rguenth at gcc dot gnu dot org
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2005-10-28 16:23 UTC (permalink / raw)
  To: gcc-bugs



-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |rguenth at gcc dot gnu dot
                   |dot org                     |org
           Severity|normal                      |enhancement
             Status|UNCONFIRMED                 |ASSIGNED
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2005-10-28 16:23:23
               date|                            |


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


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug middle-end/24556] gcc can't inline functions using setjmp
  2005-10-27  8:53 [Bug regression/24556] New: gcc can't inline functions using setjmp samuel dot thibault at ens-lyon dot org
                   ` (10 preceding siblings ...)
  2005-10-28 16:23 ` rguenth at gcc dot gnu dot org
@ 2006-04-05 13:48 ` rguenth at gcc dot gnu dot org
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2006-04-05 13:48 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #11 from rguenth at gcc dot gnu dot org  2006-04-05 13:48 -------
I'm not working on this.  Re-closing as WONTFIX.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |WONTFIX


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


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2006-04-05 13:48 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-10-27  8:53 [Bug regression/24556] New: gcc can't inline functions using setjmp samuel dot thibault at ens-lyon dot org
2005-10-27 13:37 ` [Bug regression/24556] " pinskia at gcc dot gnu dot org
2005-10-27 13:45 ` samuel dot thibault at ens-lyon dot org
2005-10-27 14:11 ` rguenth at gcc dot gnu dot org
2005-10-28  0:21 ` samuel dot thibault at ens-lyon dot org
2005-10-28  0:37 ` pinskia at gcc dot gnu dot org
2005-10-28  0:47 ` samuel dot thibault at ens-lyon dot org
2005-10-28  1:40 ` [Bug middle-end/24556] " pinskia at gcc dot gnu dot org
2005-10-28  8:27 ` samuel dot thibault at ens-lyon dot org
2005-10-28 14:18 ` pinskia at gcc dot gnu dot org
2005-10-28 16:22 ` rguenth at gcc dot gnu dot org
2005-10-28 16:23 ` rguenth at gcc dot gnu dot org
2006-04-05 13:48 ` rguenth at gcc dot gnu dot org

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).