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

Use dyn_cast<gassign *> instead of is_gimple_assign.

Switches various GCC passes to use `dyn_cast<gassign *>` for safer and more expressive type checking of GIMPLE assignment statements.

This commit replaces the is_gimple_assign function with dyn_cast<gassign *> (and safe_dyn_cast<gassign *>) across numerous C++ files in GCC. This change improves the robustness and clarity of GIMPLE statement handling by using C++ dynamic casting, which is generally safer and more idiomatic than direct type checks. The affected passes include those dealing with comparisons, code generation, and various GIMPLE optimizations.

In Details

This commit updates numerous call sites within GCC's internal code to replace calls to is_gimple_assign(stmt) with dyn_cast<gassign *>(stmt) or safe_dyn_cast<gassign *>(stmt). This is a move towards safer, C++-idiomatic dynamic type checking for GIMPLE statements, specifically ensuring a statement is an assignment (gassign) before attempting to use assignment-specific methods. It impacts various optimization and lowering passes that inspect GIMPLE statements.

For Context
dyn_cast
A C++ RTTI (Run-Time Type Information) operator used for safely casting a pointer or reference from a base class to a derived class. If the cast fails, it returns a null pointer or throws an exception, preventing undefined behavior.
gassign*
A specific type of GIMPLE statement representing an assignment operation. Using dyn_cast<gassign *> ensures that the statement being examined is indeed an assignment.
is_gimple_assign
A function in GCC that checks if a given GIMPLE statement is an assignment. This commit replaces its usage with dyn_cast for improved type safety.
GIMPLE
GCC's internal representation after the GENERIC stage. It's a lower-level, three-address code form that simplifies many operations for subsequent optimization passes.
Filed Under: gccgimplerefactortype safety