Fixes name handling in coroutine lowering for C++26.
Fixes a miscompilation in C++26 coroutines by ensuring unique names for compiler-generated variables, avoiding conflicts when multiple unnamed variables exist…
In C++26, multiple unnamed variables (’_’) can exist in the same scope within a coroutine. The compiler was incorrectly using the same field declaration multiple times for these variables, leading to miscompilation. This commit fixes the issue by ensuring that compiler-generated variables have unique names, even when the source code doesn’t provide them explicitly. Specifically, it makes the compiler pretend such variables don’t have a name, so it uses a serial number then instead.
In Details
Coroutine lowering in GCC involves transforming high-level coroutine constructs into lower-level code. The register_local_var_uses function is responsible for handling local variable uses within coroutines. For variables lacking a user-provided name (DECL_NAME is NULL), the fix assigns a serial number to make the FIELD_DECL unique. This resolves the issue of using the same FIELD_DECL multiple times for distinct unnamed variables within the same scope.
For Context
Coroutines are functions that can suspend execution and resume later, allowing for more efficient asynchronous programming. Lowering is a compiler phase that transforms high-level code into a lower-level representation that can be executed by the machine. Before this patch, the compiler would generate temporary variables that are used internally by the compiled code. For C++26, the compiler could generate multiple unnamed variables in the same scope which was leading to a miscompilation. This patch fixes this issue by ensuring that all compiler-generated variables have names that are unique.