From 96281645bdaeb0e7fb5f7340c47f60a2dbc800b2 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Fri, 24 Nov 2017 09:35:10 +0100 Subject: [PATCH] re PR sanitizer/83014 (ICE in pretty-print with -fsanitize=bounds) PR sanitizer/83014 * ubsan.c (ubsan_type_descriptor): Use pp_unsigned_wide_integer instead of pp_printf with HOST_WIDE_INT_PRINT_DEC. Avoid calling tree_to_uhwi twice. * gcc.dg/ubsan/pr83014.c: New test. From-SVN: r255134 --- gcc/ChangeLog | 5 +++++ gcc/testsuite/ChangeLog | 3 +++ gcc/testsuite/gcc.dg/ubsan/pr83014.c | 12 ++++++++++++ gcc/ubsan.c | 6 +++--- 4 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/ubsan/pr83014.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 787e545949e..8f34f37b365 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,10 @@ 2017-11-24 Jakub Jelinek + PR sanitizer/83014 + * ubsan.c (ubsan_type_descriptor): Use pp_unsigned_wide_integer + instead of pp_printf with HOST_WIDE_INT_PRINT_DEC. Avoid calling + tree_to_uhwi twice. + * tree-object-size.c (pass_through_call): Use gimple_call_return_flags ERF_RETURN*ARG* for builtins other than BUILT_IN_ASSUME_ALIGNED, check for the latter with gimple_call_builtin_p. Do not handle diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 480a5c637ff..eef79af85a4 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2017-11-24 Jakub Jelinek + PR sanitizer/83014 + * gcc.dg/ubsan/pr83014.c: New test. + * gcc.dg/builtin-object-size-18.c: New test. 2017-11-23 Julia Koval diff --git a/gcc/testsuite/gcc.dg/ubsan/pr83014.c b/gcc/testsuite/gcc.dg/ubsan/pr83014.c new file mode 100644 index 00000000000..de626043cc6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/ubsan/pr83014.c @@ -0,0 +1,12 @@ +/* PR sanitizer/83014 */ +/* { dg-do compile } */ +/* { dg-options "-fsanitize=undefined" } */ + +int +foo (void) +{ + int data[5]; + data[0] = 0; + data[5] = 0; + return data[0]; +} diff --git a/gcc/ubsan.c b/gcc/ubsan.c index 560d4654850..efde3f7bc36 100644 --- a/gcc/ubsan.c +++ b/gcc/ubsan.c @@ -436,10 +436,10 @@ ubsan_type_descriptor (tree type, enum ubsan_print_style pstyle) && TYPE_MAX_VALUE (dom) != NULL_TREE && TREE_CODE (TYPE_MAX_VALUE (dom)) == INTEGER_CST) { + unsigned HOST_WIDE_INT m; if (tree_fits_uhwi_p (TYPE_MAX_VALUE (dom)) - && tree_to_uhwi (TYPE_MAX_VALUE (dom)) + 1 != 0) - pp_printf (&pretty_name, HOST_WIDE_INT_PRINT_DEC, - tree_to_uhwi (TYPE_MAX_VALUE (dom)) + 1); + && (m = tree_to_uhwi (TYPE_MAX_VALUE (dom))) + 1 != 0) + pp_unsigned_wide_integer (&pretty_name, m + 1); else pp_wide_int (&pretty_name, wi::add (wi::to_widest (TYPE_MAX_VALUE (dom)), 1), -- 2.30.2