public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "joseph at codesourcery dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/17913] [4.0/4.1 Regression] ICE jumping into statement expression
Date: Thu, 24 Mar 2005 20:35:00 -0000	[thread overview]
Message-ID: <20050324203503.311.qmail@sourceware.org> (raw)
In-Reply-To: <20041009192304.17913.jsm28@gcc.gnu.org>


------- Additional Comments From joseph at codesourcery dot com  2005-03-24 20:34 -------
Subject: Re:  [4.0/4.1 Regression] ICE jumping into statement
 expression

On Thu, 24 Mar 2005, mmitchel at gcc dot gnu dot org wrote:

> Joseph, do you think it is tractable and reasonable to diagnose jumps into
> statement expressions for 4.0?  If you and RTH agree that this should be
> invalid, then that would be ideal.  If you agree that this should be invalid,
> but don't think it's possible to fix, would you please adjust the Keywords entry
> here, so that this is not marked as a wrong-code/ice-on-valid-code regression,
> but rather accepts-invalid?

I think it is tractable and reasonable to diagnose jumps into statement 
expressions (at least for C, not having looked at the implementation for 
C++) for 4.0.  I also don't see anything *wrong* with the C front end 
changes in the patch posted for this bug, given that the rest of the patch 
could still be of use if there are front ends which want to continue to 
allow jumps into conditional expressions which might otherwise get folded.  
(And in abstract there's nothing wrong with a front end trying to fold a 
COND_EXPR arising from if (0) { ... } else { ... }, which certainly can be 
jumped into; just that in practice trying to fold such a tree is unlikely 
to be useful.)

Having spent an hour working out how to diagnose jumps into statement 
expressions I've arrived at the following approach which I'd try; I expect 
something similar would work for C++ as well:

* Add three flags to labels: one for "this label was in a statement 
expression which has finished, so you can't jump to it any more", one for 
"this label has a goto jumping to it from the current level of statement 
expression nesting" and one for "this label has a goto jumping to it from 
outside the current level of statement expression nesting".

* Keep a list at each level of statement expression nesting (including 
inside a function but outside all statement expressions) of all labels 
defined at that level, and a list of all labels with gotos to them at that 
level.

* When a goto is encountered, it mustn't be to a label with the first 
flag.  Otherwise, if it doesn't have the second or third flag, give it the 
second flag and put it on the current list of gotos.

* When a label is defined, it mustn't have the third flag.  Otherwise, put 
it on the list of labels defined at that level.

* When starting a statement expression, start new lists as above.  Given 
all labels on the immediately previous list of gotos the third flag (so 
they can't be defined until that statement expression ends).

* When ending a statement expression, give all labels defined in that 
expression the first flag.  Remove the third flag from all gotos in the 
level to which we are returning, leaving the second flag on them.  Move 
the gotos in the list of the level we are leaving to the list of the level 
which we are returning (and leave the second flag on them).

* Keep a flag for whether the current switch statement started outside 
the current statement expression.  When starting a statement expression, 
save the flag's value and set it to true; restore it when ending a 
statement expression.  When starting a switch statement, save the flag's 
value and set it to false; restore it when ending a switch statement.  Do 
not allow case or default labels when the flag is true.

* Generate a testcase involving all cases of a function with two statement 
expressions inside, each of those containing two statement expressions and 
the label and goto in all possible places, i.e.

void
f (void)
{
 ^({ ^({^0;}); ^({^0;}); ^0;});
 ^({ ^({^0;}); ^({^0;}); ^0;});
 ^0;^
}

with the goto at any place marked ^ and the label on the goto or at any of 
those places other than right at the end of the function, i.e. 196 such 
functions, making sure that the correct subset are rejected.  (This is 
operating on the basis that we will continue to allow jumps *out* of 
statement expressions, as people have real uses for such, with it simply 
being unspecified which collateral expressions of the statement expression 
(subexpressions of the larger expression containing the statement 
expression not separated from it by a sequence point, e.g. foo() in foo() 
+ ({ goto a; 0; })) have been evaluated.)

(The second flag on labels is only used to avoid listing labels more than 
once at the same level of nesting; it isn't strictly required, and 
actually implementing it would mean multipurposing another one of the 
DECL_LANG_FLAG fields: C is using 0-5 with 4 already multipurposed.)



-- 


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


  parent reply	other threads:[~2005-03-24 20:35 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-09 19:23 [Bug c/17913] New: " jsm28 at gcc dot gnu dot org
2004-10-09 20:18 ` [Bug c/17913] [4.0 Regression] " pinskia at gcc dot gnu dot org
2004-10-14  3:47 ` pinskia at gcc dot gnu dot org
2004-10-15 14:12 ` pinskia at gcc dot gnu dot org
2004-10-15 14:21 ` pinskia at gcc dot gnu dot org
2004-10-27 12:25 ` steven at gcc dot gnu dot org
2004-10-27 12:42 ` steven at gcc dot gnu dot org
2004-10-27 12:55 ` jsm at polyomino dot org dot uk
2004-10-28  6:42 ` loki at inf dot u-szeged dot hu
2004-10-28 13:30 ` bonzini at gcc dot gnu dot org
2004-10-28 15:05 ` jsm at polyomino dot org dot uk
2004-11-03  8:17 ` loki at inf dot u-szeged dot hu
2005-01-20  4:15 ` pinskia at gcc dot gnu dot org
2005-03-24 18:22 ` [Bug c/17913] [4.0/4.1 " mmitchel at gcc dot gnu dot org
2005-03-24 20:35 ` joseph at codesourcery dot com [this message]
2005-03-30 18:08 ` jsm28 at gcc dot gnu dot org
2005-03-30 19:56 ` cvs-commit at gcc dot gnu dot org
2005-03-30 19:59 ` cvs-commit at gcc dot gnu dot org
2005-04-17  3:51 ` mmitchel at gcc dot gnu dot org
2005-05-10 13:47 ` cvs-commit at gcc dot gnu dot org
2005-05-10 13:50 ` loki at gcc dot gnu dot org
2005-07-06 16:48 ` [Bug c/17913] [4.0 " mmitchel at gcc dot gnu dot org
2005-09-09 10:41 ` [Bug c++/17913] " rguenth at gcc dot gnu dot org
2005-09-27 16:15 ` mmitchel 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=20050324203503.311.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).