https://gcc.gnu.org/bugzilla/show_bug.cgi?id=38534
--- Comment #43 from Lukas Grätz <lukas.gra...@tu-darmstadt.de> --- (In reply to Lukas Grätz from comment #42) > (In reply to Jakub Jelinek from comment #41) > > > > No. When PR78685 would be fixed by adding artificial hidden uses of > > variables at the end of their scopes, this bug would trigger far more often. > > The vars would be live across the calls, so if there would be callee-saved > > registers available, the compiler > > would use them to hold the variables across the calls. And this bug would > > break that. > > It could be done that way. But I think a better fix for PR78685 would be to > save the function parameter values to the stack (and than this problem will > not trigger that often). For the following reasons: > Just to be complete with the arguments: (5) Artificial hidden uses of variables at the end of their scopes would not always help when variables are overwritten. For example: int main (int argc, char **argv) { if (argc == 42) { h(); } might_not_return(0); argc = bar(); // here would be the hidden use of argc and argv } The "artificial hidden use" approach would only save the last value of argc, here the result of bar() in line 4 and not the argument argc. The argument value of argc is not used from line 3 on. So that approach would still produce a backtrace with argc=<optimized out>, something like: #1 might_not_return(i=0) #2 main (argc=<optimized out>, argv=0x7fffffffe0) (6) When the goal is just to have a more helpful gdb bt output, then we don't need to save any variables other than function parameters. In the original example in Bug 78685 and Comment 28 here, this seemed to be the main goal, to get gdb bt more conclusive. If interested in other variable values, too, -O0 might be better then trying hard to patch -Og to save all variable values. (7) Bug 78685 is for x86-64 with -Og. For 32 bit x86 with -Og, we don't run into that problem: there are no <optimized out> function parameters, since they are already on the stack by the 32 bit calling conventions. So saving parameters on the stack for -Og on x86-64 and similar targets without stack-parameters would just be consequent.