From 85ade8d6402c58174db08a3dbd7cb7ac538cbeae Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Mon, 20 Feb 2017 15:50:23 +0000 Subject: [PATCH] re PR sanitizer/79558 (ICE: Segfault in ubsan_type_descriptor, at ubsan.c:412) PR sanitizer/79558 * ubsan.c (ubsan_type_descriptor): Check if TYPE_MAX_VALUE is null. * c-c++-common/ubsan/bounds-14.c: New test. From-SVN: r245605 --- gcc/ChangeLog | 3 +++ gcc/testsuite/ChangeLog | 3 +++ gcc/testsuite/c-c++-common/ubsan/bounds-14.c | 13 +++++++++++++ gcc/ubsan.c | 4 +++- 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/c-c++-common/ubsan/bounds-14.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index ab2e544d6d2..02b51576e2d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -3,6 +3,9 @@ PR middle-end/79537 * gimplify.c (gimplify_expr): Handle unused *&&L;. + PR sanitizer/79558 + * ubsan.c (ubsan_type_descriptor): Check if TYPE_MAX_VALUE is null. + 2017-02-20 Jakub Jelinek PR target/79568 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index bbe7ac9a4a4..645d2ed0e9d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -3,6 +3,9 @@ PR middle-end/79537 * gcc.dg/comp-goto-4.c: New test. + PR sanitizer/79558 + * c-c++-common/ubsan/bounds-14.c: New test. + 2017-02-20 Jakub Jelinek PR target/79568 diff --git a/gcc/testsuite/c-c++-common/ubsan/bounds-14.c b/gcc/testsuite/c-c++-common/ubsan/bounds-14.c new file mode 100644 index 00000000000..ddb52516235 --- /dev/null +++ b/gcc/testsuite/c-c++-common/ubsan/bounds-14.c @@ -0,0 +1,13 @@ +/* PR sanitizer/79558 */ +/* { dg-do compile } */ +/* { dg-options "-fsanitize=bounds" } */ + +void +fn1 (int n) +{ + int i, j; + int x[2][0]; + for (i = 0; i < n; i++) + for (j = 0; j < n; j++) + x[i][j] = 5; +} diff --git a/gcc/ubsan.c b/gcc/ubsan.c index 0291401eecf..11a41e1dc53 100644 --- a/gcc/ubsan.c +++ b/gcc/ubsan.c @@ -409,7 +409,9 @@ ubsan_type_descriptor (tree type, enum ubsan_print_style pstyle) { pp_left_bracket (&pretty_name); tree dom = TYPE_DOMAIN (t); - if (dom && TREE_CODE (TYPE_MAX_VALUE (dom)) == INTEGER_CST) + if (dom != NULL_TREE + && TYPE_MAX_VALUE (dom) != NULL_TREE + && TREE_CODE (TYPE_MAX_VALUE (dom)) == INTEGER_CST) { if (tree_fits_uhwi_p (TYPE_MAX_VALUE (dom)) && tree_to_uhwi (TYPE_MAX_VALUE (dom)) + 1 != 0) -- 2.30.2