This is the mail archive of the gcc@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]

Re: volatile semantics


On Sun, Jul 17, 2005 at 09:18:01AM -0700, Ian Lance Taylor wrote:
> This is PR 22278.  DannyB posted a simple, untested, patch here:
>     http://gcc.gnu.org/ml/gcc/2005-07/msg00699.html

Thanks.  I think Danny's patch attacks this too late.  The 
following patch appears to do the right thing with the three
test cases I was given in another reply.

I'll bootstrap it right quick, and see if it has other odd
interactions with other test cases.

My time is limited today.  Anyone want to figure out the right
things to regexp on to make a set of testsuite entries for this?  
If not, I'll work on that Monday.


r~


	* gimplify.c (gimplify_expr): Create a non-volatile local to
	receive the result of a bare volatile read.
	* tree-ssa.c (tree_ssa_useless_type_conversion_1): Don't discard
	casts between pointers to volatile qualified types.

Index: gimplify.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gimplify.c,v
retrieving revision 2.140
diff -u -p -d -r2.140 gimplify.c
--- gimplify.c	8 Jul 2005 23:36:40 -0000	2.140
+++ gimplify.c	17 Jul 2005 16:34:47 -0000
@@ -4411,8 +4411,9 @@ gimplify_expr (tree *expr_p, tree *pre_p
 	{
 	  /* Historically, the compiler has treated a bare
 	     reference to a volatile lvalue as forcing a load.  */
-	  tree tmp = create_tmp_var (TREE_TYPE (*expr_p), "vol");
-	  *expr_p = build (MODIFY_EXPR, TREE_TYPE (tmp), tmp, *expr_p);
+	  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
Index: tree-ssa.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa.c,v
retrieving revision 2.105
diff -u -p -d -r2.105 tree-ssa.c
--- tree-ssa.c	13 Jul 2005 22:35:27 -0000	2.105
+++ tree-ssa.c	17 Jul 2005 16:34:47 -0000
@@ -890,6 +890,15 @@ tree_ssa_useless_type_conversion_1 (tree
   if (lang_hooks.types_compatible_p (inner_type, outer_type))
     return true;
 
+  /* Don't lose casts between pointers to volatile and non-volatile
+     qualified types.  Doing so would result in changing the semantics
+     of later accesses.  */
+  else if (POINTER_TYPE_P (inner_type)
+           && POINTER_TYPE_P (outer_type)
+	   && TYPE_VOLATILE (TREE_TYPE (outer_type))
+	      != TYPE_VOLATILE (TREE_TYPE (inner_type)))
+    return false;
+
   /* If both types are pointers and the outer type is a (void *), then
      the conversion is not necessary.  The opposite is not true since
      that conversion would result in a loss of information if the


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