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

--- Comment #4 from Allison Karlitskaya <allison.karlitskaya at redhat dot com> 
---
(In reply to Jakub Jelinek from comment #3)
> First of all, not all automatic vars live on stack, some live in registers.

Sure.  The register could also be initialised to the same value, of course.

> And, what will happen say for:
> switch (n)
> {
>   int x __attribute__((__default_value__((5)));
>   case 10:
>     foo (x);
>   case 20:
>     foo (x);
>     break;
> }

This is pretty much exactly the case that I'm talking about and the answer is
that foo() would *always* be called with 5.  The initialisation of 5 with this
attribute isn't done in the normal sense of an assignment that occurs when the
line in question is executed (note: there is no '=' anywhere in this program). 
The value of 5 is written into the local variable (register or stack space) as
soon as it is allocated, regardless of if execution passes through the line
where the declaration is.

Reply via email to