Skip to contentSkip to conversation

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

PATCH Andrew Pinski 1 participant 1 message Mar 7 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 4 lines · hanwei (K)

Ping...

Can you submit a full new patch rather than just a patch on top of Kees patch? Please use Co-authored-by: too.

Thanks,
Andrew

Quoted 168 lines
Quoted 168 lines · On Wed, Feb 25, 2026 at 12:28 AM hstk30 <[email protected]> wrote:
Quoted 97 lines · Andrew Pinski
Quoted 53 lines · Kees Cook
Quoted 35 lines

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

    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
Quoted 7 lines

0x860f78 copy_list(tree_node*)

        ../../gcc/gcc/tree.cc:1427

0xa755a5 handle_copy_attribute

        ../../gcc/gcc/c-family/c-attribs.cc:3077

I am not a fan of the wrapping because it increases the memory usage

Quoted 7 lines

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 3 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 +0 -0

index 66ea54f8b85..808b8000603 100644

--- a/gcc/tree-cfg.cc

+++ b/gcc/tree-cfg.cc

gcc/tree-cfg.cc +4 -1
@@ -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 13 lines

Thanks,

Andrew

Quoted 5 lines

Thanks,

Andrew