LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 1077 - Duplicate global vars allowed by llvm-as
Summary: Duplicate global vars allowed by llvm-as
Status: RESOLVED FIXED
Alias: None
Product: tools
Classification: Unclassified
Component: llvm-as (show other bugs)
Version: trunk
Hardware: All All
: P normal
Assignee: Unassigned LLVM Bugs
URL:
Keywords: quality-of-implementation
Depends on:
Blocks:
 
Reported: 2007-01-04 17:02 PST by Reid Spencer
Modified: 2010-02-22 12:54 PST (History)
2 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Reid Spencer 2007-01-04 17:02:36 PST
The test/Feature/constexpr.ll test case is incorrect. It is specifically
allowing this:

%t4 = global int** cast (uint** %t3 to int**)
%t4 = global int** cast (uint** %t3 to int**)

This should produce an error as it is incorrect to allow redefinition of global
vars, even if they have exactly the same type and initializer.

Such redefinition needs to be made illegal in llvm-as. The test case needs to
be modified to not test for allowing redefinition. A new test case should check
that llvm-as generates an error on redefinition.
Comment 1 Reid Spencer 2007-01-04 19:40:54 PST
This test case:

test/Regression/Assembler/2003-02-02-ConstGlobal.ll

also tests for redefinition of global/constant. 

Chris, are you SURE you want to make this illegal. I would have to remove this
regression test if I fixed this test. It was obviously a regression on
something. Are we certain the llvm-gcc4 front end cannot produce such things?

Comment 2 Chris Lattner 2007-01-04 19:50:40 PST
Yes, that testcase is also broken.  These were due to llvm-gcc3, which would output stuff then sometimes 
have to change its mind.  This was a broken design due to llvm-gcc3 having it's own implementation of 
the llvm ir that wasn't quite right.
Comment 3 Reid Spencer 2007-01-04 20:17:20 PST
Okay, there's a dozen or so more of these. I'll either fix the test case to not
redefine a name or delete it entirely (if redefinition is all its testing).
Comment 4 Chris Lattner 2007-01-04 20:56:13 PST
Sounds good
Comment 5 Reid Spencer 2007-01-04 20:58:32 PST
Why stop at just redefinition in a type plane? Any redefinition of an external
global symbol should be illegal, even across types.
Comment 6 Chris Lattner 2007-01-04 20:59:50 PST
i agree.  Historically we allowed this *because* of type planes.  However, I'd like to drop them entirely.  I'm 
not sure I will get to it in the 2.0 timeframe though.
Comment 7 Reid Spencer 2007-01-04 21:02:10 PST
Hmm .. what about:
test/Regression/Transforms/FunctionResolve/2003-10-21-GlobalResolveHack.ll
which says:

; This tests a hack put into place specifically for the C++ libstdc++ library.
; It uses an ugly hack which is cleaned up by the funcresolve pass.
; RUN: llvm-upgrade < %s | llvm-as | opt -funcresolve | llvm-dis | \
;   grep %X | grep '{'
                                                                               
%X = external global { int }
%X = global [ 4 x sbyte ] zeroinitializer                                       
implementation                                                                  
int* %test() {                                                                 
  %P = getelementptr {int}* %X, long 0, uint 0
  ret int* %P                                                                   }

Has the ugly hack now been removed?
Comment 8 Chris Lattner 2007-01-04 21:07:42 PST
good point.  To handle that, we need to verify that llvm-link will correctly unify the globals in these two 
.ll files:

a.ll:
%X = external global { int }

b.ll:
%X = global [ 4 x sbyte ] zeroinitializer                                       

The linker should merge those together: we should not have 'type-plane aware linking'.

-Chris
Comment 9 Reid Spencer 2007-01-04 21:19:01 PST
What are the unification rules? Same size?
Comment 10 Chris Lattner 2007-01-05 01:02:54 PST
same name
Comment 11 Reid Spencer 2007-01-05 01:58:01 PST
The situation wouldn't arise if they weren't the same name. That's not what I'm
asking. Assuming the names are the same:

1. What rules are there for disallowing the merged types? I suggested that they
   have to be the same size.

2. Which type would one pick for the merged gvar? The initialized one? 
   The first one?

Reid.
Comment 12 Reid Spencer 2007-01-05 14:19:16 PST
I guess it doesn't matter. llvm-link produces:

; ModuleID = 'c.bc'
%X = global [4 x i8] zeroinitializer            ; <[4 x i8]*> [#uses=0]

implementation   ; Functions:

which I guess is correct. 

So, can I just go ahead and make same named gvars in llvm-as and verifier illegal?
Comment 13 Chris Lattner 2007-01-05 15:38:13 PST
sounds good.  The buggy behavior in the linker has probably since been fixed.
Comment 14 Reid Spencer 2007-01-05 15:52:44 PST
Fixed with this patch:

http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20070101/042099.html