# DIY Linux Patch
Date: 2005-08-26
Author: Refer Origin
Origin: http://gcc.gnu.org/ml/gcc-cvs/2005-07/msg00712.html
Maker: Greg Schafer <gschafer@zip.com.au>
Upstream Status: Applied. Refer Origin
Description: Fix the Xorg "libvgahw.a" issue.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22278
https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=161242

diff -Naur gcc-4.0.1.orig/gcc/gimplify.c gcc-4.0.1/gcc/gimplify.c
--- gcc-4.0.1.orig/gcc/gimplify.c	2005-06-14 17:07:52.000000000 +0000
+++ gcc-4.0.1/gcc/gimplify.c	2005-08-26 11:40:11.000000000 +0000
@@ -4246,8 +4246,9 @@
 	{
 	  /* 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
diff -Naur gcc-4.0.1.orig/gcc/tree-ssa.c gcc-4.0.1/gcc/tree-ssa.c
--- gcc-4.0.1.orig/gcc/tree-ssa.c	2005-06-06 19:20:35.000000000 +0000
+++ gcc-4.0.1/gcc/tree-ssa.c	2005-08-26 11:40:24.000000000 +0000
@@ -804,6 +804,15 @@
 	   && TREE_CODE (TREE_TYPE (outer_type)) == VOID_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;
+
   /* Pointers and references are equivalent once we get to GENERIC,
      so strip conversions that just switch between them.  */
   else if (POINTER_TYPE_P (inner_type)

