The string literal "test" will be welded into the executable, and the OS will place it in read-only memory (that's why attempts to modify string literals often trigger a segmentation fault) while loading the file. The OS is also responsible for properly unloading the data.
So, that data is not placed on the stack, but char* str is. Since it's a regular local variable, it'll be deallocated automatically by the code inserted by the compiler.
To answer the question: at //flag the whole content of "test" will still be present at the same address initially allocated by the OS, and the stack won't be involved here at all. While processing the return statement, the compiler will insert code to clean up the stack.
char* str = "test";allocate the string in the read only memory. Only the pointerstris allocated on stack, and its value is updated from the call to the functionf(). No stack change happen.