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

Use dyn_cast for insn class checks

Replaces manual instruction type checks with C++ dynamic casting for improved safety and clarity.

This commit replaces manual instruction type checks with dyn_cast across numerous GCC source files. dyn_cast is a C++ feature that safely checks and converts pointers between class hierarchies. Using dyn_cast instead of predicates like CALL_P makes the code more robust by ensuring type safety and reducing the risk of runtime errors, while also simplifying the codebase.

In Details

This commit systematically replaces various *_P predicate macros (e.g., CALL_P, JUMP_P) and manual GET_CODE checks with dyn_cast calls when dealing with RTX objects representing instructions. This leverages C++'s dynamic dispatch for safer and more expressive type checking of RTX nodes, aligning with modern C++ practices within GCC's internal representation. It affects numerous passes and target backends that inspect instruction types.

For Context
RTX
Representation of intermediate values in GCC. It's a tree-like data structure used to represent expressions, instructions, and other program elements during compilation.
dyn_cast
A C++ RTTI (Run-Time Type Information) feature used for safe downcasting of pointers or references to a base class to a derived class. It returns null if the cast is not valid.
insn
An instruction, specifically an RTX representing a machine instruction.
CALL_P
A macro or predicate that checks if an RTX represents a call instruction.
Filed Under: refactorinternalsafety