This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH][PR sanitizer/80414] Fix segfault with -fsanitize=undefined on 32 bit host
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Denis Khalikov <d dot khalikov at partner dot samsung dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 13 Apr 2017 15:10:10 +0200
- Subject: Re: [PATCH][PR sanitizer/80414] Fix segfault with -fsanitize=undefined on 32 bit host
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jakub at redhat dot com
- Dkim-filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 6B53AC04BD3A
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6B53AC04BD3A
- References: <CGME20170413092842eucas1p248fe63106fdfe22f61a21aa33c066ed2@eucas1p2.samsung.com> <e411b044-8ab8-cf2d-75de-221ce305d8c5@partner.samsung.com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Thu, Apr 13, 2017 at 12:28:40PM +0300, Denis Khalikov wrote:
> --- /dev/null
> +++ b/gcc/testsuite/c-c++-common/ubsan/bounds-15.c
> @@ -0,0 +1,11 @@
> +/* { dg-do run } */
> +/* { dg-options "-fsanitize=bounds" } */
> +/* { dg-skip-if "" { *-*-* } { "*" } { "-O0" } } */
> +
> +int main()
> +{
> + long long offset = 10;
> + char array[10];
> + char c = array[offset];
> + return 0;
> +}
I would expect you want to dg-output here the runtime diagnostics,
at least some part of it, to make it clear the testcase is UB and
to test whether the UB is detected.
> diff --git a/gcc/ubsan.c b/gcc/ubsan.c
> index c01d633..9333336 100644
> --- a/gcc/ubsan.c
> +++ b/gcc/ubsan.c
> @@ -672,7 +672,8 @@ ubsan_expand_bounds_ifn (gimple_stmt_iterator *gsi)
>
> /* Pick up the arguments of the UBSAN_BOUNDS call. */
> tree type = TREE_TYPE (TREE_TYPE (gimple_call_arg (stmt, 0)));
> - tree index = gimple_call_arg (stmt, 1);
> + tree index, orig_index;
> + index = orig_index = gimple_call_arg (stmt, 1);
> tree orig_index_type = TREE_TYPE (index);
Instead of this I'd suggest:
tree index = gimple_call_arg (stmt, 1);
- tree orig_index_type = TREE_TYPE (index);
+ tree orig_index = index;
> tree bound = gimple_call_arg (stmt, 2);
>
> @@ -708,9 +709,9 @@ ubsan_expand_bounds_ifn (gimple_stmt_iterator *gsi)
> ? BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS
> : BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS_ABORT;
> tree fn = builtin_decl_explicit (bcode);
> - tree val = force_gimple_operand_gsi (gsi, ubsan_encode_value (index),
> - true, NULL_TREE, true,
> - GSI_SAME_STMT);
> + tree val
> + = force_gimple_operand_gsi (gsi, ubsan_encode_value (orig_index), true,
> + NULL_TREE, true, GSI_SAME_STMT);
> g = gimple_build_call (fn, 2, data, val);
> }
> gimple_set_location (g, loc);
and replace orig_index_type use with TREE_TYPE (orig_index)
Jakub