This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [tree-ssa] Switch stmts and inserting on edges


amacleod wrote:

> [...]
> I have an edge from the switch stmt to the default case that I need to
> insert a copy on.
> [...]
> case blah:
>   <...>
>   goto new_label;
> 
> default:
>   <inserted_stmt>
> new_label:
>   default code.
> [...]

That's not bad - it's only needed if the previous case falls through.


> Any other suggestions? I havent thought of anything I actually like....

How about forking the switch() into two, with the first one containing
the inserted statement?

switch (expr)
{
  case <1...N>: break;
  default: <inserted_stmt>
}
switch (expr)
{
  <unmodified>  
}

... or using a temporary variable as a flag?

switch (expr)
{
  int default_fallthrough = 0;

  case <1..M>: break;
  case <N>: stmt; stmt;  /* fallthrough */
       default_fallthrough = 1;
  default:
     if (! default_fallthrough) { <inserted_stmt> }
     <old default code>
} 


- FChE


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]