llvm.org GIT mirror llvm / ce94319
This important patch fixes two warnings in the linker which can occur from linking valid pieces of code git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@9390 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 15 years ago
1 changed file(s) with 34 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
193193 if (!HasExternal && NumInstancesWithExternalLinkage <= 1)
194194 return false; // Nothing to do? Must have multiple internal definitions.
195195
196
197 std::cerr << "WARNING: Found global types that are not compatible:\n";
198 for (unsigned i = 0; i < Globals.size(); ++i) {
199 std::cerr << "\t" << *Globals[i]->getType() << " %"
200 << Globals[i]->getName() << "\n";
196 // There are a couple of special cases we don't want to print the warning
197 // for, check them now.
198 bool DontPrintWarning = false;
199 if (Concrete && Globals.size() == 2) {
200 GlobalValue *Other = Globals[Globals[0] == Concrete];
201 // If the non-concrete global is a function which takes (...) arguments,
202 // and the return values match, do not warn.
203 if (Function *ConcreteF = dyn_cast(Concrete))
204 if (Function *OtherF = dyn_cast(Other))
205 if (ConcreteF->getReturnType() == OtherF->getReturnType() &&
206 OtherF->getFunctionType()->isVarArg() &&
207 OtherF->getFunctionType()->getParamTypes().empty())
208 DontPrintWarning = true;
209
210 // Otherwise, if the non-concrete global is a global array variable with a
211 // size of 0, and the concrete global is an array with a real size, don't
212 // warn. This occurs due to declaring 'extern int A[];'.
213 if (GlobalVariable *ConcreteGV = dyn_cast(Concrete))
214 if (GlobalVariable *OtherGV = dyn_cast(Other))
215 if (const ArrayType *OtherAT =
216 dyn_cast(OtherGV->getType()->getElementType()))
217 if (const ArrayType *ConcreteAT =
218 dyn_cast(ConcreteGV->getType()->getElementType()))
219 if (OtherAT->getElementType() == ConcreteAT->getElementType() &&
220 OtherAT->getNumElements() == 0)
221 DontPrintWarning = true;
222 }
223
224 if (!DontPrintWarning) {
225 std::cerr << "WARNING: Found global types that are not compatible:\n";
226 for (unsigned i = 0; i < Globals.size(); ++i) {
227 std::cerr << "\t" << *Globals[i]->getType() << " %"
228 << Globals[i]->getName() << "\n";
229 }
201230 }
202231
203232 if (!Concrete)