This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH: PR 23167
- From: Mark Mitchell <mark at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: rth at redhat dot com
- Date: Wed, 31 Aug 2005 15:03:40 -0700
- Subject: C++ PATCH: PR 23167
- Reply-to: mark at codesourcery dot com
Here is the previously discussed patch to correct the handling of
volatile classes with copy constructors or destructors. Tested on
x86_64-unknown-linux-gnu.
RTH requested that this change be made in the C++ gimplifier hook, but
I realized that it has no way of knowing whether the expression is
seeing is at the top-level or not, and it needs to know that in order
to determine whether or not to make this change. In addition, I think
this handling really ought to be language-independent; both TYPE_VOLATILE
and TREE_ADDRESSABLE have language-independent meaning, so I think
that the generic gimplifier ought to handle this case.
Therefore, I inted to go ahead and commit this patch, after 24 hours,
unless RTH restrains me.
--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
2005-08-31 Mark Mitchell <mark@codesourcery.com>
PR c++/23167
* gimplify.c (gimplify_expr): Handle TREE_ADDRESSABLE types when
generating synthetic loads from volatile lvalues.
2005-08-31 Mark Mitchell <mark@codesourcery.com>
PR c++/23167
* g++.dg/expr/volatile1.C: New test.
Index: gimplify.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gimplify.c,v
retrieving revision 2.148
diff -c -5 -p -r2.148 gimplify.c
*** gimplify.c 23 Aug 2005 07:28:11 -0000 2.148
--- gimplify.c 31 Aug 2005 21:59:23 -0000
*************** gimplify_expr (tree *expr_p, tree *pre_p
*** 4446,4456 ****
else if (COMPLETE_TYPE_P (TREE_TYPE (*expr_p)))
{
/* Historically, the compiler has treated a bare
reference to a volatile lvalue as forcing a load. */
tree type = TYPE_MAIN_VARIANT (TREE_TYPE (*expr_p));
! tree tmp = create_tmp_var (type, "vol");
*expr_p = build (MODIFY_EXPR, type, tmp, *expr_p);
}
else
/* We can't do anything useful with a volatile reference to
incomplete type, so just throw it away. */
--- 4446,4464 ----
else if (COMPLETE_TYPE_P (TREE_TYPE (*expr_p)))
{
/* Historically, the compiler has treated a bare
reference to a volatile lvalue as forcing a load. */
tree type = TYPE_MAIN_VARIANT (TREE_TYPE (*expr_p));
! /* Normally, we do want to create a temporary for a
! TREE_ADDRESSABLE type because such a type should not be
! copied by bitwise-assignment. However, we make an
! exception here, as all we are doing here is ensuring that
! we read the bytes that make up the type. We use
! create_tmp_var_raw because create_tmp_var will abort when
! given a TREE_ADDRESSSABLE type. */
! tree tmp = create_tmp_var_raw (type, "vol");
! gimple_add_tmp_var (tmp);
*expr_p = build (MODIFY_EXPR, type, tmp, *expr_p);
}
else
/* We can't do anything useful with a volatile reference to
incomplete type, so just throw it away. */
Index: testsuite/g++.dg/expr/volatile1.C
===================================================================
RCS file: testsuite/g++.dg/expr/volatile1.C
diff -N testsuite/g++.dg/expr/volatile1.C
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/expr/volatile1.C 31 Aug 2005 21:59:23 -0000
***************
*** 0 ****
--- 1,9 ----
+ // PR c++/23167
+
+ struct dom
+ {
+ static int tostr();
+ void eval_old() volatile{tostr();}
+ ~dom() throw();
+ };
+