[gcc(refs/users/marxin/heads/marxin-gcc-benchmark-branch)] middle-end/94216 fix another build_fold_addr_expr use

Martin Liska marxin@gcc.gnu.org
Mon Mar 30 10:57:39 GMT 2020


https://gcc.gnu.org/g:73bc09fa8c6b973a928a599498caa66a25c8bc8d

commit 73bc09fa8c6b973a928a599498caa66a25c8bc8d
Author: Richard Biener <rguenther@suse.de>
Date:   Thu Mar 19 10:15:52 2020 +0100

    middle-end/94216 fix another build_fold_addr_expr use
    
    2020-03-19  Richard Biener  <rguenther@suse.de>
    
            PR middle-end/94216
            * fold-const.c (fold_binary_loc): Avoid using
            build_fold_addr_expr when we really want an ADDR_EXPR.
    
            * g++.dg/torture/pr94216.C: New testcase.

Diff:
---
 gcc/ChangeLog                          |  6 +++++
 gcc/fold-const.c                       |  2 +-
 gcc/testsuite/ChangeLog                |  5 ++++
 gcc/testsuite/g++.dg/torture/pr94216.C | 45 ++++++++++++++++++++++++++++++++++
 4 files changed, 57 insertions(+), 1 deletion(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 66202f0253f..f015a55a870 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2020-03-19  Richard Biener  <rguenther@suse.de>
+
+	PR middle-end/94216
+	* fold-const.c (fold_binary_loc): Avoid using
+	build_fold_addr_expr when we really want an ADDR_EXPR.
+
 2020-03-18  Segher Boessenkool  <segher@kernel.crashing.org>
 
 	* config/rs6000/constraints.md (wd, wf, wi, ws, ww): New undocumented
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 3ab1a9adcdf..92679142f04 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -10284,7 +10284,7 @@ fold_binary_loc (location_t loc, enum tree_code code, tree type,
 	  if (!base)
 	    return NULL_TREE;
 	  return fold_build2 (MEM_REF, type,
-			      build_fold_addr_expr (base),
+			      build1 (ADDR_EXPR, TREE_TYPE (arg0), base),
 			      int_const_binop (PLUS_EXPR, arg1,
 					       size_int (coffset)));
 	}
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 9e5fecd24f7..e828b7f9c9a 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2020-03-19  Richard Biener  <rguenther@suse.de>
+
+	PR middle-end/94216
+	* g++.dg/torture/pr94216.C: New testcase.
+
 2020-03-18  Martin Sebor  <msebor@redhat.com>
 
 	PR ipa/92799
diff --git a/gcc/testsuite/g++.dg/torture/pr94216.C b/gcc/testsuite/g++.dg/torture/pr94216.C
new file mode 100644
index 00000000000..e67239de98d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/torture/pr94216.C
@@ -0,0 +1,45 @@
+// { dg-do compile }
+// { dg-additional-options "-g" }
+
+template <int _Nm> struct A { typedef int _Type[_Nm]; };
+template <int _Nm> struct B {
+    typename A<_Nm>::_Type _M_elems;
+    void operator[](int) { int a = *_M_elems; }
+};
+class C {
+    struct D {
+	using type = int *;
+    };
+
+public:
+    using pointer = D::type;
+};
+class F {
+public:
+    using pointer = C::pointer;
+    F(pointer);
+};
+struct G {
+    int data;
+};
+template <int MaxDimensions> struct H {
+    using dimensions_t = B<MaxDimensions>;
+    dimensions_t dimensions;
+    G mem;
+};
+template <int MaxDimensions, typename Allocator, typename DimT, typename AlignT>
+H<MaxDimensions> alloc_view(int, DimT, AlignT, Allocator) {
+    H<MaxDimensions> b;
+    b.dimensions[0];
+    return b;
+}
+namespace memory {
+    template <typename> using DynMdView = H<6>;
+}
+class I {
+    I();
+    memory::DynMdView<void> m_view;
+    F m_memory;
+};
+int c, d, e;
+I::I() : m_view(alloc_view<6>(c, d, e, [] {})), m_memory(&m_view.mem.data) {}


More information about the Gcc-cvs mailing list