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

Chris Lattner lattner at cs.uiuc.edu
Fri Feb 13 14:06:12 PST 2004


Changes in directory llvm/lib/Analysis/DataStructure:

Local.cpp updated: 1.79 -> 1.80

---
Log message:

Add support for fopen/fclose.  Specifically with fopen, we were marking all of the
operands as incomplete, though fopen is known to only read them.  This just adds
fclose for symmetry, though it doesn't gain anything.  This makes the dsgraphs for
181.mcf much more precise.


---
Diffs of the changes:  (+27 -0)

Index: llvm/lib/Analysis/DataStructure/Local.cpp
diff -u llvm/lib/Analysis/DataStructure/Local.cpp:1.79 llvm/lib/Analysis/DataStructure/Local.cpp:1.80
--- llvm/lib/Analysis/DataStructure/Local.cpp:1.79	Fri Feb 13 10:09:54 2004
+++ llvm/lib/Analysis/DataStructure/Local.cpp	Fri Feb 13 14:05:32 2004
@@ -493,6 +493,33 @@
           if (DSNode *N = H.getNode())
             N->setModifiedMarker();
           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();
+          DSNodeHandle Path = getValueDest(**AI);
+          DSNodeHandle Mode = getValueDest(**++AI);
+          if (DSNode *N = Path.getNode()) N->setReadMarker();
+          if (DSNode *N = Mode.getNode()) N->setReadMarker();
+          
+          // fopen allocates in an unknown way and writes to the file
+          // descriptor.  Also, merge the allocated type into the node.
+          DSNodeHandle Result = getValueDest(*CS.getInstruction());
+          Result.getNode()->setModifiedMarker()->setUnknownNodeMarker();
+          const Type *RetTy = F->getFunctionType()->getReturnType();
+          if (const PointerType *PTy = dyn_cast<PointerType>(RetTy))
+            Result.getNode()->mergeTypeInfo(PTy->getElementType(),
+                                            Result.getOffset());
+          return;
+        } else if (F->getName() == "fclose" && CS.arg_end()-CS.arg_begin() ==1){
+          // fclose reads and deallocates the memory in an unknown way for the
+          // file descriptor.  It merges the FILE type into the descriptor.
+          DSNodeHandle H = getValueDest(**CS.arg_begin());
+          H.getNode()->setReadMarker()->setUnknownNodeMarker();
+          
+          const Type *ArgTy = *F->getFunctionType()->param_begin();
+          if (const PointerType *PTy = dyn_cast<PointerType>(ArgTy))
+            H.getNode()->mergeTypeInfo(PTy->getElementType(), H.getOffset());
+          return;
         }
       }
 





More information about the llvm-commits mailing list