This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix cxx_omp_clause_apply_fn (PR c++/36237)


Hi!

As the attached testcase shows, if default arguments of ctor or other
special function applied for a privatized variable might throw,
cxx_omp_clause_apply_fn doesn't add needed CLEANUP_POINT_EXPR
and thus we end up with WITH_CLEANUP_EXPRs that aren't gimplified.

Fixed thusly, regtested on x86_64-linux, will apply to trunk/4.3.

2008-05-23  Jakub Jelinek  <jakub@redhat.com>

	PR c++/36237
	* cp-gimplify.c (cxx_omp_clause_apply_fn): Call
	fold_build_cleanup_point_expr on build_call_a results.

	* g++.dg/gomp/pr36237.C: New test.

--- gcc/cp/cp-gimplify.c.jj	2008-02-19 11:17:36.000000000 +0100
+++ gcc/cp/cp-gimplify.c	2008-05-23 14:48:22.000000000 +0200
@@ -1,6 +1,6 @@
 /* C++-specific tree lowering bits; see also c-gimplify.c and tree-gimple.c.
 
-   Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007
+   Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008
    Free Software Foundation, Inc.
    Contributed by Jason Merrill <jason@redhat.com>
 
@@ -784,7 +784,7 @@ cp_genericize (tree fndecl)
 static tree
 cxx_omp_clause_apply_fn (tree fn, tree arg1, tree arg2)
 {
-  tree defparm, parm;
+  tree defparm, parm, t;
   int i = 0;
   int nargs;
   tree *argarray;
@@ -804,7 +804,7 @@ cxx_omp_clause_apply_fn (tree fn, tree a
       tree inner_type = TREE_TYPE (arg1);
       tree start1, end1, p1;
       tree start2 = NULL, p2 = NULL;
-      tree ret = NULL, lab, t;
+      tree ret = NULL, lab;
 
       start1 = arg1;
       start2 = arg2;
@@ -849,6 +849,8 @@ cxx_omp_clause_apply_fn (tree fn, tree a
 	argarray[i] = convert_default_arg (TREE_VALUE (parm),
 					   TREE_PURPOSE (parm), fn, i);
       t = build_call_a (fn, i, argarray);
+      t = fold_convert (void_type_node, t);
+      t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
       append_to_statement_list (t, &ret);
 
       t = TYPE_SIZE_UNIT (inner_type);
@@ -881,7 +883,9 @@ cxx_omp_clause_apply_fn (tree fn, tree a
 	argarray[i] = convert_default_arg (TREE_VALUE (parm),
 					   TREE_PURPOSE (parm),
 					   fn, i);
-      return build_call_a (fn, i, argarray);
+      t = build_call_a (fn, i, argarray);
+      t = fold_convert (void_type_node, t);
+      return fold_build_cleanup_point_expr (TREE_TYPE (t), t);
     }
 }
 
--- gcc/testsuite/g++.dg/gomp/pr36237.C.jj	2008-05-23 14:54:47.000000000 +0200
+++ gcc/testsuite/g++.dg/gomp/pr36237.C	2008-05-23 14:54:30.000000000 +0200
@@ -0,0 +1,25 @@
+// PR c++/36237
+// { dg-do compile }
+// { dg-options "-fopenmp" }
+
+struct A
+{
+  ~A ();
+};
+
+struct B
+{
+  B (const A &x = A ()) : a (x) { }
+  A a;
+};
+
+B var;
+
+void bar ();
+
+void
+foo ()
+{
+  #pragma omp parallel private (var)
+    bar ();
+}

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]