Re: PATCH to add -std=c++14

2014-03-09 Thread Ulrich Drepper
On Sat, Mar 8, 2014 at 8:30 PM, Mike Stump  wrote:
> Are they any plans to change the default language for C++?

Probably problematic for compatibility reasons.  But how about adding
c++1, g++11, and c++14, and g++14 wrappers similar to c99?


patch fortran, pr 59746, internal compiler error : segmentation fault

2014-03-09 Thread jimmie.davis


The code would only remove a variable from a common block if it was just 
defined in the previous statement. The PR showed a case where a pre-existing 
variable was put in the common block.  When it was not removed, the common 
block list was wrong and segfaulted (or infinite looped) when used later on.

I changed it so it would remove a variable from a common block if it was just 
defined, or if it previously existed and was put in the common block in the 
last statement.

This patch works with the example given in the PR and has no regressions in the 
testsuite.

tested i686/linux.


--bud davis

2013-03-06  Bud Davis 

PR fortran/59746
* symbol.c (gfc_restore_last_undo_checkpoint): Delete a common block
symbol if it was put in the list.

 
 Index: gcc/gcc/testsuite/gfortran.dg/pr59746.f90
===
--- gcc/gcc/testsuite/gfortran.dg/pr59746.f90   (revision 0)
+++ gcc/gcc/testsuite/gfortran.dg/pr59746.f90   (revision 0)
@@ -0,0 +1,18 @@
+! { dg-do compile }
+!pr59746
+  CALL RCCFL(NVE,IR,NU3,VE(1,1,1,I))
+  COMMON /CCFILE/ INTG,NT1,NT2,NT3,NVM,NVE,NFRLE,NRESF,NRESL !{ dg-error 
"Unexpected COMMON" }
+  COMMON /CCFILE/ INTG,NT1,NT2,NT3,NVM,NVE,NFRLE,NRESF,NRESL !{ dg-error 
"Unexpected COMMON" }
+!  the PR only contained the two above.
+!  success is no segfaults or infinite loops.  
+!  let's check some combinations
+ CALL ABC (INTG)
+ COMMON /CCFILE/ INTG,NT1,NT2,NT3,NVM,NVE,NFRLE,NRESF,NRESL !{ dg-error 
"Unexpected COMMON" }
+ COMMON /CCFILE/ INTG,NT1,NT2,NT3,NVM,NVE,NFRLE,NRESF,NRESL !{ dg-error 
"Unexpected COMMON" }
+ CALL DEF (NT1)
+ COMMON /CCFILE/ INTG,NT1,NT2,NT3,NVM,NVE,NFRLE,NRESF,NRESL !{ dg-error 
"Unexpected COMMON" }
+ COMMON /CCFILE/ INTG,NT1,NT2,NT3,NVM,NVE,NFRLE,NRESF,NRESL !{ dg-error 
"Unexpected COMMON" }
+ CALL GHI (NRESL)
+ COMMON /CCFILE/ INTG,NT1,NT2,NT3,NVM,NVE,NFRLE,NRESF,NRESL !{ dg-error 
"Unexpected COMMON" }
+ COMMON /CCFILE/ INTG,NT1,NT2,NT3,NVM,NVE,NFRLE,NRESF,NRESL !{ dg-error 
"Unexpected COMMON" }
+ END
Index: gcc/gcc/fortran/symbol.c
===
--- gcc/gcc/fortran/symbol.c(revision 208437)
+++ gcc/gcc/fortran/symbol.c(working copy)
@@ -3069,9 +3069,9 @@
 
   FOR_EACH_VEC_ELT (latest_undo_chgset->syms, i, p)
 {
-  if (p->gfc_new)
+  if (p->gfc_new || (p->attr.in_common && !p->old_symbol->attr.in_common) )
{
- /* Symbol was new.  */
+ /* Symbol was new. Or was old and just put in common */
  if (p->attr.in_common && p->common_block && p->common_block->head)
{
  /* If the symbol was added to any common block, it
@@ -3115,6 +3115,9 @@
  /* The derived type is saved in the symtree with the first
 letter capitalized; the all lower-case version to the
 derived type contains its associated generic function.  */
+ }
+ if (p->gfc_new) 
+ {
  if (p->attr.flavor == FL_DERIVED)
gfc_delete_symtree (&p->ns->sym_root, gfc_get_string ("%c%s",
 (char) TOUPPER ((unsigned char) p->name[0]),
@@ -3125,7 +3128,9 @@
  gfc_release_symbol (p);
}
   else
-   restore_old_symbol (p);
+{
+ restore_old_symbol (p);
+}
 }
 
   latest_undo_chgset->syms.truncate (0);







Re: [PATCH, libgcc]: Avoid warning: array subscript is above array bounds when compiling crtstuff.c

2014-03-09 Thread Uros Bizjak
On Fri, Mar 7, 2014 at 8:03 PM, Ian Lance Taylor  wrote:

>> Attached patch avoids a bunch of:
>>
>> ../../../gcc-svn/trunk/libgcc/crtstuff.c: In function 'frame_dummy':
>> ../../../gcc-svn/trunk/libgcc/crtstuff.c:463:19: warning: array
>> subscript is above array bounds [-Warray-bounds]
>>if (__JCR_LIST__[0])
>>^
>>
>> when compiling libgcc.
>>
>> 2014-03-08  Uros Bizjak  
>>
>> * crtstuff.c (__JCR_LIST__): Declare as zero-length array.
>>
>
> I don't understand why this works.  You can't index element 0 of a 0
> element array.
>
> This code is relying on linker magic and it's not surprising that it
> confuses the compiler.  Can you use a type cast or variable assignment
> in frame_dummy instead?

I was not able to cast variable with any sensible type cast (maybe I
didn't understand your suggestion correctly), the only other variant
that avoided warning was

--cut here--
Index: crtstuff.c
===
--- crtstuff.c  (revision 208403)
+++ crtstuff.c  (working copy)
@@ -259,7 +259,7 @@
so we can register them properly.  */
 STATIC void *__JCR_LIST__[]
   __attribute__ ((used, section(JCR_SECTION_NAME), aligned(sizeof(void*
-  = { };
+  = { 0 };
 #endif /* JCR_SECTION_NAME */

 #if USE_TM_CLONE_REGISTRY
--cut here--

but I don't know if this is correct approach, concerning mentioned linker magic.

I have opened PR 60472 [1] with a reduced testcase, if somebody wants
to deal with this problem...

[1] http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60472

Uros.


New Swedish PO file for 'gcc' (version 4.9-b20140202)

2014-03-09 Thread Translation Project Robot
Hello, gentle maintainer.

This is a message from the Translation Project robot.

A revised PO file for textual domain 'gcc' has been submitted
by the Swedish team of translators.  The file is available at:

http://translationproject.org/latest/gcc/sv.po

(This file, 'gcc-4.9-b20140202.sv.po', has just now been sent to you in
a separate email.)

All other PO files for your package are available in:

http://translationproject.org/latest/gcc/

Please consider including all of these in your next release, whether
official or a pretest.

Whenever you have a new distribution with a new version number ready,
containing a newer POT file, please send the URL of that distribution
tarball to the address below.  The tarball may be just a pretest or a
snapshot, it does not even have to compile.  It is just used by the
translators when they need some extra translation context.

The following HTML page has been updated:

http://translationproject.org/domain/gcc.html

If any question arises, please contact the translation coordinator.

Thank you for all your work,

The Translation Project robot, in the
name of your translation coordinator.




[Patch, fortran] PR 60392 wrong descriptor when passing a transposed array to a contiguous assumed shape dummy.

2014-03-09 Thread Mikael Morin
Hello,

here is a fix for a wrong code issue, where we pass a descriptor with
broken bounds when the actual argument is a transposed array and the
dummy an assumed shape dummy.
The bug comes from the interaction of the transpose optimization,
which creates a descriptor with transposed bounds without copying the
data, and the contiguous optimization, which reuses the descriptor for
passing as argument after the call to internal_pack.
The attached patch makes a copy of the descriptor with the correct
bounds when a transposed scalarization is detected.

Regression-tested on x86_64-unknown-linux-gnu.
This is not a regression as far as I know, but quite a severe
wrong-code, albeit limited to the corner case of transpose and
assumed shape and contiguous.  OK for trunk/4.8/4.7 anyway ?


Mikael

PS: To not reproduce the same mistake as in the PR regarding the memory
representation of matrices, I have filled the matrices one element at a
time in the testcase.



2014-03-09  Mikael Morin  

	PR fortran/60392
	* trans-array.c (gfc_conv_array_parameter): Don't reuse the descriptor
	if it has transposed dimensions.

2014-03-09  Mikael Morin  

	PR fortran/60392
	* gfortran.dg/transpose_4.f90: New test.

Index: trans-array.c
===
--- trans-array.c	(révision 208442)
+++ trans-array.c	(copie de travail)
@@ -7227,7 +7227,50 @@ gfc_conv_array_parameter (gfc_se * se, gfc_expr *
   else
 	{
 	  tmp = build_fold_indirect_ref_loc (input_location, desc);
-	  gfc_conv_descriptor_data_set (&se->pre, tmp, ptr);
+
+	  gfc_ss * ss = gfc_walk_expr (expr);
+	  if (!transposed_dims (ss))
+	gfc_conv_descriptor_data_set (&se->pre, tmp, ptr);
+	  else
+	{
+	  tree old_field, new_field;
+
+	  /* The original descriptor has transposed dims so we can't reuse
+		 it directly; we have to create a new one.  */
+	  tree old_desc = tmp;
+	  tree new_desc = gfc_create_var (TREE_TYPE (old_desc), "arg_desc");
+
+	  old_field = gfc_conv_descriptor_dtype (old_desc);
+	  new_field = gfc_conv_descriptor_dtype (new_desc);
+	  gfc_add_modify (&se->pre, new_field, old_field);
+
+	  old_field = gfc_conv_descriptor_offset (old_desc);
+	  new_field = gfc_conv_descriptor_offset (new_desc);
+	  gfc_add_modify (&se->pre, new_field, old_field);
+
+	  for (int i = 0; i < expr->rank; i++)
+		{
+		  old_field = gfc_conv_descriptor_dimension (old_desc,
+			gfc_rank_cst[get_array_ref_dim_for_loop_dim (ss, i)]);
+		  new_field = gfc_conv_descriptor_dimension (new_desc,
+			gfc_rank_cst[i]);
+		  gfc_add_modify (&se->pre, new_field, old_field);
+		}
+
+	  if (gfc_option.coarray == GFC_FCOARRAY_LIB
+		  && GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (old_desc))
+		  && GFC_TYPE_ARRAY_AKIND (TREE_TYPE (old_desc))
+		 == GFC_ARRAY_ALLOCATABLE)
+		{
+		  old_field = gfc_conv_descriptor_token (old_desc);
+		  new_field = gfc_conv_descriptor_token (new_desc);
+		  gfc_add_modify (&se->pre, new_field, old_field);
+		}
+
+	  gfc_conv_descriptor_data_set (&se->pre, new_desc, ptr);
+	  se->expr = gfc_build_addr_expr (NULL_TREE, new_desc);
+	}
+	  gfc_free_ss (ss);
 	}
 
   if (gfc_option.rtcheck & GFC_RTCHECK_ARRAY_TEMPS)



! { dg-do run }
!
! PR fortran/60392
! In the transposed case call to my_mul_cont, the compiler used to (wrongly)
! reuse a transposed descriptor for an array that was not transposed as a result
! of packing.
!
! Original test case from Alexander Vogt .

program test
  implicit none

  integer, dimension(2,2) :: A, R, RT
  integer, dimension(2,2) :: B1, B2

  ! 
  ! A = [  2   17 ]
  ! [ 82  257 ]
  !
  ! matmul(a,a) = [  1398   4403 ]
  !   [ 21238  67443 ]
  !
  ! matmul(transpose(a), a) = [  6728  21108 ]
  !   [ 21108  66338 ]
  A(1,1) =   2
  A(1,2) =  17
  A(2,1) =  82
  A(2,2) = 257

  R(1,1) =  1398
  R(1,2) =  4403
  R(2,1) = 21238
  R(2,2) = 67443
  
  RT(1,1) =  6728
  RT(1,2) = 21108
  RT(2,1) = 21108
  RT(2,2) = 66338

  ! Normal argument
  B1 = 0
  B2 = 0
  B1 = my_mul(A,A)
  B2 = my_mul_cont(A,A)
! print *,'Normal:',maxval(abs(B1-B2))
! print *,B1
! print *,B2
  if (any(B1 /= R)) call abort
  if (any(B2 /= R)) call abort

  ! Transposed argument
  B1 = 0
  B2 = 0
  B1 = my_mul(transpose(A),A)
  B2 = my_mul_cont(transpose(A),A)
! print *,'Transposed:',maxval(abs(B1-B2))
! print *,B1
! print *,B2
  if (any(B1 /= RT)) call abort
  if (any(B2 /= RT)) call abort

contains

  function my_mul(A,C) result (B)
use, intrinsic :: ISO_Fortran_env
integer, intent(in) :: A(2,2), C(2,2)
integer :: B(2,2)
B = matmul(A, C)
  end function

  function my_mul_cont(A,C) result (B)
use, intrinsic :: ISO_Fortran_env
integer, intent(in), contiguous :: A(:,:), C(:,:)
integer :: B(2,2)
B = matmul(A, C)
  end function

end program





Re: Backports to 4.8 branch

2014-03-09 Thread Jakub Jelinek
On Sat, Mar 08, 2014 at 11:08:14PM +0100, Gerald Pfeifer wrote:
> On Thu, 6 Mar 2014, Jakub Jelinek wrote:
> > I've backported a few bugfixes to 4.8 branch, bootstrapped/regtested 
> > on x86_64-linux and i686-linux, committed to branch.
> 
> This reminds my:  what are your plans doing new release off that 
> branch?  The last one has been five months ago.  What is the rough
> interval between releases you have in mind?

Last year we did 4.n-1 and 4.n-2 releases a short time after the 4.n
release, given the focus on making 4.9 stable now I'd say we should do the
same thing this year as well.

> And how about GCC 4.7.4?  Any plans for that and closing the branch
> afterwards?  Or do you plan to keep 4.7 alive for longer?

Jakub


Re: [PATCH, libgcc]: Avoid warning: array subscript is above array bounds when compiling crtstuff.c

2014-03-09 Thread Ian Lance Taylor
On Sun, Mar 9, 2014 at 6:57 AM, Uros Bizjak  wrote:
> On Fri, Mar 7, 2014 at 8:03 PM, Ian Lance Taylor  wrote:
>
>>> Attached patch avoids a bunch of:
>>>
>>> ../../../gcc-svn/trunk/libgcc/crtstuff.c: In function 'frame_dummy':
>>> ../../../gcc-svn/trunk/libgcc/crtstuff.c:463:19: warning: array
>>> subscript is above array bounds [-Warray-bounds]
>>>if (__JCR_LIST__[0])
>>>^
>>>
>>> when compiling libgcc.
>>>
>>> 2014-03-08  Uros Bizjak  
>>>
>>> * crtstuff.c (__JCR_LIST__): Declare as zero-length array.
>>>
>>
>> I don't understand why this works.  You can't index element 0 of a 0
>> element array.
>>
>> This code is relying on linker magic and it's not surprising that it
>> confuses the compiler.  Can you use a type cast or variable assignment
>> in frame_dummy instead?
>
> I was not able to cast variable with any sensible type cast (maybe I
> didn't understand your suggestion correctly), the only other variant
> that avoided warning was
>
> --cut here--
> Index: crtstuff.c
> ===
> --- crtstuff.c  (revision 208403)
> +++ crtstuff.c  (working copy)
> @@ -259,7 +259,7 @@
> so we can register them properly.  */
>  STATIC void *__JCR_LIST__[]
>__attribute__ ((used, section(JCR_SECTION_NAME), aligned(sizeof(void*
> -  = { };
> +  = { 0 };
>  #endif /* JCR_SECTION_NAME */
>
>  #if USE_TM_CLONE_REGISTRY
> --cut here--
>
> but I don't know if this is correct approach, concerning mentioned linker 
> magic.

As you guess, that likely won't work, because it will introduce a NULL
pointer into the array.

Ian


Re: patch fortran, pr 59746, internal compiler error : segmentation fault

2014-03-09 Thread Mikael Morin
Hello,

Le 09/03/2014 13:59, jimmie.da...@l-3com.com a écrit :
> 
> 
> The code would only remove a variable from a common block if it was just 
> defined in the previous statement. The PR showed a case where a pre-existing 
> variable was put in the common block.  When it was not removed, the common 
> block list was wrong and segfaulted (or infinite looped) when used later on.
> 
> I changed it so it would remove a variable from a common block if it was just 
> defined, or if it previously existed and was put in the common block in the 
> last statement.
> 
> This patch works with the example given in the PR and has no regressions in 
> the testsuite.
> 
> tested i686/linux.
> 
> 
> --bud davis
> 
[...]
> Index: gcc/gcc/fortran/symbol.c
> ===
> --- gcc/gcc/fortran/symbol.c  (revision 208437)
> +++ gcc/gcc/fortran/symbol.c  (working copy)
> @@ -3069,9 +3069,9 @@
>  
>FOR_EACH_VEC_ELT (latest_undo_chgset->syms, i, p)
>  {
> -  if (p->gfc_new)
> +  if (p->gfc_new || (p->attr.in_common && 
> !p->old_symbol->attr.in_common) )
>   {
> -   /* Symbol was new.  */
> +   /* Symbol was new. Or was old and just put in common */
> if (p->attr.in_common && p->common_block && p->common_block->head)
Please merge the two ifs; it seems they have exactly the same scope
after the patch.

>   {
> /* If the symbol was added to any common block, it
> @@ -3115,6 +3115,9 @@
> /* The derived type is saved in the symtree with the first
>letter capitalized; the all lower-case version to the
>derived type contains its associated generic function.  */
This comment applies to the TOUPPER thing below...

> + }
> + if (p->gfc_new) 
> + {
... so it should be put here. Also the indentation is wrong.

> if (p->attr.flavor == FL_DERIVED)
>   gfc_delete_symtree (&p->ns->sym_root, gfc_get_string ("%c%s",
>  (char) TOUPPER ((unsigned char) p->name[0]),
> @@ -3125,7 +3128,9 @@
> gfc_release_symbol (p);
>   }
>else
> - restore_old_symbol (p);
> +{
> +   restore_old_symbol (p);
> +}
>  }
This is unnecessary.

Otherwise looks goodish.  This is not a regression, but I suppose it
will be acceptable.

Mikael


Re: [PATCH, libgcc]: Avoid warning: array subscript is above array bounds when compiling crtstuff.c

2014-03-09 Thread Jakub Jelinek
On Sun, Mar 09, 2014 at 09:41:59AM -0700, Ian Lance Taylor wrote:
> >>> Attached patch avoids a bunch of:
> >>>
> >>> ../../../gcc-svn/trunk/libgcc/crtstuff.c: In function 'frame_dummy':
> >>> ../../../gcc-svn/trunk/libgcc/crtstuff.c:463:19: warning: array
> >>> subscript is above array bounds [-Warray-bounds]
> >>>if (__JCR_LIST__[0])
> >>>^
> >>>
> >>> when compiling libgcc.
> >>>
> >>> 2014-03-08  Uros Bizjak  
> >>>
> >>> * crtstuff.c (__JCR_LIST__): Declare as zero-length array.

I guess the only thing to avoid the warning (and potential miscompilation)
is to hide the access from the optimizers through something like:
  void *jcr_list;
  __asm ("" : "=g" (jcr_list) : "0" (__JCR_LIST__));
and then use jcr_list instead of __JCR_LIST__.

Jakub


[libstdc++-v3] PATCH, RFC: implement is_trivially_default_constructible

2014-03-09 Thread Ville Voutilainen
This is my first shot at library patches. Do tell me if there's
anything massively
wrong. Tested on x86_64-linux.


2014-03-09  Ville Voutilainen  

Implement is_trivially_default_constructible.
* doc/xml/manual/status_cxx2011.xml: Remove mention of is_trivially_default_cons
tructible not being implemented
* include/std/type_traits (is_trivially_default_constructible): New.
* testsuite/20_util/is_trivially_default_constructible/value.cc: New.
diff --git a/libstdc++-v3/doc/xml/manual/status_cxx2011.xml 
b/libstdc++-v3/doc/xml/manual/status_cxx2011.xml
index b3c24d8..aaa4887 100644
--- a/libstdc++-v3/doc/xml/manual/status_cxx2011.xml
+++ b/libstdc++-v3/doc/xml/manual/status_cxx2011.xml
@@ -816,7 +816,7 @@ particular release.
   Type properties
   Partial
   Missing is_trivially_copyable,
-  is_trivially_constructible, is_trivially_default_constructible,
+  is_trivially_constructible,
   is_trivially_copy_constructible, is_trivially_move_constructible,
   is_trivially_assignable, is_trivially_default_assignable,
   is_trivially_copy_assignable, is_trivially_move_assignable
diff --git a/libstdc++-v3/include/std/type_traits 
b/libstdc++-v3/include/std/type_traits
index 4b434a6..b529ee6 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -1258,7 +1258,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   /// is_trivially_constructible (still unimplemented)
   
-  /// is_trivially_default_constructible (still unimplemented)
+  /// is_trivially_default_constructible
+  template
+struct is_trivially_default_constructible
+: public __and_, integral_constant>::type
+{ };
 
   /// is_trivially_copy_constructible (still unimplemented)
 
diff --git 
a/libstdc++-v3/testsuite/20_util/is_trivially_default_constructible/value.cc 
b/libstdc++-v3/testsuite/20_util/is_trivially_default_constructible/value.cc
new file mode 100644
index 000..4d10275
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/is_trivially_default_constructible/value.cc
@@ -0,0 +1,47 @@
+// { dg-options "-std=gnu++11" }
+// { dg-do compile }
+//
+// 2014-03-09  Ville Voutilainen  
+//
+// Copyright (C) 2014 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// .
+
+#include 
+#include 
+
+void test01()
+{
+  using std::is_trivially_default_constructible;
+  using namespace __gnu_test;
+
+  static_assert(test_category(true), 
"");
+  static_assert(test_category(true), "");
+  static_assert(test_category(true), "");
+
+  static_assert(test_category(false), "");
+  static_assert(test_category(true), "");
+  static_assert(test_category(true), "");
+  static_assert(test_category(false), "");
+  static_assert(test_category(false), "");
+  static_assert(test_category(false), "");
+  static_assert(test_category(false), "");
+  static_assert(test_category(false), "");
+  static_assert(test_category(false), "");
+  static_assert(test_category(false), "");
+  static_assert(test_category(false), "");
+
+}


RE: patch fortran, pr 59746, internal compiler error : segmentation fault

2014-03-09 Thread jimmie.davis
Comments from Mikael:
 
#1.  Please merge the two ifs; it seems they have exactly the same scope
after the patch.
 
#2.  This comment applies to the TOUPPER thing below...
 .. so it should be put here. Also the indentation is wrong.
 
#3.This is unnecessary.
 
===

All corrected in the patch below.  
This patch is not very important.   If we are in 'regressions fix only' mode, 
then this needs to sit until stage 1 happensIt is not worth any kind of 
breakage.

Reran the testsuite.  No new failures.


regards,
Bud Davis


Index: gcc/gcc/fortran/symbol.c
===
--- gcc/gcc/fortran/symbol.c(revision 208437)
+++ gcc/gcc/fortran/symbol.c(working copy)
@@ -3069,65 +3069,65 @@
 
   FOR_EACH_VEC_ELT (latest_undo_chgset->syms, i, p)
 {
-  if (p->gfc_new)
-   {
- /* Symbol was new.  */
- if (p->attr.in_common && p->common_block && p->common_block->head)
-   {
- /* If the symbol was added to any common block, it
-needs to be removed to stop the resolver looking
-for a (possibly) dead symbol.  */
+  /* Symbol was new. Or was old and just put in common */
+  if ((p->gfc_new || 
+  (p->attr.in_common && !p->old_symbol->attr.in_common )) && 
+   p->attr.in_common && p->common_block && p->common_block->head)
+{
+  /* If the symbol was added to any common block, it
+ needs to be removed to stop the resolver looking
+ for a (possibly) dead symbol.  */
 
- if (p->common_block->head == p && !p->common_next)
-   {
- gfc_symtree st, *st0;
- st0 = find_common_symtree (p->ns->common_root,
-p->common_block);
- if (st0)
-   {
- st.name = st0->name;
- gfc_delete_bbt (&p->ns->common_root, &st, 
compare_symtree);
- free (st0);
-   }
-   }
+  if (p->common_block->head == p && !p->common_next)
+{
+  gfc_symtree st, *st0;
+  st0 = find_common_symtree (p->ns->common_root,
+ p->common_block);
+  if (st0)
+{
+  st.name = st0->name;
+ gfc_delete_bbt (&p->ns->common_root, &st, compare_symtree);
+ free (st0);
+}
+}
 
- if (p->common_block->head == p)
-   p->common_block->head = p->common_next;
- else
-   {
- gfc_symbol *cparent, *csym;
+   if (p->common_block->head == p)
+ p->common_block->head = p->common_next;
+   else
+  {
+gfc_symbol *cparent, *csym;
 
- cparent = p->common_block->head;
- csym = cparent->common_next;
+cparent = p->common_block->head;
+csym = cparent->common_next;
 
- while (csym != p)
-   {
- cparent = csym;
- csym = csym->common_next;
-   }
+while (csym != p)
+  {
+cparent = csym;
+csym = csym->common_next;
+  }
 
- gcc_assert(cparent->common_next == p);
+  gcc_assert(cparent->common_next == p);
+  cparent->common_next = csym->common_next;
+  }
+}
+if (p->gfc_new) 
+  {
+/* The derived type is saved in the symtree with the first
+   letter capitalized; the all lower-case version to the
+   derived type contains its associated generic function.  */
 
- cparent->common_next = csym->common_next;
-   }
-   }
+if (p->attr.flavor == FL_DERIVED)
+  gfc_delete_symtree (&p->ns->sym_root, gfc_get_string ("%c%s",
+  (char) TOUPPER ((unsigned char) p->name[0]),
+  &p->name[1]));
+else
+ gfc_delete_symtree (&p->ns->sym_root, p->name);
 
- /* The derived type is saved in the symtree with the first
-letter capitalized; the all lower-case version to the
-derived type contains its associated generic function.  */
- if (p->attr.flavor == FL_DERIVED)
-   gfc_delete_symtree (&p->ns->sym_root, gfc_get_string ("%c%s",
-(char) TOUPPER ((unsigned char) p->name[0]),
-&p->name[1]));
- else
-   gfc_delete_symtree (&p->ns->sym_root, p->name);
-
- gfc_release_symbol (p);
-   }
-  else
-   restore_old_symbol (p);
+   gfc_release_symbol (p);
+ }
+

RE: [PATCH] Add a new option "-ftree-bitfield-merge" (patch / doc inside)

2014-03-09 Thread Zoran Jovanovic
Hello,
This is new patch version. 
Approach suggested by Richard Biener with lowering bit-field accesses instead 
of modifying gimple trees is implemented.
Although, algorithm still detects adjacent bit field accesses, which copy 
values from one to another bit-field of same type.
If those accesses are detected field size used during lowering is equal to sum 
of sizes of all adjacent fields that can be merged. 
Idea is to let dse and cse to remove unnecessary instructions afterwards.
I wanted to preserve this behavior because it was one of original goals of this 
work.


Example:

Original code:
  :
  _2 = pr1.f1;
  pr2.f1 = _2;
  _4 = pr1.f2;
  pr2.f2 = _4;
  _6 = pr1.f3;
  pr2.f3 = _6;
  return;


Optimized code:
  :
  _8 = pr1.D.1364;
  _9 = BIT_FIELD_REF <_8, 13, 0>;
  _10 = pr2.D.1364;
  _11 = _10 & 4294959104;
  _12 = (unsigned int) _9;
  _13 = _11 | _12;
  pr2.D.1364 = _13;
  _14 = pr1.D.1364;
  _15 = BIT_FIELD_REF <_14, 13, 0>;
  _16 = pr2.D.1364;
  _17 = _16 & 4294959104;
  _18 = (unsigned int) _15;
  _19 = _17 | _18;
  pr2.D.1364 = _19;
  _20 = pr1.D.1364;
  _21 = BIT_FIELD_REF <_20, 13, 0>;
  _22 = pr2.D.1364;
  _23 = _22 & 4294959104;
  _24 = (unsigned int) _21;
  _25 = _23 | _24;
  pr2.D.1364 = _25;
  return;
  

Algorithm works on basic block level and consists of following 3 major steps:
1. Go through basic block statements list. If there are statement pairs that 
implement copy of bit field content from one memory location to another record 
statements pointers and other necessary data in corresponding data structure.
2. Identify records that represent adjacent bit field accesses and mark them as 
merged.
3. Lower bit-field accesses by using new field size for those that can be 
merged.


New command line option "-fmerge-bitfields" is introduced.

Tested - passed gcc regression tests.

Changelog -

gcc/ChangeLog:
2014-03-09 Zoran Jovanovic (zoran.jovano...@imgtec.com)
  * common.opt (fmerge-bitfields): New option.
  * doc/invoke.texi: Added reference to "-fmerge-bitfields".
  * tree-sra.c (lower_bitfields): New function.
  Entry for (-fmerge-bitfields).
  (bfaccess::hash): New function.
  (bfaccess::equal): New function.
  (bfaccess::remove): New function.
  (bitfield_access_p): New function.
  (lower_bitfield_read): New function.
  (lower_bitfield_write): New function.
  (bitfield_stmt_access_pair_htab_hash): New function.
  (bitfield_stmt_access_pair_htab_eq): New function.
  (create_and_insert_access): New function.
  (get_bit_offset): New function.
  (get_merged_bit_field_size): New function.
  (add_stmt_access_pair): New function.
  (cmp_access): New function.
  * dwarf2out.c (simple_type_size_in_bits): moved to tree.c.
  (field_byte_offset): declaration moved to tree.h, static removed.
  * testsuite/gcc.dg/tree-ssa/bitfldmrg1.c: New test.
  * testsuite/gcc.dg/tree-ssa/bitfldmrg2.c: New test.
  * tree-ssa-sccvn.c (expressions_equal_p): moved to tree.c.
  * tree-ssa-sccvn.h (expressions_equal_p): declaration moved to tree.h.
  * tree.c (expressions_equal_p): moved from tree-ssa-sccvn.c.
  (simple_type_size_in_bits): moved from dwarf2out.c.
  * tree.h (expressions_equal_p): declaration added.
  (field_byte_offset): declaration added.

Patch -

diff --git a/gcc/common.opt b/gcc/common.opt
index 661516d..3331d03 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -2193,6 +2193,10 @@ ftree-sra
 Common Report Var(flag_tree_sra) Optimization
 Perform scalar replacement of aggregates
 
+fmerge-bitfields
+Common Report Var(flag_tree_bitfield_merge) Init(0) Optimization
+Merge loads and stores of consecutive bitfields
+
 ftree-ter
 Common Report Var(flag_tree_ter) Optimization
 Replace temporary expressions in the SSA->normal pass
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 24bd76e..54bae56 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -411,7 +411,7 @@ Objective-C and Objective-C++ Dialects}.
 -fsplit-ivs-in-unroller -fsplit-wide-types -fstack-protector @gol
 -fstack-protector-all -fstack-protector-strong -fstrict-aliasing @gol
 -fstrict-overflow -fthread-jumps -ftracer -ftree-bit-ccp @gol
--ftree-builtin-call-dce -ftree-ccp -ftree-ch @gol
+-fmerge-bitfields -ftree-builtin-call-dce -ftree-ccp -ftree-ch @gol
 -ftree-coalesce-inline-vars -ftree-coalesce-vars -ftree-copy-prop @gol
 -ftree-copyrename -ftree-dce -ftree-dominator-opts -ftree-dse @gol
 -ftree-forwprop -ftree-fre -ftree-loop-if-convert @gol
@@ -7807,6 +7807,11 @@ pointer alignment information.
 This pass only operates on local scalar variables and is enabled by default
 at @option{-O} and higher.  It requires that @option{-ftree-ccp} is enabled.
 
+@item -fbitfield-merge
+@opindex fmerge-bitfields
+Combines several adjacent bit-field accesses that copy values
+from one memory location to another into one single bit-field access.
+
 @item -ftree-ccp
 @opindex ftree-ccp
 Perform sparse conditional constant propagation (CCP) on trees.  This
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 2b584a5..5150d

Re: patch fortran, pr 59746, internal compiler error : segmentation fault

2014-03-09 Thread Mikael Morin
Le 09/03/2014 20:47, jimmie.da...@l-3com.com a écrit :
> Comments from Mikael:
>  
> #1.  Please merge the two ifs; it seems they have exactly the same scope
> after the patch.
>  
> #2.  This comment applies to the TOUPPER thing below...
>  .. so it should be put here. Also the indentation is wrong.
>  
> #3.This is unnecessary.
>  
> ===
> 
> All corrected in the patch below.  
> This patch is not very important.   If we are in 'regressions fix only' mode, 
> then this needs to sit until stage 1 happensIt is not worth any kind of 
> breakage.
Alright, don't forget to ping the patch during next stage1 then.

Next review iteration:
> Index: gcc/gcc/fortran/symbol.c
> ===
> --- gcc/gcc/fortran/symbol.c  (revision 208437)
> +++ gcc/gcc/fortran/symbol.c  (working copy)
> @@ -3069,65 +3069,65 @@
>  
>FOR_EACH_VEC_ELT (latest_undo_chgset->syms, i, p)
>  {
> -  if (p->gfc_new)
> - {
> -   /* Symbol was new.  */
> -   if (p->attr.in_common && p->common_block && p->common_block->head)
> - {
> -   /* If the symbol was added to any common block, it
> -  needs to be removed to stop the resolver looking
> -  for a (possibly) dead symbol.  */
> +  /* Symbol was new. Or was old and just put in common */
> +  if ((p->gfc_new || 
> +  (p->attr.in_common && !p->old_symbol->attr.in_common )) && 
> +   p->attr.in_common && p->common_block && p->common_block->head)
write this instead:
if (p->attr.in_common && p->common_block && p->common_block->head
&& (p->gfc_new || !p->old_symbol->attr.in_common))

[p->attr.in_common is less likely than p->gfc_new which happens all the
time; we may as well short-circuit the latter.]


For the rest of the patch, there are indentation issues, any leading 8
spaces block should be replaced with a tab.
You can use "contrib/check_GNU_style.sh your_patch" to check common
style issues)

> +   )
> +{
> +  /* If the symbol was added to any common block, it
> + needs to be removed to stop the resolver looking
> + for a (possibly) dead symbol.  */
>  
> -   if (p->common_block->head == p && !p->common_next)
> - {
> -   gfc_symtree st, *st0;
> -   st0 = find_common_symtree (p->ns->common_root,
> -  p->common_block);
> -   if (st0)
> - {
> -   st.name = st0->name;
> -   gfc_delete_bbt (&p->ns->common_root, &st, 
> compare_symtree);
> -   free (st0);
> - }
> - }
> +  if (p->common_block->head == p && !p->common_next)
> +{
> +  gfc_symtree st, *st0;
> +  st0 = find_common_symtree (p->ns->common_root,
> + p->common_block);
> +  if (st0)
> +{
> +  st.name = st0->name;
> +   gfc_delete_bbt (&p->ns->common_root, &st, compare_symtree);
> +   free (st0);
> +}
> +}
>  
> -   if (p->common_block->head == p)
> - p->common_block->head = p->common_next;
> -   else
> - {
> -   gfc_symbol *cparent, *csym;


> + if (p->common_block->head == p)
I think the code block starting here is indented too much.

> +   p->common_block->head = p->common_next;
> + else
> +  {
> +gfc_symbol *cparent, *csym;
>  
> -   cparent = p->common_block->head;
> -   csym = cparent->common_next;
> +cparent = p->common_block->head;
> +csym = cparent->common_next;
>  
> -   while (csym != p)
> - {
> -   cparent = csym;
> -   csym = csym->common_next;
> - }
> +while (csym != p)
> +  {
> +cparent = csym;
> +csym = csym->common_next;
> +  }
>  
> -   gcc_assert(cparent->common_next == p);
> +  gcc_assert(cparent->common_next == p);
> +  cparent->common_next = csym->common_next;
> +  }
> +}


> +if (p->gfc_new) 
Same here, the code after this shouldn't need reindenting.

> +  {
> +/* The derived type is saved in the symtree with the first
> +   letter capitalized; the all lower-case version to the
> +   derived type contains its associated generic function.  */
>  
> -   cparent->common_next = csym->common_next;
> - }
> - }
> +if (p->attr.flavor == FL_DERIVED)
> +  gfc_delete_symtree (&p->ns->sym_root, gfc_get_string ("%c%s",
> +  (char) TOUPPER

Re: [PATCH, libgcc]: Avoid warning: array subscript is above array bounds when compiling crtstuff.c

2014-03-09 Thread Uros Bizjak
On Sun, Mar 9, 2014 at 6:31 PM, Jakub Jelinek  wrote:
> On Sun, Mar 09, 2014 at 09:41:59AM -0700, Ian Lance Taylor wrote:
>> >>> Attached patch avoids a bunch of:
>> >>>
>> >>> ../../../gcc-svn/trunk/libgcc/crtstuff.c: In function 'frame_dummy':
>> >>> ../../../gcc-svn/trunk/libgcc/crtstuff.c:463:19: warning: array
>> >>> subscript is above array bounds [-Warray-bounds]
>> >>>if (__JCR_LIST__[0])
>> >>>^
>> >>>
>> >>> when compiling libgcc.
>> >>>
>> >>> 2014-03-08  Uros Bizjak  
>> >>>
>> >>> * crtstuff.c (__JCR_LIST__): Declare as zero-length array.
>
> I guess the only thing to avoid the warning (and potential miscompilation)
> is to hide the access from the optimizers through something like:
>   void *jcr_list;
>   __asm ("" : "=g" (jcr_list) : "0" (__JCR_LIST__));
> and then use jcr_list instead of __JCR_LIST__.

Attached patch builds on your idea, but jcr_list temporary has to be
declared as void ** to allow proper dereference of pointer to void
array.

The resulting code is also a bit better, as shown by following test:

--cut here--
void register_classes (void *);

static void *__JCR_LIST__[]  __attribute__ ((used)) = { };

void frame_dummy (void)
{
  void **jcr_list;
  __asm ("" : "=g" (jcr_list) : "0" (__JCR_LIST__));
  if (*jcr_list)
register_classes (jcr_list);
}

void _frame_dummy (void)
{
  if (__JCR_LIST__[0])
register_classes (__JCR_LIST__);
}
--cut here--

gcc -O2 -Wall:

frame_dummy:
movl$__JCR_LIST__, %edi
cmpq$0, (%rdi)
je  .L1
jmp register_classes
.p2align 4,,10
.p2align 3
.L1:
rep ret

_frame_dummy:
cmpq$0, __JCR_LIST__(%rip)
je  .L4
movl$__JCR_LIST__, %edi
jmp register_classes
.p2align 4,,10
.p2align 3
.L4:
rep ret

The new code preloads __JCR_LIST__ into a temporary register that is
reused in the call to register_classes.

2014-03-09  Uros Bizjak  

* crtstuff.c (frame_dummy): Use void **jcr_list temporary variable to
avoid array subscript is above array bounds warnings.

Patch was bootstrapped and regression tested on x86_64-pc-linux-gnu
{,-m32} with all default languages + go.

OK for mainline?

Uros.
Index: crtstuff.c
===
--- crtstuff.c  (revision 208441)
+++ crtstuff.c  (working copy)
@@ -460,12 +460,14 @@ frame_dummy (void)
 #endif /* USE_EH_FRAME_REGISTRY */
 
 #ifdef JCR_SECTION_NAME
-  if (__JCR_LIST__[0])
+  void **jcr_list;
+  __asm ("" : "=g" (jcr_list) : "0" (__JCR_LIST__));
+  if (*jcr_list)
 {
   void (*register_classes) (void *) = _Jv_RegisterClasses;
   __asm ("" : "+r" (register_classes));
   if (register_classes)
-   register_classes (__JCR_LIST__);
+   register_classes (jcr_list);
 }
 #endif /* JCR_SECTION_NAME */
 
@@ -565,12 +567,14 @@ __do_global_ctors_1(void)
 #endif
 
 #ifdef JCR_SECTION_NAME
-  if (__JCR_LIST__[0])
+  void **jcr_list
+  __asm ("" : "=g" (jcr_list) : "0" (__JCR_LIST__));
+  if (*jcr_list)
 {
   void (*register_classes) (void *) = _Jv_RegisterClasses;
   __asm ("" : "+r" (register_classes));
   if (register_classes)
-   register_classes (__JCR_LIST__);
+   register_classes (jcr_list);
 }
 #endif
 


[patch,libfortran] [4.7/4.8/4.9 Regression] PR38199 missed optimization: I/O performance

2014-03-09 Thread Jerry DeLisle
Hi all,

This final patch does two things.

First:  In read.c it implements a simple space skipping scheme in read_decimal
where I found a lot of repeated next_char calls happening. This gives a pretty
good boost in performance and is applicable in general for reading integers.

Second: I have taken Thomas idea of using LEN_TRIM in unit.c revised it to work
on formatted READ.  I tried to document the code with comments.  There are
certain conditions for which one can not shorten the string length for internal
units. For arrays of characters you can not do this for strings more than rank 1
and stride 1. Also, you can not do this any time a BLANK='zero' is being used. I
also skip the optimization if there is any BLANK= specified in the READ. Thats
conservative.  I could also test for BLANK='NULL' in the DTP structure. I will
probably do that later.

I have added a helper function which tests for the BZ within a format string
when a format string is present.  I also check to see if the UNIT has had the
BLANK status set.  The optimization is skipped for these conditions.

So what are the results?

For the case in comment 29 of the PR which was the last case to be worked out:

Size:   NoPatch Patch:

10  7.48.312
5   3.65.152
25000   2.07.085
12000   1.00.054
6000.513.036
3000.255.029
1500.143.028
750 .082.026
300 .047.025
150 .032.024
75  .026.022
50  .023.021

Where Size is the size of the buffer string and format specifier in the read.

Times are in seconds.

I was thinking that at some string size we could just skip the optimization
altogether to avoid the overhead on smaller strings. Maybe strings less then 50
bytes long.

Regression tested on X86-64-Gnu-Linux. No new test case needed.

OK for trunk?

Regards,

Jerry

2014-03-08  Jerry DeLisle  

PR libfortran/38199

Index: read.c
===
--- read.c	(revision 208303)
+++ read.c	(working copy)
@@ -677,7 +677,13 @@ read_decimal (st_parameter_dt *dtp, const fnode *f
 	
   if (c == ' ')
 {
-	  if (dtp->u.p.blank_status == BLANK_NULL) continue;
+	  if (dtp->u.p.blank_status == BLANK_NULL)
+	{
+	  /* Skip spaces.  */
+	  for ( ; w > 0; p++, w--)
+		if (*p != ' ') break; 
+	  continue;
+	}
 	  if (dtp->u.p.blank_status == BLANK_ZERO) c = '0';
 }
 
Index: unit.c
===
--- unit.c	(revision 208303)
+++ unit.c	(working copy)
@@ -375,6 +375,25 @@ find_or_create_unit (int n)
 }
 
 
+/* Helper function to test for BZ (Blank Zero) in format string. This
+   is used for optimization. You can't trim out blanks if they have
+   significance.  */
+static bool
+is_BZ (st_parameter_dt *dtp)
+{
+  if (dtp->common.flags & IOPARM_DT_HAS_FORMAT)
+{
+  char *p = dtp->format;
+  off_t i;
+  for (i = 0; i < dtp->format_len; i++)
+	if (p[i] == 'b' || p[i] == 'B')
+	  if (p[i+1] == 'z' || p[i+1] == 'Z')
+	return true;
+}
+  return false;
+}
+
+
 gfc_unit *
 get_internal_unit (st_parameter_dt *dtp)
 {
@@ -402,6 +421,33 @@ get_internal_unit (st_parameter_dt *dtp)
  some other file I/O unit.  */
   iunit->unit_number = -1;
 
+  /* As an optimization, adjust the unit record length to not
+ include trailing blanks. This will not work under certain conditions
+ where trailing blanks have significance.  */
+  if (dtp->u.p.mode == READING && !dtp->u.p.ionml
+  && !(dtp->internal_unit_desc
+	   && (GFC_DESCRIPTOR_RANK (dtp->internal_unit_desc) > 1
+	   || GFC_DESCRIPTOR_STRIDE(dtp->internal_unit_desc, 0) != 1))
+  && !is_BZ (dtp) && dtp->blank_len == 0)
+{
+  if (dtp->common.unit == 0)
+	{
+	  int tmp = string_len_trim (dtp->internal_unit_len,
+ dtp->internal_unit);
+	  if (tmp > 0)
+	dtp->internal_unit_len = tmp; 
+	  iunit->recl = dtp->internal_unit_len;
+	}
+  else
+	{
+	  int tmp = string_len_trim_char4 (dtp->internal_unit_len,
+			  (const gfc_char4_t*) dtp->internal_unit);
+	  if (tmp > 0)
+	dtp->internal_unit_len = tmp;
+	  iunit->recl = dtp->internal_unit_len;
+	}
+}
+
   /* Set up the looping specification from the array descriptor, if any.  */
 
   if (is_array_io (dtp))
@@ -414,27 +460,6 @@ get_internal_unit (st_parameter_dt *dtp)
 
   start_record *= iunit->recl;
 }
-  else
-{
-  /* If we are not processing an array, adjust the unit record length not
-	 to include trailing blanks for list-formatted reads.  */
-  if (dtp->u.p.mode == READING && !(dtp->common.flags & IOPARM_DT_HAS_FORMAT))
-	{
-	  if (dtp->commo

RE: patch fortran, pr 59746, internal compiler error : segmentation fault

2014-03-09 Thread jimmie.davis


From: Mikael Morin [mikael.mo...@sfr.fr]
Sent: Sunday, March 09, 2014 3:40 PM
To: Davis, Bud @ SSG - Link; gcc-patches@gcc.gnu.org; fort...@gcc.gnu.org
Subject: Re: patch fortran, pr 59746, internal compiler error : segmentation 
fault

   
> -  if (p->gfc_new)
 
>write this instead:
>if (p->attr.in_common && p->common_block && p->common_block->head
>&& (p->gfc_new || !p->old_symbol->attr.in_common))

>[p->attr.in_common is less likely than p->gfc_new which happens all the
>time; we may as well short-circuit the latter.]

Done.

>For the rest of the patch, there are indentation issues, any leading 8
>spaces block should be replaced with a tab.

Done.  All sequences of 8 spaces are replaced with a tab.

>You can use "contrib/check_GNU_style.sh your_patch" to check common
>style issues)

All issues fixed, except for test case lines, the 'dg error' lines are over 80 
columns.  A lot of the tests do this, I am guessing this violation is 
acceptable.

 
> + if (p->common_block->head == p)
>I think the code block starting here is indented too much.

Fixed.

> +if (p->gfc_new)
>Same here, the code after this shouldn't need reindenting.
 
Fixed.

>Mikael

Below is the revised patch.  Still passes the testsuite with no new failures.


regards,
Bud Davis





Index: gcc/gcc/testsuite/gfortran.dg/pr59746.f90
===
--- gcc/gcc/testsuite/gfortran.dg/pr59746.f90   (revision 0)
+++ gcc/gcc/testsuite/gfortran.dg/pr59746.f90   (revision 0)
@@ -0,0 +1,18 @@
+! { dg-do compile }
+!pr59746
+  CALL RCCFL (NVE,IR,NU3,VE (1,1,1,I))
+  COMMON /CCFILE/ INTG,NT1,NT2,NT3,NVM,NVE,NFRLE,NRESF,NRESL !{ dg-error 
"Unexpected COMMON" }
+  COMMON /CCFILE/ INTG,NT1,NT2,NT3,NVM,NVE,NFRLE,NRESF,NRESL !{ dg-error 
"Unexpected COMMON" }
+!  the PR only contained the two above.
+!  success is no segfaults or infinite loops.
+!  let's check some combinations
+ CALL ABC (INTG)
+ COMMON /CCFILE/ INTG,NT1,NT2,NT3,NVM,NVE,NFRLE,NRESF,NRESL !{ dg-error 
"Unexpected COMMON" }
+ COMMON /CCFILE/ INTG,NT1,NT2,NT3,NVM,NVE,NFRLE,NRESF,NRESL !{ dg-error 
"Unexpected COMMON" }
+ CALL DEF (NT1)
+ COMMON /CCFILE/ INTG,NT1,NT2,NT3,NVM,NVE,NFRLE,NRESF,NRESL !{ dg-error 
"Unexpected COMMON" }
+ COMMON /CCFILE/ INTG,NT1,NT2,NT3,NVM,NVE,NFRLE,NRESF,NRESL !{ dg-error 
"Unexpected COMMON" }
+ CALL GHI (NRESL)
+ COMMON /CCFILE/ INTG,NT1,NT2,NT3,NVM,NVE,NFRLE,NRESF,NRESL !{ dg-error 
"Unexpected COMMON" }
+ COMMON /CCFILE/ INTG,NT1,NT2,NT3,NVM,NVE,NFRLE,NRESF,NRESL !{ dg-error 
"Unexpected COMMON" }
+ END
Index: gcc/gcc/fortran/symbol.c
===
--- gcc/gcc/fortran/symbol.c(revision 208437)
+++ gcc/gcc/fortran/symbol.c(working copy)
@@ -3069,56 +3069,56 @@
 
   FOR_EACH_VEC_ELT (latest_undo_chgset->syms, i, p)
 {
-  if (p->gfc_new)
+  /* Symbol was new.  Or was old and just put in common.  */
+  if ( p->attr.in_common && p->common_block && p->common_block->head
+  && (p->gfc_new || !p->old_symbol->attr.in_common))
{
- /* Symbol was new.  */
- if (p->attr.in_common && p->common_block && p->common_block->head)
-   {
- /* If the symbol was added to any common block, it
-needs to be removed to stop the resolver looking
-for a (possibly) dead symbol.  */
+ /* If the symbol was added to any common block, it
+ needs to be removed to stop the resolver looking
+ for a (possibly) dead symbol.  */
 
- if (p->common_block->head == p && !p->common_next)
+ if (p->common_block->head == p && !p->common_next)
+   {
+ gfc_symtree st, *st0;
+ st0 = find_common_symtree (p->ns->common_root,
+p->common_block);
+ if (st0)
{
- gfc_symtree st, *st0;
- st0 = find_common_symtree (p->ns->common_root,
-p->common_block);
- if (st0)
-   {
- st.name = st0->name;
- gfc_delete_bbt (&p->ns->common_root, &st, 
compare_symtree);
- free (st0);
-   }
+ st.name = st0->name;
+ gfc_delete_bbt (&p->ns->common_root, &st, compare_symtree);
+ free (st0);
}
+   }
 
- if (p->common_block->head == p)
-   p->common_block->head = p->common_next;
- else
-   {
- gfc_symbol *cparent, *csym;
+ if (p->common_block->head == p)
+   p->common_block->head = p->common_next;
+ else
+   {
+ gfc_symbol *cparent, *csym;
 
- cparent = p->common_block->head;
- csym