[llvm-commits] CVS: llvm/lib/Transforms/IPO/FunctionResolution.cpp

Chris Lattner lattner at cs.uiuc.edu
Wed Oct 22 18:04:01 PDT 2003


Changes in directory llvm/lib/Transforms/IPO:

FunctionResolution.cpp updated: 1.41 -> 1.42

---
Log message:

This important patch fixes two warnings in the linker which can occur from linking
valid pieces of code


---
Diffs of the changes:  (+33 -4)

Index: llvm/lib/Transforms/IPO/FunctionResolution.cpp
diff -u llvm/lib/Transforms/IPO/FunctionResolution.cpp:1.41 llvm/lib/Transforms/IPO/FunctionResolution.cpp:1.42
--- llvm/lib/Transforms/IPO/FunctionResolution.cpp:1.41	Tue Oct 21 23:43:18 2003
+++ llvm/lib/Transforms/IPO/FunctionResolution.cpp	Wed Oct 22 18:03:38 2003
@@ -194,11 +194,40 @@
     if (!HasExternal && NumInstancesWithExternalLinkage <= 1)
       return false;  // Nothing to do?  Must have multiple internal definitions.
 
+    // There are a couple of special cases we don't want to print the warning
+    // for, check them now.
+    bool DontPrintWarning = false;
+    if (Concrete && Globals.size() == 2) {
+      GlobalValue *Other = Globals[Globals[0] == Concrete];
+      // If the non-concrete global is a function which takes (...) arguments,
+      // and the return values match, do not warn.
+      if (Function *ConcreteF = dyn_cast<Function>(Concrete))
+        if (Function *OtherF = dyn_cast<Function>(Other))
+          if (ConcreteF->getReturnType() == OtherF->getReturnType() &&
+              OtherF->getFunctionType()->isVarArg() &&
+              OtherF->getFunctionType()->getParamTypes().empty())
+            DontPrintWarning = true;
+      
+      // Otherwise, if the non-concrete global is a global array variable with a
+      // size of 0, and the concrete global is an array with a real size, don't
+      // warn.  This occurs due to declaring 'extern int A[];'.
+      if (GlobalVariable *ConcreteGV = dyn_cast<GlobalVariable>(Concrete))
+        if (GlobalVariable *OtherGV = dyn_cast<GlobalVariable>(Other))
+          if (const ArrayType *OtherAT =
+              dyn_cast<ArrayType>(OtherGV->getType()->getElementType()))
+            if (const ArrayType *ConcreteAT =
+                dyn_cast<ArrayType>(ConcreteGV->getType()->getElementType()))
+              if (OtherAT->getElementType() == ConcreteAT->getElementType() &&
+                  OtherAT->getNumElements() == 0)
+                DontPrintWarning = true;
+    }
 
-    std::cerr << "WARNING: Found global types that are not compatible:\n";
-    for (unsigned i = 0; i < Globals.size(); ++i) {
-      std::cerr << "\t" << *Globals[i]->getType() << " %"
-                << Globals[i]->getName() << "\n";
+    if (!DontPrintWarning) {
+      std::cerr << "WARNING: Found global types that are not compatible:\n";
+      for (unsigned i = 0; i < Globals.size(); ++i) {
+        std::cerr << "\t" << *Globals[i]->getType() << " %"
+                  << Globals[i]->getName() << "\n";
+      }
     }
 
     if (!Concrete)





More information about the llvm-commits mailing list