diff options
author | Denis Khalikov <d.khalikov@partner.samsung.com> | 2017-06-02 12:17:06 +0300 |
---|---|---|
committer | Dongkyun Son <dongkyun.s@samsung.com> | 2017-06-08 00:14:50 +0000 |
commit | ac5b0b65260c7b4659fc503b96401f7011601c69 (patch) | |
tree | 124fe71527fd9d551078baa2c51aa1d79e153b31 | |
parent | aa45a75f425e69935bde7dbbfdb2e629e9d43ed5 (diff) | |
download | linaro-gcc-ac5b0b65260c7b4659fc503b96401f7011601c69.tar.gz linaro-gcc-ac5b0b65260c7b4659fc503b96401f7011601c69.tar.bz2 linaro-gcc-ac5b0b65260c7b4659fc503b96401f7011601c69.zip |
PR sanitizer/80414
* ubsan.c (ubsan_expand_bounds_ifn): Pass original index
to ubsan_encode_value.
Change-Id: Id8e339c51aac586cd7d61e02a6711e875354948a
Signed-off-by: Denis Khalikov <d.khalikov@partner.samsung.com>
-rw-r--r-- | gcc/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/c-c++-common/ubsan/bounds-15.c | 13 | ||||
-rw-r--r-- | gcc/ubsan.c | 10 |
4 files changed, 29 insertions, 5 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d83072b727f..77528a50efc 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2017-04-13 Denis Khalikov <d.khalikov@partner.samsung.com> + + PR sanitizer/80414 + * ubsan.c (ubsan_expand_bounds_ifn): Pass original index + to ubsan_encode_value. + 2017-03-07 Jakub Jelinek <jakub@redhat.com> PR sanitizer/79897 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e564593263e..3ae4c959a54 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-04-13 Denis Khalikov <d.khalikov@partner.samsung.com> + + PR sanitizer/80414 + * c-c++-common/ubsan/bounds-15.c: New test. + 2017-03-07 Jakub Jelinek <jakub@redhat.com> PR sanitizer/79897 diff --git a/gcc/testsuite/c-c++-common/ubsan/bounds-15.c b/gcc/testsuite/c-c++-common/ubsan/bounds-15.c new file mode 100644 index 00000000000..5fa8eee524e --- /dev/null +++ b/gcc/testsuite/c-c++-common/ubsan/bounds-15.c @@ -0,0 +1,13 @@ +/* { 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; +} + +/* { dg-output "index 10 out of bounds for type 'char \\\[10\\\]'" } */ diff --git a/gcc/ubsan.c b/gcc/ubsan.c index 127f21dda96..cbb46ec6601 100644 --- a/gcc/ubsan.c +++ b/gcc/ubsan.c @@ -666,7 +666,7 @@ 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 orig_index_type = TREE_TYPE (index); + tree orig_index = index; tree bound = gimple_call_arg (stmt, 2); gimple_stmt_iterator gsi_orig = *gsi; @@ -693,7 +693,7 @@ ubsan_expand_bounds_ifn (gimple_stmt_iterator *gsi) tree data = ubsan_create_data ("__ubsan_out_of_bounds_data", 1, &loc, ubsan_type_descriptor (type, UBSAN_PRINT_ARRAY), - ubsan_type_descriptor (orig_index_type), + ubsan_type_descriptor (TREE_TYPE (orig_index)), NULL_TREE, NULL_TREE); data = build_fold_addr_expr_loc (loc, data); enum built_in_function bcode @@ -701,9 +701,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); |