[llvm-commits] [llvm] r41174 - /llvm/trunk/lib/Linker/LinkModules.cpp
Chris Lattner
sabre at nondot.org
Sun Aug 19 15:22:54 PDT 2007
Author: lattner
Date: Sun Aug 19 17:22:54 2007
New Revision: 41174
URL: http://llvm.org/viewvc/llvm-project?rev=41174&view=rev
Log:
Fix PR1611 - Visibility should be ignored for a declaration
when a definition's visibility is different. Likewise, the
visibility of two declarations mismatching is not an error.
Modified:
llvm/trunk/lib/Linker/LinkModules.cpp
Modified: llvm/trunk/lib/Linker/LinkModules.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkModules.cpp?rev=41174&r1=41173&r2=41174&view=diff
==============================================================================
--- llvm/trunk/lib/Linker/LinkModules.cpp (original)
+++ llvm/trunk/lib/Linker/LinkModules.cpp Sun Aug 19 17:22:54 2007
@@ -440,8 +440,9 @@
// Check visibility
if (Dest && Src->getVisibility() != Dest->getVisibility())
- return Error(Err, "Linking globals named '" + Src->getName() +
- "': symbols have different visibilities!");
+ if (!Src->isDeclaration() && !Dest->isDeclaration())
+ return Error(Err, "Linking globals named '" + Src->getName() +
+ "': symbols have different visibilities!");
return false;
}
@@ -651,9 +652,13 @@
// Check visibility
if (DF && !DF->hasInternalLinkage() &&
- SF->getVisibility() != DF->getVisibility())
- return Error(Err, "Linking functions named '" + SF->getName() +
- "': symbols have different visibilities!");
+ SF->getVisibility() != DF->getVisibility()) {
+ // If one is a prototype, ignore its visibility. Prototypes are always
+ // overridden by the definition.
+ if (!SF->isDeclaration() && !DF->isDeclaration())
+ return Error(Err, "Linking functions named '" + SF->getName() +
+ "': symbols have different visibilities!");
+ }
if (DF && DF->getType() != SF->getType()) {
if (DF->isDeclaration() && !SF->isDeclaration()) {
@@ -695,7 +700,7 @@
}
} else if (!DF || SF->hasInternalLinkage() || DF->hasInternalLinkage()) {
// Function does not already exist, simply insert an function signature
- // identical to SF into the dest module...
+ // identical to SF into the dest module.
Function *NewDF = new Function(SF->getFunctionType(), SF->getLinkage(),
SF->getName(), Dest);
CopyGVAttributes(NewDF, SF);
@@ -724,6 +729,8 @@
// Link the external functions, update linkage qualifiers
ValueMap.insert(std::make_pair(SF, DF));
DF->setLinkage(SF->getLinkage());
+ // Visibility of prototype is overridden by vis of definition.
+ DF->setVisibility(SF->getVisibility());
} else if (SF->hasWeakLinkage() || SF->hasLinkOnceLinkage()) {
// At this point we know that DF has LinkOnce, Weak, or External* linkage.
ValueMap.insert(std::make_pair(SF, DF));
More information about the llvm-commits
mailing list