Bug 40721 - [LTO] complains about two tentative definitions
Summary: [LTO] complains about two tentative definitions
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: lto (show other bugs)
Version: lto
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2009-07-11 17:45 UTC by Richard Biener
Modified: 2009-07-13 13:43 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2009-07-13 05:27:24


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Biener 2009-07-11 17:45:37 UTC
This breaks a lot of benchmarks in SPEC CPU 2000.

t.c

int i;

t2.c

int i;
int main() { return i; }

$ ./xgcc -B. -o t t1.c t2.c
$ ./xgcc -B. -o t t1.c t2.c -flto
t2.c:1:5: error: 'i' has already been defined
t1.c:1:5: error: previously defined here
lto-wrapper: ././xgcc returned 1 exit status
collect2: lto-wrapper returned 1 exit status

the LTO behavior is wrong for C.  The testcase would violate the C++ ODR, but
LTO should not reject the valid C program (note ODR violations do not need to
be diagnosed).
Comment 1 Richard Biener 2009-07-11 17:53:12 UTC
Cases like

t1.c
int i = 2;

t2.c
int i = 1;
int main() { return i; }

are diagnosed by the linker - not ideal, but not different from -fno-lto either.


Index: lto-symtab.c
===================================================================
--- lto-symtab.c	(revision 149512)
+++ lto-symtab.c	(working copy)
@@ -568,15 +568,17 @@ lto_symtab_merge_decl (tree new_decl,
   if (resolution == LDPR_PREVAILING_DEF
       || resolution == LDPR_PREVAILING_DEF_IRONLY)
     {
-      if (old_resolution == LDPR_PREVAILING_DEF
-	  || old_resolution == LDPR_PREVAILING_DEF_IRONLY)
+      if ((old_resolution == LDPR_PREVAILING_DEF
+	   || old_resolution == LDPR_PREVAILING_DEF_IRONLY)
+	  && old_resolution != resolution)
 	{
 	  error ("%J%qD has already been defined", new_decl, new_decl);
 	  error ("%Jpreviously defined here", old_decl);
 	  return;
 	}
       gcc_assert (old_resolution == LDPR_PREEMPTED_IR
-		  || old_resolution ==  LDPR_RESOLVED_IR);
+		  || old_resolution ==  LDPR_RESOLVED_IR
+		  || old_resolution == resolution);
       lto_symtab_set_identifier_decl (name, new_decl);
       return;
     }
Comment 2 Andrew Pinski 2009-07-11 18:05:16 UTC
Note this is only true for the non -fno-common case.  Really this is an extension to the standard C language but we should support it.
Comment 3 rguenther@suse.de 2009-07-11 18:09:47 UTC
Subject: Re:  [LTO] complains about two tentative
 definitions

On Sat, 11 Jul 2009, pinskia at gcc dot gnu dot org wrote:

> ------- Comment #2 from pinskia at gcc dot gnu dot org  2009-07-11 18:05 -------
> Note this is only true for the non -fno-common case.  Really this is an
> extension to the standard C language but we should support it.

You mean it is only true for -fcommon (which is the default)?

Richard.
Comment 4 Andrew Pinski 2009-07-11 18:19:20 UTC
(In reply to comment #3)
> Subject: Re:  [LTO] complains about two tentative
>  definitions
> 
> On Sat, 11 Jul 2009, pinskia at gcc dot gnu dot org wrote:
> 
> > ------- Comment #2 from pinskia at gcc dot gnu dot org  2009-07-11 18:05 -------
> > Note this is only true for the non -fno-common case.  Really this is an
> > extension to the standard C language but we should support it.
> 
> You mean it is only true for -fcommon (which is the default)?

What I write is the same as what your wrote (I had  two negatives ;) .

-- Pinski
Comment 5 Ben Elliston 2009-07-13 05:27:24 UTC
Confirmed.
Comment 6 Richard Biener 2009-07-13 13:42:29 UTC
Subject: Bug 40721

Author: rguenth
Date: Mon Jul 13 13:42:03 2009
New Revision: 149587

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=149587
Log:
2009-07-13  Richard Guenther  <rguenther@suse.de>

	PR lto/40721
	* lto-opts.c (register_user_option_p): Handle OPT_fcommon.
	(handle_common_option): Likewise.
	* lto-symtab.c (lto_symtab_merge_decl): Merge re-definitions
	if flag_no_common is not set.

Modified:
    branches/lto/gcc/ChangeLog.lto
    branches/lto/gcc/lto-opts.c
    branches/lto/gcc/lto-symtab.c

Comment 7 Richard Biener 2009-07-13 13:43:06 UTC
Fixed.