Skip to contentSkip to conversation

Fix sanitizer attribute infrastructure to use standard TREE_LIST format [PR113264]

PATCH hanwei (K) 1 participant 1 message Feb 25

lore
Share & tools
lore

hanwei (K)

author
#0 lore raw
Quoted 48 lines · On Wed, Feb 25, 2026 at 12:28 AM hstk30 <[email protected]> wrote:
Quoted 25 lines · Andrew Pinski
Quoted 11 lines · Kees Cook

The __attribute__((__copy__)) functionality was crashing when
copying sanitizer-related attributes because these attributes
violated the standard GCC attribute infrastructure by storing
INTEGER_CST values directly instead of wrapping them in TREE_LIST like all other attributes.

Wrap sanitizer attributes INTEGER_CST values in TREE_LIST structures to follow the same pattern as other attributes. This eliminates the copy_list() crashes when copying sanitizer attributes:

test.c:4:1: internal compiler error: tree check: expected tree that contains ‘common’ structure, have ‘integer_cst’ in copy_list, at tree.cc:1427

Quoted 10 lines
    4 | __attribute__((__copy__(__tanh)));
      | ^~~~~~~~~~~~~
0x859d06 tree_contains_struct_check_failed(tree_node const*, tree_node_structure_enum, char const*, int, char const*)
        ../../gcc/gcc/tree.cc:9126
0x860f78 contains_struct_check(tree_node*, tree_node_structure_enum, char const*, int, char const*)
        ../../gcc/gcc/tree.h:3748
0x860f78 copy_list(tree_node*)
        ../../gcc/gcc/tree.cc:1427
0xa755a5 handle_copy_attribute
        ../../gcc/gcc/c-family/c-attribs.cc:3077
Quoted 5 lines

I am not a fan of the wrapping because it increases the memory usage slightly but it is required since the rest of the attributes code requires TREE_LIST here.

So Ok. I will do final testing either Monday or Tuesday and push it after that.

So this causes some ICEs in the testsuite:
FAIL: c-c++-common/asan/inline-kernel.c -O0 (internal compiler
error: in tree_to_sanitize_code_type, at tree.cc:6704)

0xa4376b fancy_abort(char const*, int, char const*)
/home/apinski/src/upstream-gcc-new/gcc/gcc/diagnostics/context.cc:1812
0x92f581 tree_to_sanitize_code_type(tree_node const*)

        /home/apinski/src/upstream-gcc-new/gcc/gcc/tree.cc:6704
0x92f581 tree_to_sanitize_code_type(tree_node const*)
        /home/apinski/src/upstream-gcc-new/gcc/gcc/tree.cc:6702
0x128bea2 print_no_sanitize_attr_value
        /home/apinski/src/upstream-gcc-new/gcc/gcc/tree-cfg.cc:8223
0x128bea2 dump_function_to_file(tree_node*, _IO_FILE*, dump_flag)
        /home/apinski/src/upstream-gcc-new/gcc/gcc/tree-cfg.cc:8276
Quoted 2 lines

Looks like you forgot to update dump_function_to_file too.
Can you double check all of the locations that use tree_to_sanitize_code_type to make sure they all have been fixed?

Fix this fail by below patch:

gcc/tree-cfg.cc +4 -1
index 66ea54f8b85..808b8000603 100644
@@ -8220,7 +8220,10 @@ dump_default_def (FILE *file, tree def, int spc, dump_flags_t flags)
 static void
 print_no_sanitize_attr_value (FILE *file, tree value)
 {
-  sanitize_code_type flags = tree_to_sanitize_code_type (value);
+  /* Extract the INTEGER_CST from the TREE_LIST wrapper.  */
+  gcc_assert (TREE_CODE (value) == TREE_LIST);
+  sanitize_code_type flags = tree_to_sanitize_code_type (TREE_VALUE (value));
+
   bool first = true;
   for (int i = 0; sanitizer_opts[i].name != NULL; ++i)
     {

I have checked the patch which first introduces the tree_to_sanitize_code_type
(https://inbox.sourceware.org/gcc-patches/[email protected]/)

Quoted 7 lines

Thanks,
Andrew

Quoted 3 lines

Thanks,
Andrew