summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2025-07-03 22:39:39 +0200
committerJakub Jelinek <jakub@gcc.gnu.org>2025-07-03 22:56:43 +0200
commited950a9ed384389ff07ac793b7065abe31bcae3f (patch)
treed77331ae5dc9278aed33df71e640018bb9db3467
parentb5f0faa4eb71650a9dde3938c3a98eda710534de (diff)
c++: Fix a pasto in the PR120471 fix [PR120940]
No idea how this slipped in, I'm terribly sorry. Strangely nothing in the testsuite has caught this, so I've added a new test for that. 2025-07-03 Jakub Jelinek <jakub@redhat.com> PR c++/120940 * typeck.cc (cp_build_array_ref): Fix a pasto. * g++.dg/parse/pr120940.C: New test. * g++.dg/warn/Wduplicated-branches9.C: New test. (cherry picked from commit dc90649466a54ab61926d88500a05f59a55cb055)
-rw-r--r--gcc/cp/typeck.cc2
-rw-r--r--gcc/testsuite/g++.dg/parse/pr120940.C18
-rw-r--r--gcc/testsuite/g++.dg/warn/Wduplicated-branches9.C11
3 files changed, 30 insertions, 1 deletions
diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc
index 19dfaf18928..2f67bb33ff0 100644
--- a/gcc/cp/typeck.cc
+++ b/gcc/cp/typeck.cc
@@ -3814,7 +3814,7 @@ cp_build_array_ref (location_t loc, tree array, tree idx,
tree op0, op1, op2;
op0 = TREE_OPERAND (array, 0);
op1 = TREE_OPERAND (array, 1);
- op2 = TREE_OPERAND (array, 1);
+ op2 = TREE_OPERAND (array, 2);
if (TREE_SIDE_EFFECTS (idx) || !tree_invariant_p (idx))
{
/* If idx could possibly have some SAVE_EXPRs, turning
diff --git a/gcc/testsuite/g++.dg/parse/pr120940.C b/gcc/testsuite/g++.dg/parse/pr120940.C
new file mode 100644
index 00000000000..5da36b2f88a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/parse/pr120940.C
@@ -0,0 +1,18 @@
+// PR c++/120940
+// { dg-do run }
+
+int a[8] = { 1, 2, 3, 4, 5, 6, 7, 8 };
+int b[8] = { 9, 10, 11, 12, 13, 14, 15, 16 };
+
+__attribute__((noipa)) int
+foo (int x, int y)
+{
+ return (x ? a : b)[y];
+}
+
+int
+main ()
+{
+ if (foo (1, 4) != 5 || foo (0, 6) != 15)
+ __builtin_abort ();
+}
diff --git a/gcc/testsuite/g++.dg/warn/Wduplicated-branches9.C b/gcc/testsuite/g++.dg/warn/Wduplicated-branches9.C
new file mode 100644
index 00000000000..f9fafcd467b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wduplicated-branches9.C
@@ -0,0 +1,11 @@
+// PR c++/120940
+// { dg-do compile }
+// { dg-options "-Wduplicated-branches" }
+
+static char a[16][8], b[16][8];
+
+char *
+foo (int x, int y)
+{
+ return (x ? a : b)[y];
+}