public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] [PR c++/84943] allow folding of array indexing indirect_ref
@ 2018-03-22 23:03 Alexandre Oliva
  2018-03-23 13:12 ` Jason Merrill
  0 siblings, 1 reply; 19+ messages in thread
From: Alexandre Oliva @ 2018-03-22 23:03 UTC (permalink / raw)
  To: gcc-patches; +Cc: jason, nathan

fn[0]() ICEs because we end up with addr_expr of a decl, and that
should only happen for artificial or otherwise special internal
functions.  For anything else, we should find the decl earlier, but we
don't because we build an indirect_ref or an addr_expr and don't
cancel them out.  Let fold do its job when building the array indexing
indirect_ref, and the ICE is gone.

Regstrapped on i686- and x86_64-linux-gnu.  Ok to install?

for  gcc/cp/ChangeLog

	PR c++/84943
	* typeck.c (cp_build_array_ref): Allow the indirect_ref to be
	folded.

for  gcc/testsuite/ChangeLog

	PR c++/84943
	* g++.dg/pr84943.C: New.
---
 gcc/cp/typeck.c                |   10 +++++-----
 gcc/testsuite/g++.dg/pr84943.C |    8 ++++++++
 2 files changed, 13 insertions(+), 5 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/pr84943.C

diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index d3183b5321d3..5d08cb78a388 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -3393,11 +3393,11 @@ cp_build_array_ref (location_t loc, tree array, tree idx,
 
     warn_array_subscript_with_type_char (loc, idx);
 
-    ret = cp_build_indirect_ref (cp_build_binary_op (input_location,
-						     PLUS_EXPR, ar, ind,
-						     complain),
-                                 RO_ARRAY_INDEXING,
-                                 complain);
+    ret = cp_build_indirect_ref_1 (cp_build_binary_op (input_location,
+						       PLUS_EXPR, ar, ind,
+						       complain),
+				   RO_ARRAY_INDEXING,
+				   complain, true);
     protected_set_expr_location (ret, loc);
     if (non_lvalue)
       ret = non_lvalue_loc (loc, ret);
diff --git a/gcc/testsuite/g++.dg/pr84943.C b/gcc/testsuite/g++.dg/pr84943.C
new file mode 100644
index 000000000000..36f75a164119
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr84943.C
@@ -0,0 +1,8 @@
+// { dg-do compile }
+
+// Avoid -pedantic-error default
+// { dg-options "" }
+
+void a() {
+  a[0](); // { dg-warning "arithmetic" }
+}


-- 
Alexandre Oliva, freedom fighter    http://FSFLA.org/~lxoliva/
You must be the change you wish to see in the world. -- Gandhi
Be Free! -- http://FSFLA.org/   FSF Latin America board member
Free Software Evangelist|Red Hat Brasil GNU Toolchain Engineer

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2018-04-04  2:41 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-22 23:03 [PATCH] [PR c++/84943] allow folding of array indexing indirect_ref Alexandre Oliva
2018-03-23 13:12 ` Jason Merrill
2018-03-23 16:19   ` Alexandre Oliva
2018-03-23 16:45     ` Jason Merrill
2018-03-23 20:59       ` Jason Merrill
2018-03-23 22:04         ` Jason Merrill
2018-03-28  6:31           ` Alexandre Oliva
2018-03-28 19:21             ` Jason Merrill
2018-03-30  1:07               ` Alexandre Oliva
2018-03-30  2:31                 ` Alexandre Oliva
2018-03-30  7:49                   ` Alexandre Oliva
2018-03-30 14:46                     ` Jason Merrill
2018-03-31  8:23                       ` Alexandre Oliva
2018-04-03  1:17                         ` Jason Merrill
2018-04-03  7:44                           ` Alexandre Oliva
2018-04-03 15:48                             ` Jason Merrill
2018-04-03 15:48                               ` Jason Merrill
2018-04-04  2:41                                 ` Alexandre Oliva
2018-03-23 20:55   ` Alexandre Oliva

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).