mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-14 02:33:53 +00:00
Add support for remove, fwrite, and fread
Also fix problem where we didn't check to see if a node pointer was null. Though fclose(null) doesn't make a lot of sense, 300.twolf does it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11810 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
878be7dbe9
commit
d561209a47
@ -483,7 +483,8 @@ void GraphBuilder::visitCallSite(CallSite CS) {
|
|||||||
if (DSNode *N = RetNH.getNode())
|
if (DSNode *N = RetNH.getNode())
|
||||||
N->setHeapNodeMarker()->setModifiedMarker()->setReadMarker();
|
N->setHeapNodeMarker()->setModifiedMarker()->setReadMarker();
|
||||||
return;
|
return;
|
||||||
} else if (F->getName() == "atoi" || F->getName() == "atof") {
|
} else if (F->getName() == "atoi" || F->getName() == "atof" ||
|
||||||
|
F->getName() == "remove") {
|
||||||
// atoi reads its argument.
|
// atoi reads its argument.
|
||||||
if (DSNode *N = getValueDest(**CS.arg_begin()).getNode())
|
if (DSNode *N = getValueDest(**CS.arg_begin()).getNode())
|
||||||
N->setReadMarker();
|
N->setReadMarker();
|
||||||
@ -500,21 +501,30 @@ void GraphBuilder::visitCallSite(CallSite CS) {
|
|||||||
// fopen allocates in an unknown way and writes to the file
|
// fopen allocates in an unknown way and writes to the file
|
||||||
// descriptor. Also, merge the allocated type into the node.
|
// descriptor. Also, merge the allocated type into the node.
|
||||||
DSNodeHandle Result = getValueDest(*CS.getInstruction());
|
DSNodeHandle Result = getValueDest(*CS.getInstruction());
|
||||||
Result.getNode()->setModifiedMarker()->setUnknownNodeMarker();
|
if (DSNode *N = Result.getNode()) {
|
||||||
|
N->setModifiedMarker()->setUnknownNodeMarker();
|
||||||
const Type *RetTy = F->getFunctionType()->getReturnType();
|
const Type *RetTy = F->getFunctionType()->getReturnType();
|
||||||
if (const PointerType *PTy = dyn_cast<PointerType>(RetTy))
|
if (const PointerType *PTy = dyn_cast<PointerType>(RetTy))
|
||||||
Result.getNode()->mergeTypeInfo(PTy->getElementType(),
|
N->mergeTypeInfo(PTy->getElementType(), Result.getOffset());
|
||||||
Result.getOffset());
|
}
|
||||||
|
return;
|
||||||
|
} else if (F->getName() == "memcmp" && CS.arg_end()-CS.arg_begin() ==3){
|
||||||
|
// memcmp reads the memory pointed to by the first two operands.
|
||||||
|
if (DSNode *N = getValueDest(**CS.arg_begin()).getNode())
|
||||||
|
N->setReadMarker();
|
||||||
|
if (DSNode *N = getValueDest(**++CS.arg_begin()).getNode())
|
||||||
|
N->setReadMarker();
|
||||||
return;
|
return;
|
||||||
} else if (F->getName() == "fclose" && CS.arg_end()-CS.arg_begin() ==1){
|
} else if (F->getName() == "fclose" && CS.arg_end()-CS.arg_begin() ==1){
|
||||||
// fclose reads and deallocates the memory in an unknown way for the
|
// fclose reads and deallocates the memory in an unknown way for the
|
||||||
// file descriptor. It merges the FILE type into the descriptor.
|
// file descriptor. It merges the FILE type into the descriptor.
|
||||||
DSNodeHandle H = getValueDest(**CS.arg_begin());
|
DSNodeHandle H = getValueDest(**CS.arg_begin());
|
||||||
H.getNode()->setReadMarker()->setUnknownNodeMarker();
|
if (DSNode *N = H.getNode()) {
|
||||||
|
N->setReadMarker()->setUnknownNodeMarker();
|
||||||
const Type *ArgTy = *F->getFunctionType()->param_begin();
|
const Type *ArgTy = F->getFunctionType()->getParamType(0);
|
||||||
if (const PointerType *PTy = dyn_cast<PointerType>(ArgTy))
|
if (const PointerType *PTy = dyn_cast<PointerType>(ArgTy))
|
||||||
H.getNode()->mergeTypeInfo(PTy->getElementType(), H.getOffset());
|
N->mergeTypeInfo(PTy->getElementType(), H.getOffset());
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
} else if (CS.arg_end()-CS.arg_begin() == 1 &&
|
} else if (CS.arg_end()-CS.arg_begin() == 1 &&
|
||||||
(F->getName() == "fflush" || F->getName() == "feof" ||
|
(F->getName() == "fflush" || F->getName() == "feof" ||
|
||||||
@ -523,11 +533,32 @@ void GraphBuilder::visitCallSite(CallSite CS) {
|
|||||||
// fflush reads and writes the memory for the file descriptor. It
|
// fflush reads and writes the memory for the file descriptor. It
|
||||||
// merges the FILE type into the descriptor.
|
// merges the FILE type into the descriptor.
|
||||||
DSNodeHandle H = getValueDest(**CS.arg_begin());
|
DSNodeHandle H = getValueDest(**CS.arg_begin());
|
||||||
H.getNode()->setReadMarker()->setModifiedMarker();
|
if (DSNode *N = H.getNode()) {
|
||||||
|
N->setReadMarker()->setModifiedMarker();
|
||||||
|
|
||||||
const Type *ArgTy = *F->getFunctionType()->param_begin();
|
const Type *ArgTy = F->getFunctionType()->getParamType(0);
|
||||||
if (const PointerType *PTy = dyn_cast<PointerType>(ArgTy))
|
if (const PointerType *PTy = dyn_cast<PointerType>(ArgTy))
|
||||||
H.getNode()->mergeTypeInfo(PTy->getElementType(), H.getOffset());
|
N->mergeTypeInfo(PTy->getElementType(), H.getOffset());
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
} else if (CS.arg_end()-CS.arg_begin() == 4 &&
|
||||||
|
(F->getName() == "fwrite" || F->getName() == "fread")) {
|
||||||
|
// fread writes the first operand, fwrite reads it. They both
|
||||||
|
// read/write the FILE descriptor, and merges the FILE type.
|
||||||
|
DSNodeHandle H = getValueDest(**--CS.arg_end());
|
||||||
|
if (DSNode *N = H.getNode()) {
|
||||||
|
N->setReadMarker()->setModifiedMarker();
|
||||||
|
const Type *ArgTy = F->getFunctionType()->getParamType(3);
|
||||||
|
if (const PointerType *PTy = dyn_cast<PointerType>(ArgTy))
|
||||||
|
N->mergeTypeInfo(PTy->getElementType(), H.getOffset());
|
||||||
|
}
|
||||||
|
|
||||||
|
H = getValueDest(**CS.arg_begin());
|
||||||
|
if (DSNode *N = H.getNode())
|
||||||
|
if (F->getName() == "fwrite")
|
||||||
|
N->setReadMarker();
|
||||||
|
else
|
||||||
|
N->setModifiedMarker();
|
||||||
return;
|
return;
|
||||||
} else if (F->getName() == "fgets" && CS.arg_end()-CS.arg_begin() == 3){
|
} else if (F->getName() == "fgets" && CS.arg_end()-CS.arg_begin() == 3){
|
||||||
// fgets reads and writes the memory for the file descriptor. It
|
// fgets reads and writes the memory for the file descriptor. It
|
||||||
@ -542,11 +573,12 @@ void GraphBuilder::visitCallSite(CallSite CS) {
|
|||||||
|
|
||||||
// Reads and writes file descriptor, merge in FILE type.
|
// Reads and writes file descriptor, merge in FILE type.
|
||||||
H = getValueDest(**CS.arg_begin());
|
H = getValueDest(**CS.arg_begin());
|
||||||
if (DSNode *N = H.getNode())
|
if (DSNode *N = H.getNode()) {
|
||||||
N->setReadMarker()->setModifiedMarker();
|
N->setReadMarker()->setModifiedMarker();
|
||||||
const Type *ArgTy = *(F->getFunctionType()->param_begin()+2);
|
const Type *ArgTy = *(F->getFunctionType()->param_begin()+2);
|
||||||
if (const PointerType *PTy = dyn_cast<PointerType>(ArgTy))
|
if (const PointerType *PTy = dyn_cast<PointerType>(ArgTy))
|
||||||
H.getNode()->mergeTypeInfo(PTy->getElementType(), H.getOffset());
|
N->mergeTypeInfo(PTy->getElementType(), H.getOffset());
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
} else if (F->getName() == "printf" || F->getName() == "fprintf" ||
|
} else if (F->getName() == "printf" || F->getName() == "fprintf" ||
|
||||||
F->getName() == "sprintf") {
|
F->getName() == "sprintf") {
|
||||||
@ -688,9 +720,8 @@ void GraphBuilder::visitCallSite(CallSite CS) {
|
|||||||
|
|
||||||
void GraphBuilder::visitFreeInst(FreeInst &FI) {
|
void GraphBuilder::visitFreeInst(FreeInst &FI) {
|
||||||
// Mark that the node is written to...
|
// Mark that the node is written to...
|
||||||
DSNode *N = getValueDest(*FI.getOperand(0)).getNode();
|
if (DSNode *N = getValueDest(*FI.getOperand(0)).getNode())
|
||||||
N->setModifiedMarker();
|
N->setModifiedMarker()->setHeapNodeMarker();
|
||||||
N->setHeapNodeMarker();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handle casts...
|
/// Handle casts...
|
||||||
|
Loading…
x
Reference in New Issue
Block a user