From 5c3f1d7b10ab48d50e80359eb18c0edc1e3ed402 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 21 Feb 2017 18:59:07 +0100 Subject: [PATCH] re PR sanitizer/79589 (ICE in gimplify_compound_expr (gimplify.c:5712) with -fsanitize=undefined) PR sanitizer/79589 * decl.c: Include gimplify.h. (cp_finish_decomp): Make sure there is no sharing of trees in between DECL_VALUE_EXPR of decomposition decls. * g++.dg/ubsan/pr79589.C: New test. From-SVN: r245638 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/decl.c | 10 ++++++---- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/ubsan/pr79589.C | 13 +++++++++++++ 4 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ubsan/pr79589.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 914f80c777d..a63eb4be2a5 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,10 @@ 2017-02-21 Jakub Jelinek + PR sanitizer/79589 + * decl.c: Include gimplify.h. + (cp_finish_decomp): Make sure there is no sharing of trees + in between DECL_VALUE_EXPR of decomposition decls. + PR c++/79655 * constexpr.c (cxx_eval_array_reference): Diagnose negative subscript. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index e5c2bab214b..5ab9a20c829 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -50,6 +50,7 @@ along with GCC; see the file COPYING3. If not see #include "plugin.h" #include "cilk.h" #include "builtins.h" +#include "gimplify.h" /* Possible cases of bad specifiers type used by bad_specifiers. */ enum bad_spec_place { @@ -7470,7 +7471,7 @@ cp_finish_decomp (tree decl, tree first, unsigned int count) { TREE_TYPE (v[i]) = eltype; layout_decl (v[i], 0); - tree t = dexp; + tree t = unshare_expr (dexp); t = build4_loc (DECL_SOURCE_LOCATION (v[i]), ARRAY_REF, eltype, t, size_int (i), NULL_TREE, NULL_TREE); @@ -7489,7 +7490,7 @@ cp_finish_decomp (tree decl, tree first, unsigned int count) { TREE_TYPE (v[i]) = eltype; layout_decl (v[i], 0); - tree t = dexp; + tree t = unshare_expr (dexp); t = build1_loc (DECL_SOURCE_LOCATION (v[i]), i ? IMAGPART_EXPR : REALPART_EXPR, eltype, t); @@ -7507,7 +7508,7 @@ cp_finish_decomp (tree decl, tree first, unsigned int count) { TREE_TYPE (v[i]) = eltype; layout_decl (v[i], 0); - tree t = dexp; + tree t = unshare_expr (dexp); convert_vector_to_array_for_subscript (DECL_SOURCE_LOCATION (v[i]), &t, size_int (i)); t = build4_loc (DECL_SOURCE_LOCATION (v[i]), ARRAY_REF, @@ -7606,7 +7607,8 @@ cp_finish_decomp (tree decl, tree first, unsigned int count) continue; else { - tree tt = finish_non_static_data_member (field, t, NULL_TREE); + tree tt = finish_non_static_data_member (field, unshare_expr (t), + NULL_TREE); if (REFERENCE_REF_P (tt)) tt = TREE_OPERAND (tt, 0); TREE_TYPE (v[i]) = TREE_TYPE (tt); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 9f278bb8b83..abefa2db56a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-02-21 Jakub Jelinek + + PR sanitizer/79589 + * g++.dg/ubsan/pr79589.C: New test. + 2017-02-21 Jeff Law PR tree-optimization/79621 diff --git a/gcc/testsuite/g++.dg/ubsan/pr79589.C b/gcc/testsuite/g++.dg/ubsan/pr79589.C new file mode 100644 index 00000000000..1c6d8635863 --- /dev/null +++ b/gcc/testsuite/g++.dg/ubsan/pr79589.C @@ -0,0 +1,13 @@ +// PR sanitizer/79589 +// { dg-do compile } +// { dg-options "-fsanitize=undefined -std=c++1z" } + +struct A { char a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r; } a[64]; + +void +foo () +{ + int z = 0; + for (auto & [ b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s ] : a) + z += b + c + d + e + f + g + h + i + j + k + l + m + n + o + p + q + r + s; +} -- 2.30.2