* [Patch, Fortran] PR 31600 - Better diagnosis when redeclaring used-assoc symbol
@ 2011-08-23 10:17 Tobias Burnus
2011-08-23 11:33 ` Mikael Morin
0 siblings, 1 reply; 2+ messages in thread
From: Tobias Burnus @ 2011-08-23 10:17 UTC (permalink / raw)
To: gcc patches, gfortran
[-- Attachment #1: Type: text/plain, Size: 975 bytes --]
Before, one got the following error for the attached test case:
------------------------------------
integer :: bar
1
Error: Symbol 'bar' at (1) already has basic type of INTEGER
------------------------------------
Which can be a bit puzzling in larger programs. With the patch, one gets:
------------------------------------
use_16.f90:15.14:
integer :: bar
1
use_16.f90:13.83:
use a
2
Error: Symbol 'bar' at (1) conflicts with symbol from module 'a',
use-associated at (2)
------------------------------------
The module change is a bit unrelated but makes the error a bit more
readable. Instead of having:
dg-error "Symbol 'bar' at \\(1\\) conflicts with symbol from module 'a'" }
2
One now has:
use a ! { dg-error "Symbol 'bar' at \\(1\\) conflicts with symbol from
module '
2
Build and regtested on x86-64-linux.
OK for the trunk?
Tobias
[-- Attachment #2: redecl-err.diff --]
[-- Type: text/x-patch, Size: 2608 bytes --]
2011-08-23 Tobias Burnus <burnus@net-b.de>
PR fortran/31600
* symbol.c (gfc_add_type): Better diagnostic if redefining
use-associated symbol.
* module.c (gfc_use_module): Use module name as locus.
2011-08-23 Tobias Burnus <burnus@net-b.de>
PR fortran/31600
* gfortran.dg/use_16.f90: New.
diff --git a/gcc/fortran/module.c b/gcc/fortran/module.c
index aef3404..4250a17 100644
--- a/gcc/fortran/module.c
+++ b/gcc/fortran/module.c
@@ -5727,6 +5727,9 @@ gfc_use_module (void)
int c, line, start;
gfc_symtree *mod_symtree;
gfc_use_list *use_stmt;
+ locus old_locus = gfc_current_locus;
+
+ gfc_current_locus = use_locus;
filename = (char *) alloca (strlen (module_name) + strlen (MODULE_EXTENSION)
+ 1);
@@ -5748,6 +5751,7 @@ gfc_use_module (void)
"intrinsic module at %C") != FAILURE)
{
use_iso_fortran_env_module ();
+ gfc_current_locus = old_locus;
return;
}
@@ -5756,6 +5760,7 @@ gfc_use_module (void)
"ISO_C_BINDING module at %C") != FAILURE)
{
import_iso_c_binding_module();
+ gfc_current_locus = old_locus;
return;
}
@@ -5845,6 +5850,8 @@ gfc_use_module (void)
gfc_rename_list = NULL;
use_stmt->next = gfc_current_ns->use_stmts;
gfc_current_ns->use_stmts = use_stmt;
+
+ gfc_current_locus = old_locus;
}
diff --git a/gcc/fortran/symbol.c b/gcc/fortran/symbol.c
index 4463460..126a52b 100644
--- a/gcc/fortran/symbol.c
+++ b/gcc/fortran/symbol.c
@@ -1672,7 +1672,12 @@ gfc_add_type (gfc_symbol *sym, gfc_typespec *ts, locus *where)
if (type != BT_UNKNOWN && !(sym->attr.function && sym->attr.implicit_type))
{
- gfc_error ("Symbol '%s' at %L already has basic type of %s", sym->name,
+ if (sym->attr.use_assoc)
+ gfc_error ("Symbol '%s' at %L conflicts with symbol from module '%s', "
+ "use-associated at %L", sym->name, where, sym->module,
+ &sym->declared_at);
+ else
+ gfc_error ("Symbol '%s' at %L already has basic type of %s", sym->name,
where, gfc_basic_typename (type));
return FAILURE;
}
--- /dev/null 2011-08-23 07:28:57.751883742 +0200
+++ gcc/gcc/testsuite/gfortran.dg/use_16.f90 2011-08-23 09:59:19.000000000 +0200
@@ -0,0 +1,18 @@
+! { dg-do compile }
+!
+! PR fortran/31600
+!
+module a
+implicit none
+contains
+ integer function bar()
+ bar = 42
+ end function
+end module a
+
+use a ! { dg-error "Symbol 'bar' at \\(1\\) conflicts with symbol from module 'a'" }
+implicit none
+integer :: bar ! { dg-error "Symbol 'bar' at \\(1\\) conflicts with symbol from module 'a'" }
+end
+
+! { dg-final { cleanup-modules "a" } }
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Patch, Fortran] PR 31600 - Better diagnosis when redeclaring used-assoc symbol
2011-08-23 10:17 [Patch, Fortran] PR 31600 - Better diagnosis when redeclaring used-assoc symbol Tobias Burnus
@ 2011-08-23 11:33 ` Mikael Morin
0 siblings, 0 replies; 2+ messages in thread
From: Mikael Morin @ 2011-08-23 11:33 UTC (permalink / raw)
To: fortran; +Cc: Tobias Burnus, gcc patches
On Tuesday 23 August 2011 11:48:27 Tobias Burnus wrote:
> Build and regtested on x86-64-linux.
> OK for the trunk?
>
OK.
Mikael
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-08-23 11:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-23 10:17 [Patch, Fortran] PR 31600 - Better diagnosis when redeclaring used-assoc symbol Tobias Burnus
2011-08-23 11:33 ` Mikael Morin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).