Bug 51788 - Unstable gfc_verify_binding_labels check for a binding label which collides with a global entity
Summary: Unstable gfc_verify_binding_labels check for a binding label which collides w...
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid, diagnostic
Depends on:
Blocks: 51578
  Show dependency treegraph
 
Reported: 2012-01-07 22:19 UTC by Tobias Burnus
Modified: 2019-01-26 11:31 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-12-18 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2012-01-07 22:19:43 UTC
Found when trying to create a patch for PR 51578. Seemingly, the generated tree is now slightly different.

The problem is that the test case
  gfortran.dg/binding_label_tests_10_main.f03
fails with my patch - without, one gets the following.

However, if one swaps the lines
  use binding_label_tests_10_main
  use binding_label_tests_10 ! { dg-error "collides" }
I get now an error with my patch - but none with the unpatched GCC.

Hence, the test case is not stable. At least with my patch it fails in resolve.c's gfc_verify_binding_labels as:
          if (sym->attr.if_source == IFSRC_DECL
is not fulfilled. The reason is that symbols loaded from .mod files are have IFSRC_UNKNOWN.


A "proper" error message looks as follows:

gfortran.dg/binding_label_tests_10_main.f03:11.6:

  use binding_label_tests_10 ! { dg-error "collides" }
      1
gfortran.dg/binding_label_tests_10_main.f03:7.45:

  integer(c_int), bind(c,name="c_one") :: one ! { dg-error "collides" }
                                             2
Error: Binding label 'c_one' at (1) collides with global entity 'c_one' at (2)


(Cf. PR 48858 comment 9 for some information about binding labels.)
Comment 1 Tobias Burnus 2012-01-07 23:15:58 UTC
The problems is that:
            if ((sym->attr.use_assoc && bind_c_sym->mod_name
                 && strcmp (bind_c_sym->mod_name, sym->module) != 0)
is not true as the gsym and the sym are for the same symbol.

However, one has an ambiguity:
  (gdb) p sym->ns->sym_root->right->right->name
  $44 = 0x2aaaacc36018 "one"
  (gdb) p sym->ns->sym_root->right->right->ambiguous
  $45 = 1

This ambiguity will later lead to:
  Error: Name 'one' at (1) is an ambiguous reference to 'one'
if one tries to reference the variable.


I do not see a good solution but as the ambiguity is diagnosed if one tries to reference the variable, I am tempted to use the following patch:


--- a/gcc/testsuite/gfortran.dg/binding_label_tests_10_main.f03
+++ b/gcc/testsuite/gfortran.dg/binding_label_tests_10_main.f03
@@ -7 +7 @@ module binding_label_tests_10_main
-  integer(c_int), bind(c,name="c_one") :: one ! { dg-error "collides" }
+  integer(c_int), bind(c,name="c_one") :: two ! { dg-error "collides" }

--- a/gcc/testsuite/gfortran.dg/binding_label_tests_11_main.f03
+++ b/gcc/testsuite/gfortran.dg/binding_label_tests_11_main.f03
@@ -8,2 +8,2 @@ contains
-  function one() bind(c, name="c_one") ! { dg-error "collides" }
-    integer(c_int) one
+  function two() bind(c, name="c_one") ! { dg-error "collides" }
+    integer(c_int) two
@@ -11 +11 @@ contains
-  end function one
+  end function two
Comment 2 Dominique d'Humieres 2013-12-18 08:07:43 UTC
I confirm that if the lines

  use binding_label_tests_10 ! { dg-error "Variable one ..." }
  use binding_label_tests_10_main

are swapped, the code is compiled without error at r206072.

I am not sure to understand the remaining of this PR.
Comment 3 Dominique d'Humieres 2019-01-14 21:14:05 UTC
Is this still a problem?
Comment 4 Dominique d'Humieres 2019-01-26 11:31:42 UTC
> Is this still a problem?

No feedback, closing as INVALID.