[llvm-commits] CVS: llvm/lib/Analysis/DataStructure/Local.cpp

Chris Lattner lattner at cs.uiuc.edu
Mon Feb 16 16:58:02 PST 2004


Changes in directory llvm/lib/Analysis/DataStructure:

Local.cpp updated: 1.83 -> 1.84

---
Log message:

Only spit out warning for functions that take pointers, not for sin and the like
Add more special case handling for stdio functions.  I feel dirty, how about you?


---
Diffs of the changes:  (+25 -5)

Index: llvm/lib/Analysis/DataStructure/Local.cpp
diff -u llvm/lib/Analysis/DataStructure/Local.cpp:1.83 llvm/lib/Analysis/DataStructure/Local.cpp:1.84
--- llvm/lib/Analysis/DataStructure/Local.cpp:1.83	Mon Feb 16 12:37:40 2004
+++ llvm/lib/Analysis/DataStructure/Local.cpp	Mon Feb 16 16:57:19 2004
@@ -484,6 +484,12 @@
           if (DSNode *N = RetNH.getNode())
             N->setHeapNodeMarker()->setModifiedMarker()->setReadMarker();
           return;
+        } else if (F->getName() == "atoi") {
+          // atoi reads its argument.
+          if (DSNode *N = getValueDest(**CS.arg_begin()).getNode())
+            N->setReadMarker();
+          return;
+
         } else if (F->getName() == "fopen" && CS.arg_end()-CS.arg_begin() == 2){
           // fopen reads the mode argument strings.
           CallSite::arg_iterator AI = CS.arg_begin();
@@ -511,8 +517,11 @@
           if (const PointerType *PTy = dyn_cast<PointerType>(ArgTy))
             H.getNode()->mergeTypeInfo(PTy->getElementType(), H.getOffset());
           return;
-        } else if (F->getName() == "fflush" && CS.arg_end()-CS.arg_begin() ==1){
-          // fclose reads and writes the memory for the file descriptor.  It
+        } else if (CS.arg_end()-CS.arg_begin() == 1 && 
+                   (F->getName() == "fflush" || F->getName() == "feof" ||
+                    F->getName() == "fileno" || F->getName() == "clearerr" ||
+                    F->getName() == "rewind" || F->getName() == "ftell")) {
+          // fflush reads and writes the memory for the file descriptor.  It
           // merges the FILE type into the descriptor.
           DSNodeHandle H = getValueDest(**CS.arg_begin());
           H.getNode()->setReadMarker()->setModifiedMarker();
@@ -522,7 +531,7 @@
             H.getNode()->mergeTypeInfo(PTy->getElementType(), H.getOffset());
           return;
         } else if (F->getName() == "fgets" && CS.arg_end()-CS.arg_begin() == 3){
-          // fclose reads and writes the memory for the file descriptor.  It
+          // fgets reads and writes the memory for the file descriptor.  It
           // merges the FILE type into the descriptor, and writes to the
           // argument.  It returns the argument as well.
           CallSite::arg_iterator AI = CS.arg_begin();
@@ -565,8 +574,19 @@
         } else if (F->getName() == "exit") {
           // Nothing to do!
         } else {
-          std::cerr << "WARNING: Call to unknown external function '"
-                    << F->getName() << "' will cause pessimistic results!\n";
+          // Unknown function, warn if it returns a pointer type or takes a
+          // pointer argument.
+          bool Warn = isPointerType(CS.getInstruction()->getType());
+          if (!Warn)
+            for (CallSite::arg_iterator I = CS.arg_begin(), E = CS.arg_end();
+                 I != E; ++I)
+              if (isPointerType((*I)->getType())) {
+                Warn = true;
+                break;
+              }
+          if (Warn)
+            std::cerr << "WARNING: Call to unknown external function '"
+                      << F->getName() << "' will cause pessimistic results!\n";
         }
       }
 





More information about the llvm-commits mailing list