Fix for passing nested function address without trampoline
A bug preventing proper marking of parent functions for nested functions has been fixed, ensuring trampolines are generated when needed.
This commit corrects an issue in GCC where the address of a nested function was sometimes passed without generating a necessary trampoline. The bug occurred because the mark_decl_used function would incorrectly return early if a function was already marked, failing to propagate the marking to its parent functions. This prevented the generation of trampolines required for non-local context access. The fix ensures that parent functions are correctly marked, even if already processed, thus guaranteeing the generation of trampolines when a nested function requires a non-local context.
In Details
In c-typeck.cc, the mark_decl_used function had flawed logic for handling nested functions. When a function requiring a non-local context was already marked, it returned prematurely. This prevented the necessary propagation of marking to its parent functions, which is crucial for generating trampolines when the nested function's address is taken and its context differs from the caller's. The fix ensures that the marking logic correctly traverses up the parent chain, regardless of prior marking status, to establish the required non-local context.
- nested function
- A function defined inside another function. In C, nested functions are not standard but are supported as a language extension by GCC. They can access local variables of the enclosing function.
- trampoline
- A small piece of code that acts as an intermediary. In the context of nested functions, a trampoline is often used when the address of a nested function is taken. It helps manage the function's context, especially when calling it from a different scope than its definition.
- non-local context
- Refers to the execution environment or scope of a function that is not directly the immediate caller's scope. For nested functions, accessing non-local context means the function might need to be called or its address taken in a way that requires managing the state of its enclosing function.
- mark_decl_used
- A function within GCC's C type-checking logic responsible for marking declarations (like functions or variables) as used. This information is important for optimization and code generation.