On Wed, 29 Jul 2026, Jakub Jelinek wrote:
> Hi!
>
> Alex reported that since my r17-2388 fix we now emit an undesirable
> __asan_handle_no_return call before the __asan_report_{load,store}*
> calls added during bitintlower pass. Normally (when large/huge _BitInt
> is not involved), those are added by the sanopt pass which runs after
> the asan pass and so aren't instrumented.
>
> The following patch avoids instrumenting those.
> Unfortunately the first hunk isn't all that is needed.
> That is because for the bitintlower added __asan_report_* calls
> gimple_call_builtin_p (stmt, BUILT_IN_NORMAL) returns false
> due to argument type mismatch.
> THe C/C++/Fortran FEs use
> DEF_PRIMITIVE_TYPE (BT_PTRMODE, (*lang_hooks.types.type_for_mode)(ptr_mode,
> 0))
> and so use signed type with TYPE_MODE (ptr_mode).
> The fallback initialization in initialize_sanitizer_builtins
> (done for non-C/C++/Fortran FEs) uses for PTRMODE instead
> pointer_sized_int_node type, which is initialized to:
> pointer_sized_int_node = build_nonstandard_integer_type (POINTER_SIZE, 1);
> where
> ptr_mode = as_a <scalar_int_mode>
> (mode_for_size (POINTER_SIZE, GET_MODE_CLASS (Pmode), 0).require ());
> so, I think both have the same precision, just one is signed and one
> unsigned. And then asan_expand_poison_ifn uses pointer_sized_int_node.
>
> The following patch just changes initialize_sanitizer_builtins and
> asan_expand_poison_ifn to do the same thing as the C/C++/Fortran FEs here.
> Seems asan.cc is full of similar builtin argument type mismatches, but
> I've changed only what was needed for this patch.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
OK.
Thanks,
Richard.
> 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.
>
> --- gcc/asan.cc.jj 2026-07-14 10:39:46.550212889 +0200
> +++ gcc/asan.cc 2026-07-29 11:53:43.529201551 +0200
> @@ -3185,6 +3185,18 @@ maybe_instrument_call (gimple_stmt_itera
> 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_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));
>
> Jakub
>
>
--
Richard Biener <[email protected]>
SUSE Software Solutions Germany GmbH,
Frankenstrasse 146, 90461 Nuernberg, Germany;
GF: Jochen Jaser, Andrew McDonald, Abhinav Puri; (HRB 36809, AG Nuernberg)