https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91952

--- Comment #5 from Allison Karlitskaya <allison.karlitskaya at redhat dot com> 
---
One could imagine (as a first step) that __default_value__() would be
implemented by way of a simple code transformation whenever it is encountered. 
An additional block could be added and the variable declaration and its initial
value would be lifted out of its current location to the start of the new
block.

Given the example:

(In reply to Jakub Jelinek from comment #3)
> switch (n)
> {
>   int x __attribute__((__default_value__((5)));
>   case 10:
>     foo (x);
>   case 20:
>     foo (x);
>     break;
> }

the transformed code would look something like:

{
  int x = 5;

  switch (n)
  {
    case 10:
      foo (x);
    case 20:
      foo (x);
      break;
  }
}


I'm no compiler author, of course, and this might be a ridiculous way to
approach the implementation (and probably also has some edge cases where it
doesn't work properly), but it's another way to describe what I'm talking about
and argue in favour of its feasibility (regardless of concerns such as whether
the variable in question lands on the stack or in a register, etc.)

Reply via email to