https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120241
--- Comment #1 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Cupertino Miranda <[email protected]>: https://gcc.gnu.org/g:fb7bfbaa9192a8055683447810f08b9fa352e402 commit r16-7698-gfb7bfbaa9192a8055683447810f08b9fa352e402 Author: Cupertino Miranda <[email protected]> Date: Tue Oct 21 13:33:58 2025 +0100 bpf: Split expressions for proper CO-RE code generation This patch corrects CO-RE generation for the cases where an expression starts with a non-CO-RE access, but in the middle it requires to generate CO-RE to correctly compute the access location. It fixes it by splitting the expression into their CO-RE and non-CO-RE counterparts. It performs this by walking gimple expressions, and for each field access to which its type is a struct or union, it verifies if both the types for the base and field are attributed similarly. Otherwise, it splits the expression at this location by creating a temporary variable and performing any required pointer conversions. This smaller expressions are converted to CO-RE in the subsequent gimple walker. There is no way in GCC to distinguish nested struct/union definitions from non-nested ones. This patch simplifies code and enforces that all preserve_access_index structs/unions would be attributed explicitly. Previous approach was error prone as it would extend CO-RE accesses to structures which would not be attributed. All GCC BPF dejagnu passes tests: # of expected passes 553 # of expected failures 6 kernel-next bpf selftests: before: Summary: 543/4888 PASSED, 113 SKIPPED, 136 FAILED after: Summary: 545/4893 PASSED, 113 SKIPPED, 134 FAILED gcc/ChangeLog: PR target/120241 * config/bpf/core-builtins.cc (is_attr_preserve_access): Correct for pointer types. (maybe_get_base_for_field_expr, core_access_index_map, core_access_clean, core_is_access_index, core_mark_as_access_index): Remove. (make_gimple_core_safe_access_index): Remove function. (struct walker_data): New struct to pass data to tree walker. (callback_should_do_core_access, should_do_core_access): Add function to identify expressions that should not be converted to CO-RE. (core_make_builtins): Add callback tree walker function to convert expressions to CO-RE. (callback_find_next_split_location, core_should_split_expr, find_next_split_location, gimple_core_early_split_expr): Add function to split expressions in CO-RE and non-CO-RE expressions. (execute_lower_bpf_core): Adapt to new code. * config/bpf/bpf.opt: Add option Wco-re. * doc/invoke.texi: Add documentation for Wco-re. gcc/testsuite/ChangeLog: PR target/120241 * gcc.target/bpf/core-attr-3.c: Add attribute. * gcc.target/bpf/core-attr-4.c: Add attribute. * gcc.target/bpf/core-attr-5.c: Add attribute. * gcc.target/bpf/core-attr-6.c: Add attribute. * gcc.target/bpf/core-attr-7.c: New test. * gcc.target/bpf/core-attr-calls.c: Adapt.
