[gcc(refs/users/aoliva/heads/testme)] [asan] [bitint] do not instrument early lowering of bitint asan [PR126084]

Alexandre Oliva via Gcc-cvs <[email protected]> Thu, 30 Jul 2026 01:21:31 +0000 (GMT)
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:2b025fd5433ca925c97a418aa0ded2cbde29b9d2

commit 2b025fd5433ca925c97a418aa0ded2cbde29b9d2
Author: Jakub Jelinek <[email protected]>
Date:   Wed Jul 29 22:16:15 2026 -0300

    [asan] [bitint] do not instrument early lowering of bitint asan [PR126084]
    
    2026-07-29  Jakub Jelinek  <[email protected]>
    
            PR middle-end/126084
            * asan.cc (maybe_instrument_call): Don't instrument
            BUILT_IN_ASAN_REPORT_{LOAD,STORE}{1,2,4,8,16,_N} builtins.
            (initialize_sanitizer_builtins): Use
            (*lang_hooks.types.type_for_mode) (ptr_mode, 0) instead of
            pointer_sized_int_mode for PTRMODE arguments.
            (asan_expand_poison_ifn): Likewise.

Diff:
---
 gcc/asan.cc | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/gcc/asan.cc b/gcc/asan.cc
index 19c175b495f8..7f625fdcfa09 100644
--- a/gcc/asan.cc
+++ b/gcc/asan.cc
@@ -3185,6 +3185,18 @@ maybe_instrument_call (gimple_stmt_iterator *iter)
 	    case BUILT_IN_UNREACHABLE:
 	    case BUILT_IN_UNREACHABLE_TRAP:
 	    case BUILT_IN_TRAP:
+	    case BUILT_IN_ASAN_REPORT_LOAD1:
+	    case BUILT_IN_ASAN_REPORT_LOAD2:
+	    case BUILT_IN_ASAN_REPORT_LOAD4:
+	    case BUILT_IN_ASAN_REPORT_LOAD8:
+	    case BUILT_IN_ASAN_REPORT_LOAD16:
+	    case BUILT_IN_ASAN_REPORT_LOAD_N:
+	    case BUILT_IN_ASAN_REPORT_STORE1:
+	    case BUILT_IN_ASAN_REPORT_STORE2:
+	    case BUILT_IN_ASAN_REPORT_STORE4:
+	    case BUILT_IN_ASAN_REPORT_STORE8:
+	    case BUILT_IN_ASAN_REPORT_STORE16:
+	    case BUILT_IN_ASAN_REPORT_STORE_N:
 	      /* Don't instrument these.  */
 	      return false;
 	    default:
@@ -3585,6 +3597,7 @@ initialize_sanitizer_builtins (void)
   if (builtin_decl_implicit_p (BUILT_IN_ASAN_INIT))
     return;
 
+  tree ptrmode_type = (*lang_hooks.types.type_for_mode) (ptr_mode, 0);
   tree BT_FN_VOID = build_function_type_list (void_type_node, NULL_TREE);
   tree BT_FN_VOID_PTR
     = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
@@ -3598,7 +3611,7 @@ initialize_sanitizer_builtins (void)
 				ptr_type_node, ptr_type_node, NULL_TREE);
   tree BT_FN_VOID_PTR_PTRMODE
     = build_function_type_list (void_type_node, ptr_type_node,
-				pointer_sized_int_node, NULL_TREE);
+				ptrmode_type, NULL_TREE);
   tree BT_FN_VOID_INT
     = build_function_type_list (void_type_node, integer_type_node, NULL_TREE);
   tree BT_FN_SIZE_CONST_PTR_INT
@@ -3633,7 +3646,7 @@ initialize_sanitizer_builtins (void)
   tree BT_FN_VOID_PTR_UINT8_PTRMODE
     = build_function_type_list (void_type_node, ptr_type_node,
 				unsigned_char_type_node,
-				pointer_sized_int_node, NULL_TREE);
+				ptrmode_type, NULL_TREE);
 
   tree BT_FN_BOOL_VPTR_PTR_IX_INT_INT[5];
   tree BT_FN_IX_CONST_VPTR_INT[5];
@@ -4385,11 +4398,13 @@ asan_expand_poison_ifn (gimple_stmt_iterator *iter,
 	{
 	  tree fun = report_error_func (store_p, recover_p, tree_to_uhwi (size),
 					&nargs);
+	  tree ptrmode_type
+	    = (nargs == 2 ? (*lang_hooks.types.type_for_mode) (ptr_mode, 0)
+	       : NULL_TREE);
 	  call = gimple_build_call (fun, nargs,
 				    build_fold_addr_expr (shadow_var),
 				    nargs == 2
-				    ? fold_convert (pointer_sized_int_node,
-						    size)
+				    ? fold_convert (ptrmode_type, size)
 				    : NULL_TREE);
 	}
       gimple_set_location (call, gimple_location (use));