From f1bc6caec5fdc1affd2047d518137f7de32cd5d6 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 10 Jul 2018 10:04:14 +0200 Subject: [PATCH] re PR sanitizer/86406 ([UBSAN] -fcompare-debug failure with -fsanitize=undefined) PR sanitizer/86406 * cp-gimplify.c (cp_maybe_instrument_return): Skip trailing DEBUG_BEGIN_STMTs. * g++.dg/ubsan/pr86406.C: New test. From-SVN: r262536 --- gcc/cp/ChangeLog | 4 ++++ gcc/cp/cp-gimplify.c | 7 ++++++ gcc/testsuite/ChangeLog | 3 +++ gcc/testsuite/g++.dg/ubsan/pr86406.C | 33 ++++++++++++++++++++++++++++ 4 files changed, 47 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ubsan/pr86406.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 86d4a349905..5fc7f05d3d0 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2018-07-10 Jakub Jelinek + PR sanitizer/86406 + * cp-gimplify.c (cp_maybe_instrument_return): Skip trailing + DEBUG_BEGIN_STMTs. + PR c++/86443 * semantics.c (handle_omp_for_class_iterator): Remove lastp argument, instead of setting *lastp turn orig_declv elt into a TREE_LIST. diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c index 16831fc7100..145af26f18d 100644 --- a/gcc/cp/cp-gimplify.c +++ b/gcc/cp/cp-gimplify.c @@ -1621,6 +1621,13 @@ cp_maybe_instrument_return (tree fndecl) case STATEMENT_LIST: { tree_stmt_iterator i = tsi_last (t); + while (!tsi_end_p (i)) + { + tree p = tsi_stmt (i); + if (TREE_CODE (p) != DEBUG_BEGIN_STMT) + break; + tsi_prev (&i); + } if (!tsi_end_p (i)) { t = tsi_stmt (i); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e2bc00d18f3..da079abfd5b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2018-07-10 Jakub Jelinek + PR sanitizer/86406 + * g++.dg/ubsan/pr86406.C: New test. + PR fortran/86421 * gfortran.dg/vect/pr86421.f90: New test. diff --git a/gcc/testsuite/g++.dg/ubsan/pr86406.C b/gcc/testsuite/g++.dg/ubsan/pr86406.C new file mode 100644 index 00000000000..1a0f4786a0f --- /dev/null +++ b/gcc/testsuite/g++.dg/ubsan/pr86406.C @@ -0,0 +1,33 @@ +// PR sanitizer/86406 +// { dg-do compile } +// { dg-options "-fcompare-debug -fsanitize=undefined -g -O1" } + +typedef enum { } cmd_status; +class ECell; +class ECell_const_ptr { }; +class ECell_ptr +{ + ECell *mp_element; + ECell *getPointer () const { return mp_element; } +public: + operator ECell_const_ptr () const { return ECell_const_ptr(); } +}; + +extern ECell_ptr NULL_CELL; +class VwUI_2DCellLayerView; +class view_cell_layoutImpl +{ + cmd_status handleChangeFlags (VwUI_2DCellLayerView * + p_ui_celllayerview, + ECell_const_ptr p_peekCell); + cmd_status openCellLayoutView (); +}; + +cmd_status +view_cell_layoutImpl::openCellLayoutView () +{ + ECell_const_ptr pcell = NULL_CELL; + VwUI_2DCellLayerView *p_user_interface; + return handleChangeFlags (p_user_interface, pcell); + ; +} -- 2.30.2