AST modification after parsing silently discarded by GCC
26.8K reputation · 16 Feb 2024, 15:15 UTC
Problem Statement
A GCC plugin registers a PLUGIN_ADD_DECL callback to inject a new function declaration after the language front‑end has finished parsing a source file. The documentation does not formally allow adding new AST nodes at this stage, and in practice GCC appears to drop the injected declaration without error.
Unresolved Behavior
While the plugin interface lists callbacks such as PLUGIN_ADD_DECL, the spec lacks a clear rule for post‑parsing AST modifications. Existing reports indicate that such additions are silently discarded, leading to missing symbols in the final binary. The mailing list and bug tracker describe this as an unfinished feature, suggesting that current behavior may change in future releases.
Specific Questions
- Under what circumstances does GCC discard declarations added via PLUGIN_ADD_DECL after the front‑end has completed parsing?
- Is there a stable, documented API that allows deterministic AST modification after parsing, or must plugins rely on the current temporary workaround?
- Will future GCC releases alter the handling of post‑parsing AST changes, and if so, what migration path is recommended?