2007-08-29 Christopher D. Rickett <crickett@lanl.gov>
authorburnus <burnus@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 29 Aug 2007 13:08:55 +0000 (13:08 +0000)
committerburnus <burnus@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 29 Aug 2007 13:08:55 +0000 (13:08 +0000)
PR fortran/33215
* decl.c (build_sym): Pass number of identifiers on line to
set_binding_label.
(set_binding_label): Verify that only one identifier given if
NAME= specified, even if the given binding label has zero length.
(gfc_match_bind_c): Remove declaration for has_name_equals because
it hides the static global one that is needed.

2007-08-29  Christopher D. Rickett  <crickett@lanl.gov>

PR fortran/33215
* gfortran.dg/binding_label_tests_15.f03: New test case.
* gfortran.dg/binding_label_tests_16.f03: Ditto.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@127898 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/fortran/ChangeLog
gcc/fortran/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/binding_label_tests_15.f03 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/binding_label_tests_16.f03 [new file with mode: 0644]

index b523e8a..7e5a7d8 100644 (file)
@@ -1,3 +1,13 @@
+2007-08-28  Christopher D. Rickett  <crickett@lanl.gov>
+
+       PR fortran/33215
+       * decl.c (build_sym): Pass number of identifiers on line to
+       set_binding_label.
+       (set_binding_label): Verify that only one identifier given if
+       NAME= specified, even if the given binding label has zero length.
+       (gfc_match_bind_c): Remove declaration for has_name_equals because
+       it hides the static global one that is needed.
+
 2007-08-29  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
 
        * trans-array.c (gfc_grow_array): Use gfc_call_realloc.
index 70098b4..8b35662 100644 (file)
@@ -980,9 +980,10 @@ build_sym (const char *name, gfc_charlen *cl,
     {
       if (sym->binding_label[0] == '\0')
         {
-          /* Here, we're not checking the numIdents (the last param).
-             This could be an error we're letting slip through!  */
-          if (set_binding_label (sym->binding_label, sym->name, 1) == FAILURE)
+         /* Set the binding label and verify that if a NAME= was specified
+            then only one identifier was in the entity-decl-list.  */
+         if (set_binding_label (sym->binding_label, sym->name,
+                                num_idents_on_line) == FAILURE)
             return FAILURE;
         }
     }
@@ -2847,15 +2848,15 @@ cleanup:
 try
 set_binding_label (char *dest_label, const char *sym_name, int num_idents)
 {
-  if (curr_binding_label[0] != '\0')
+  if (num_idents > 1 && has_name_equals)
     {
-      if (num_idents > 1 || num_idents_on_line > 1)
-        {
-          gfc_error ("Multiple identifiers provided with "
-                     "single NAME= specifier at %C");
-          return FAILURE;
-        }
+      gfc_error ("Multiple identifiers provided with "
+                "single NAME= specifier at %C");
+      return FAILURE;
+    }
 
+  if (curr_binding_label[0] != '\0')
+    {
       /* Binding label given; store in temp holder til have sym.  */
       strncpy (dest_label, curr_binding_label,
                strlen (curr_binding_label) + 1);
@@ -4084,7 +4085,6 @@ gfc_match_bind_c (gfc_symbol *sym)
   char binding_label[GFC_MAX_SYMBOL_LEN + 1];
   match double_quote;
   match single_quote;
-  int has_name_equals = 0;
 
   /* Initialize the flag that specifies whether we encountered a NAME= 
      specifier or not.  */
index 1878af1..03edfa1 100644 (file)
@@ -1,3 +1,9 @@
+2007-08-29  Christopher D. Rickett  <crickett@lanl.gov>
+
+       PR fortran/33215
+       * gfortran.dg/binding_label_tests_15.f03: New test case.
+       * gfortran.dg/binding_label_tests_16.f03: Ditto.
+
 2007-08-29  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
 
        * gfortran.dg/alloc_comp_basics_1.f90: Update check.
@@ -61,7 +67,7 @@
        PR c++/32596
        * g++.dg/ext/visibility/anon5.C: New test.
 
-2007-07-28  Dominique d'Humieres  <dominiq@lps.ens.fr>
+2007-08-28  Dominique d'Humieres  <dominiq@lps.ens.fr>
 
        * gfortran.dg/gamma_4.f90: Fix large-real kind selection.
 
diff --git a/gcc/testsuite/gfortran.dg/binding_label_tests_15.f03 b/gcc/testsuite/gfortran.dg/binding_label_tests_15.f03
new file mode 100644 (file)
index 0000000..b1b4b58
--- /dev/null
@@ -0,0 +1,12 @@
+! { dg-do compile }
+! Verify that an error is correctly reported if multiple identifiers are given
+! with a bind(c) statement that has a NAME= specifier.
+module m
+  use iso_c_binding
+  implicit none
+  integer(c_int), bind(C, name="") :: a,b ! { dg-error "Multiple identifiers" }
+  integer(c_int), bind(C, name="bob") :: c,d ! { dg-error "Multiple identifiers" }
+  integer(c_int) :: e,f 
+  bind(c, name="foo") :: e,f ! { dg-error "Multiple identifiers" }
+end module m
+
diff --git a/gcc/testsuite/gfortran.dg/binding_label_tests_16.f03 b/gcc/testsuite/gfortran.dg/binding_label_tests_16.f03
new file mode 100644 (file)
index 0000000..6b8f1f8
--- /dev/null
@@ -0,0 +1,22 @@
+! { dg-do run }
+! Verify that the variables 'a' in both modules don't collide.
+module m
+  use iso_c_binding
+  implicit none
+  integer(c_int), save, bind(C, name="") :: a = 5
+end module m
+
+module n
+  use iso_c_binding
+  implicit none
+  integer(c_int), save, bind(C,name="") :: a = -5
+end module n
+
+program prog
+use m
+use n, b=>a
+implicit none
+  print *, a, b
+  if (a /= 5 .or. b /= -5) call abort()
+end program prog
+! { dg-final { cleanup-modules "m n" } }