GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
gcc/alias

Handle named globals in errno alias analysis

Fixes alias analysis to correctly identify when pointer aliases might access errno.

The alias analysis in GCC previously failed to recognize when a pointer might alias the errno variable if the pointer’s points-to set only contained named global variables (like errno itself). This led to incorrect optimizations where reads of errno across function calls were dropped, causing programs to see an unchanged errno value. This change updates the analysis to consider pointers aliasing named, interposable global variables as potential errno accesses.

In Details

The default_ref_may_alias_errno hook in targhooks.cc determines if a memory access via a pointer could be an access to errno. It previously required the pointer's points-to set to contain 'anything' or 'nonlocal'. This commit extends the check to include sets containing 'interposable' variables, addressing cases where C libraries (e.g., avr-libc) declare errno as a global, and PTA determines it's interposable. This prevents FRE from incorrectly merging loads of errno.

For Context
alias analysis
A compiler analysis that determines which memory locations might be accessed through different pointers, helping to resolve ambiguities and enable optimizations.
errno
A standard C thread-local variable that holds the error code of the last failed system call or library function.
Points-to analysis (PTA)
A static analysis technique that determines, for each pointer in a program, the set of memory locations that the pointer might point to.
FRE (Function Returns Elimination)
A compiler optimization pass that aims to eliminate unnecessary function calls or simplify return paths.
interposable
A variable or function that can be replaced at runtime by a different version, typically used for dynamic linking or interception.
Filed Under: gccalias analysisoptimizationC library