diff mbox

[Fortran] PR fortran/43665: function annotations for noclobber/noescape arguments

Message ID 4C8E7148.6090400@domob.eu
State New
Headers show

Commit Message

Daniel Kraft Sept. 13, 2010, 6:45 p.m. UTC
Hi all,

Tobias asked me to resubmit his updated patch attached to PR 43665, 
including the test-case he forgot and the fix in the last comment by 
him, so here it is.

Bootstrapped and regtested on x86_64-unknown-linux-gnu, no regressions. 
  Ok for trunk?  (Not sure if I will commit it for him, but I ask for 
review anyways so he can do it when he is back at the latest.)

Yours,
Daniel

Comments

Tobias Burnus Sept. 16, 2010, 5:44 p.m. UTC | #1
*ping*

Daniel Kraft wrote:
> Tobias asked me to resubmit his updated patch attached to PR 43665, 
> including the test-case he forgot and the fix in the last comment by 
> him, so here it is.
>
> Bootstrapped and regtested on x86_64-unknown-linux-gnu, no 
> regressions.  Ok for trunk?

Current patch: http://gcc.gnu.org/ml/fortran/2010-09/msg00303.html

I followed the suggestion of Mikael at 
http://gcc.gnu.org/ml/fortran/2010-09/msg00198.html to moved the 
function from trans-decl.c to gfc_get_function_type in trans-types.

And I use -fno-inline for the test Cray test case to avoid wrong-code 
issues due to the invalid aliasing in the test case (which is needed to 
check the result).

Tobias
Mikael Morin Sept. 16, 2010, 8:33 p.m. UTC | #2
On Thursday 16 September 2010 19:44:08 Tobias Burnus wrote:
>   *ping*
> 
> Daniel Kraft wrote:
> > Tobias asked me to resubmit his updated patch attached to PR 43665,
> > including the test-case he forgot and the fix in the last comment by
> > him, so here it is.
> > 
> > Bootstrapped and regtested on x86_64-unknown-linux-gnu, no
> > regressions.  Ok for trunk?
> 
> Current patch: http://gcc.gnu.org/ml/fortran/2010-09/msg00303.html
> 
> I followed the suggestion of Mikael at
> http://gcc.gnu.org/ml/fortran/2010-09/msg00198.html to moved the
> function from trans-decl.c to gfc_get_function_type in trans-types.
> 
> And I use -fno-inline for the test Cray test case to avoid wrong-code
> issues due to the invalid aliasing in the test case (which is needed to
> check the result).
> 
> Tobias

OK. Thanks.

Mikael
diff mbox

Patch

Index: gcc/fortran/trans-types.c
===================================================================
--- gcc/fortran/trans-types.c	(revision 164143)
+++ gcc/fortran/trans-types.c	(working copy)
@@ -2279,6 +2279,53 @@  gfc_get_mixed_entry_union (gfc_namespace
   return type;
 }
 
+/* Create a "fn spec" based on the formal arguments;
+   cf. create_function_arglist.  */
+
+static tree
+create_fn_spec (gfc_symbol *sym, tree fntype)
+{
+  char spec[150];
+  size_t spec_len;
+  gfc_formal_arglist *f;
+  tree tmp;
+
+  memset (&spec, 0, sizeof (spec));
+  spec[0] = '.';
+  spec_len = 1;
+
+  if (sym->attr.entry_master)
+    spec[spec_len++] = 'R';
+  if (gfc_return_by_reference (sym))
+    {
+      gfc_symbol *result = sym->result ? sym->result : sym;
+
+      if (result->attr.pointer || sym->attr.proc_pointer)
+	spec[spec_len++] = '.';
+      else
+	spec[spec_len++] = 'w';
+      if (sym->ts.type == BT_CHARACTER)
+	spec[spec_len++] = 'R';
+    }
+
+  for (f = sym->formal; f; f = f->next)
+    if (spec_len < sizeof (spec))
+      {
+	if (!f->sym || f->sym->attr.pointer || f->sym->attr.target
+	    || f->sym->attr.external || f->sym->attr.cray_pointer)
+	  spec[spec_len++] = '.';
+	else if (f->sym->attr.intent == INTENT_IN)
+	  spec[spec_len++] = 'r';
+	else if (f->sym)
+	  spec[spec_len++] = 'w';
+      }
+
+  tmp = build_tree_list (NULL_TREE, build_string (spec_len, spec));
+  tmp = tree_cons (get_identifier ("fn spec"), tmp, TYPE_ATTRIBUTES (fntype));
+  return build_type_attribute_variant (fntype, tmp);
+}
+
+
 tree
 gfc_get_function_type (gfc_symbol * sym)
 {
@@ -2420,6 +2467,7 @@  gfc_get_function_type (gfc_symbol * sym)
     type = gfc_sym_type (sym);
 
   type = build_function_type (type, typelist);
+  type = create_fn_spec (sym, type);
 
   return type;
 }
Index: gcc/testsuite/gfortran.dg/cray_pointers_2.f90
===================================================================
--- gcc/testsuite/gfortran.dg/cray_pointers_2.f90	(revision 164143)
+++ gcc/testsuite/gfortran.dg/cray_pointers_2.f90	(working copy)
@@ -1,6 +1,11 @@ 
 ! { dg-do run }
-! { dg-options "-fcray-pointer -fbounds-check" }
+! { dg-options "-fcray-pointer -fbounds-check -fno-inline" }
+!
 ! Series of routines for testing a Cray pointer implementation
+!
+! Note: Some of the test cases violate Fortran's alias rules;
+! the "-fno-inline option" for now prevents failures.
+!
 program craytest
   common /errors/errors(400)
   common /foo/foo ! To prevent optimizations
--- /dev/null	2010-07-20 08:01:57.395357453 +0200
+++ gcc/testsuite/gfortran.dg/intent_optimize_1.f90	2010-07-20 16:19:59.000000000 +0200
@@ -0,0 +1,24 @@ 
+! { dg-do compile }
+! { dg-options "-O2 -fdump-tree-optimized" }
+!
+! Check whether the "does_not_exist" subroutine has been
+! optimized away, i.e. check that "foo"'s intent(IN) gets
+! honoured.
+!
+! PR fortran/43665
+!
+interface
+  subroutine foo(x)
+    integer, intent(in) :: x
+  end subroutine foo
+end interface
+
+integer :: y
+
+y = 5
+call foo(y)
+if (y /= 5) call does_not_exist ()
+end
+
+! { dg-final { scan-tree-dump-times "does_not_exist" 0 "optimized" } }
+! { dg-final { cleanup-tree-dump "optimized" } }