re PR c++/82835 (ICE on valid code with -fopenmp)
authorJakub Jelinek <jakub@redhat.com>
Tue, 7 Nov 2017 20:51:05 +0000 (21:51 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 7 Nov 2017 20:51:05 +0000 (21:51 +0100)
PR c++/82835
* cp-gimplify.c (cxx_omp_clause_apply_fn): For methods pass i - 1 to
convert_default_arg instead of i.

* testsuite/libgomp.c++/pr82835.C: New test.

From-SVN: r254511

gcc/cp/ChangeLog
gcc/cp/cp-gimplify.c
libgomp/ChangeLog
libgomp/testsuite/libgomp.c++/pr82835.C [new file with mode: 0644]

index 44788808193bdb9f25db4ff0ba719c22860051d8..52cd542bb9731844e076731e30b51554139287e8 100644 (file)
@@ -1,3 +1,9 @@
+2017-11-07  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/82835
+       * cp-gimplify.c (cxx_omp_clause_apply_fn): For methods pass i - 1 to
+       convert_default_arg instead of i.
+
 2017-11-06  Jason Merrill  <jason@redhat.com>
 
        P0704R1 - fixing const-qualified pointers to members
index 014c1ee7231f7889e3bac40b1e6e755a3175ce30..7c7c0409af8378769a6fd8420a70e23e1e63ee60 100644 (file)
@@ -1717,6 +1717,7 @@ cxx_omp_clause_apply_fn (tree fn, tree arg1, tree arg2)
   if (arg2)
     defparm = TREE_CHAIN (defparm);
 
+  bool is_method = TREE_CODE (TREE_TYPE (fn)) == METHOD_TYPE;
   if (TREE_CODE (TREE_TYPE (arg1)) == ARRAY_TYPE)
     {
       tree inner_type = TREE_TYPE (arg1);
@@ -1765,8 +1766,8 @@ cxx_omp_clause_apply_fn (tree fn, tree arg1, tree arg2)
       for (parm = defparm; parm && parm != void_list_node;
           parm = TREE_CHAIN (parm), i++)
        argarray[i] = convert_default_arg (TREE_VALUE (parm),
-                                          TREE_PURPOSE (parm), fn, i,
-                                          tf_warning_or_error);
+                                          TREE_PURPOSE (parm), fn,
+                                          i - is_method, tf_warning_or_error);
       t = build_call_a (fn, i, argarray);
       t = fold_convert (void_type_node, t);
       t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
@@ -1798,8 +1799,8 @@ cxx_omp_clause_apply_fn (tree fn, tree arg1, tree arg2)
       for (parm = defparm; parm && parm != void_list_node;
           parm = TREE_CHAIN (parm), i++)
        argarray[i] = convert_default_arg (TREE_VALUE (parm),
-                                          TREE_PURPOSE (parm),
-                                          fn, i, tf_warning_or_error);
+                                          TREE_PURPOSE (parm), fn,
+                                          i - is_method, tf_warning_or_error);
       t = build_call_a (fn, i, argarray);
       t = fold_convert (void_type_node, t);
       return fold_build_cleanup_point_expr (TREE_TYPE (t), t);
index 7c0e808d587250092e12647b44ad29c70e1f0103..19966bd0947646e135680d307382880d65349a9f 100644 (file)
@@ -1,3 +1,8 @@
+2017-11-07  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/82835
+       * testsuite/libgomp.c++/pr82835.C: New test.
+
 2017-11-06  Martin Liska  <mliska@suse.cz>
 
        * testsuite/libgomp.c++/loop-2.C: Return a value
diff --git a/libgomp/testsuite/libgomp.c++/pr82835.C b/libgomp/testsuite/libgomp.c++/pr82835.C
new file mode 100644 (file)
index 0000000..df64ecf
--- /dev/null
@@ -0,0 +1,34 @@
+// PR c++/82835
+// { dg-do run }
+
+int a, b;
+
+template <class>
+struct C {
+  C (int x = a) : c (5) { if (x != 137) __builtin_abort (); }
+  int c;
+};
+
+struct D {
+  void foo ();
+  int d;
+};
+
+void
+D::foo ()
+{
+  C<int> c;
+#pragma omp for private (c)
+  for (b = 0; b < d; b++)
+    c.c++;
+}
+
+int
+main ()
+{
+  a = 137;
+  D d;
+  d.d = 16;
+  d.foo ();
+  return 0;
+}