From 09efeca1a40c3bccdd200ca1bcba4199d89f6422 Mon Sep 17 00:00:00 2001
From: Paolo Bonzini <bonzini@gnu.org>
Date: Tue, 20 Jan 2009 13:24:25 +0000
Subject: [PATCH] re PR target/38868 (r143152 breaks output routines in
 xplor-nih)

gcc:
2008-01-20  Paolo Bonzini  <bonzini@gnu.org>

	PR target/38868
	* emit-rtl.c (adjust_address_1): Make sure memref is never
	overwritten.

gcc/testsuite:
2008-01-20  Paolo Bonzini  <bonzini@gnu.org>

	PR target/38868
	* gfortran.dg/pr38868.f: New testcase.

From-SVN: r143513
---
 gcc/ChangeLog                       |  6 ++++++
 gcc/emit-rtl.c                      |  7 ++++++-
 gcc/testsuite/ChangeLog             |  5 +++++
 gcc/testsuite/gfortran.dg/pr38868.f | 17 +++++++++++++++++
 4 files changed, 34 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gfortran.dg/pr38868.f

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 574e254fbb9d..20215dcfad0e 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2008-01-20  Paolo Bonzini  <bonzini@gnu.org>
+
+	PR target/38868
+	* emit-rtl.c (adjust_address_1): Make sure memref is never
+	overwritten.
+
 2009-01-20  Ben Elliston  <bje@au.ibm.com>
 
 	* libgcov.c (__gcov_execl, __gcov_execlp, __gcov_execle): Remove
diff --git a/gcc/emit-rtl.c b/gcc/emit-rtl.c
index 830ce1dc9105..679e95ea8a24 100644
--- a/gcc/emit-rtl.c
+++ b/gcc/emit-rtl.c
@@ -1,6 +1,6 @@
 /* Emit RTL for the GCC expander.
    Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
+   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
    Free Software Foundation, Inc.
 
 This file is part of GCC.
@@ -2035,6 +2035,11 @@ adjust_address_1 (rtx memref, enum machine_mode mode, HOST_WIDE_INT offset,
 
   new_rtx = change_address_1 (memref, mode, addr, validate);
 
+  /* If the address is a REG, change_address_1 rightfully returns memref,
+     but this would destroy memref's MEM_ATTRS.  */
+  if (new_rtx == memref && offset != 0)
+    new_rtx = copy_rtx (new_rtx);
+
   /* Compute the new values of the memory attributes due to this adjustment.
      We add the offsets and update the alignment.  */
   if (memoffset)
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 30bf7ac79c91..8273b9938d79 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2008-01-20  Paolo Bonzini  <bonzini@gnu.org>
+
+	PR target/38868
+	* gfortran.dg/pr38868.f: New testcase.
+
 2009-01-20  Richard Guenther  <rguenther@suse.de>
 
 	* gcc.c-torture/execute/pr36227.c: Move ...
diff --git a/gcc/testsuite/gfortran.dg/pr38868.f b/gcc/testsuite/gfortran.dg/pr38868.f
new file mode 100644
index 000000000000..6acd52b186cd
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr38868.f
@@ -0,0 +1,17 @@
+! { dg-do compile }
+! { dg-options "-O2 -fdump-rtl-expand" }
+      PROGRAM testcase
+      IMPLICIT NONE
+
+      CHARACTER*4 ANER(18)
+      CHARACTER*80 LINE
+      aner = ''
+      ANER(1)='A   '
+      ANER(2)='    '
+      LINE=' '
+      LINE(78:80)='xyz'
+      WRITE(*,'(A82)') "'"//LINE//"'"
+      END
+
+! { dg-final { scan-rtl-dump-times "line\\\+80" 0 "expand" } }
+! { dg-final { cleanup-rtl-dump "expand" } } */
-- 
GitLab