RTL list head access corrected to prevent aliasing issues.
RTL list manipulation functions no longer cast list heads to generic RTX, preventing aliasing bugs.
Several functions in lists.cc that manage instruction and expression lists were incorrectly casting list head pointers (e.g., rtx_insn_list **) to generic rtx *. This led to potential aliasing bugs, where loads of list heads could return stale data due to compiler reordering, as detected by type sanitizers. The fix introduces a template function free_list and adjusts other functions to operate directly on the correct pointer types, ensuring accurate list manipulation.
In Details
Functions like free_INSN_LIST_list, remove_free_INSN_LIST_elem, etc., in lists.cc were casting rtx_insn_list ** or rtx_expr_list ** to rtx * to access and modify the list head. This is problematic because rtx, rtx_insn_list *, and rtx_expr_list * have distinct alias sets. Loads of the list head could then be reordered incorrectly by the compiler, potentially yielding stale data, especially after inlining or through IPA summaries. The fix uses a template free_list and ensures that list heads are manipulated using their specific types (rtx_insn_list * or rtx_expr_list *)…
- RTL
- Register Transfer Language. An intermediate representation used by GCC after GIMPLE, which describes operations in terms of registers and memory references.
- rtx
- A data structure in GCC representing a machine-dependent construct, such as an operation, a register, or a memory address.
- rtx_insn_list
- A data structure representing a node in a linked list of RTL instructions.
- rtx_expr_list
- A data structure representing a node in a linked list of RTL expressions.
- alias sets
- A mechanism used by compilers to track which memory locations might refer to the same address. This is crucial for optimizations like reordering memory accesses.
- type sanitizer
- A debugging tool, like GCC's
-fsanitize=type, that detects type confusion errors and memory access violations related to type safety.