GCC Newspaper
JUNE 15, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
cfghooks

cfghooks: Make cfg_hooks const to Prevent Runtime Modification

The cfg_hooks struct is now const to prevent accidental runtime modification, improving code safety.

This commit makes the cfg_hooks struct const, preventing unintended modifications at runtime. The change involves adjusting how sel-sched handles cfg_hooks by directly changing the pointer back to the original cfg_hooks instead of copying data back. This change improves code safety without significantly impacting functionality, primarily affecting the ia64 backend.

In Details

This commit constifies the cfg_hooks struct and functions that access it (get_cfg_hooks, set_cfg_hooks). The primary challenge is sel-sched-ir.cc, which copies the hooks. Instead of copying back, the code now reverts the pointer. cfg_hooks provides callbacks for CFG manipulation, used throughout the compiler. The hooks are defined in cfghooks.h and implemented in tree-cfg.cc and cfgrtl.cc. ia64 uses sel-sched by default.

For Context

In GCC, cfg_hooks provides a set of callback functions that allow different parts of the compiler to interact with and modify the control flow graph (CFG). The CFG represents the structure of the code, showing how execution flows through basic blocks. Making cfg_hooks const ensures that these callbacks cannot be accidentally changed during compilation, leading to more predictable and stable behavior. This change enhances the overall robustness of the compiler.

Filed Under: cfgconstrefactoria64