Skip to content

Commit

Permalink
blah
Browse files Browse the repository at this point in the history
  • Loading branch information
ragusaa committed Apr 23, 2024
1 parent 4d60675 commit 9ee2941
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 76 deletions.
19 changes: 8 additions & 11 deletions libclambcc/ClamBCRebuild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,16 @@ class ClamBCRebuild : public PassInfoMixin<ClamBCRebuild>, public InstVisitor<Cl
return NV;
}

/* findDuplicateType looks through all the casts of a value to find if it
* is ultimately being casted to a type that it is already casted from.
* If that is the case, it just returns the original, instead of creating
* another cast.
*
* In addition to being inefficient, the excessive casting was causing
* issues in 0.103 and 0.105.
*/
Value * findDuplicateType(Value * v, Type * t){
if (BitCastInst * bci = llvm::dyn_cast<BitCastInst>(v)){
//DEBUG_VALUE(bci->getOperand(0));
//DEBUG_VALUE(bci->getOperand(0)->getType());
//DEBUG_VALUE(bci->getSrcTy());
//DEBUG_VALUE(t);
if (bci->getSrcTy() == t){
return bci->getOperand(0);
}
Expand All @@ -323,18 +327,11 @@ class ClamBCRebuild : public PassInfoMixin<ClamBCRebuild>, public InstVisitor<Cl
Value *makeCast(Value *V, Type *Ty)
{

//looking for concat_var
//DEBUG_VALUE(V);
//DEBUG_VALUE(Ty);
Value * v = findDuplicateType(V, Ty);
if (v){
//DEBUG_VALUE(v);
return v;
}




if (V->getType() == Ty) {
return V;
}
Expand Down
65 changes: 1 addition & 64 deletions libclambcc/ClamBCVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,6 @@ class ClamBCVerifier : public PassInfoMixin<ClamBCVerifier>,
Function *getCalledFunctionFromCallInst(CallInst *pci)
{

{
/*
* Issue is in 'memstr'.
*
* The 'needle' is not correct in the earlier versions.
*/
llvm::errs() << "<" << __LINE__ << ">" << "TODO: Clean this up!!!" << "<END>\n";
Value * pCalledOperand = pci->getCalledOperand();
Function * ret = llvm::dyn_cast<Function>(pCalledOperand);
if (nullptr == ret){
Expand All @@ -179,65 +172,9 @@ class ClamBCVerifier : public PassInfoMixin<ClamBCVerifier>,
}

if (nullptr == ret){
assert (0 && "still got work to do ");
ClamBCStop("Verifier unable to get called function from call instruction", pci);
}

return ret;
}



DEBUG_VALUE(pci);
Function *ret = pci->getCalledFunction();
if (nullptr == ret) {
DEBUG_VALUE(pci);
Value *v = pci->getOperand(0); /*This is the called operand.*/
if (nullptr == v) {
llvm::errs() << "<" << __LINE__ << ">" << *pci << "<END>\n";
llvm::errs() << "<" << __LINE__ << ">" << *(pci->getOperand(0)) << "<END>\n";
assert(0 && "How do I handle function pointers?");
}

for (size_t i = 0; i< pci->getNumOperands(); i++){
DEBUG_VALUE(pci->getOperand(i));
}
llvm::errs() << "\n";
llvm::errs() << "\n";
llvm::errs() << "\n";


DEBUG_VALUE(pci->getCalledOperand());
llvm::errs() << "\n";
llvm::errs() << "\n";
llvm::errs() << "\n";



exit(11);
#if 0




while (1){

if (BitCastOperator *bco = llvm::dyn_cast<BitCastOperator>(v)) {
ret = llvm::dyn_cast<Function>(bco->getOperand(0));
} else if (GEPOperator * pgpe = llvm::dyn_cast<GEPOperator>(v)) {
ret = llvm::dyn_cast<Function>(pgpe->getPointerOperand());
} else {
DEBUG_VALUE(v);
DEBUG_NONPOINTER(llvm::isa<GEPOperator>(v));
assert (0 && "WTF");
}
}



#endif

}

return ret;
}

Expand Down
1 change: 0 additions & 1 deletion libclambcc/ClamBCWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1337,7 +1337,6 @@ class ClamBCWriter : public PassInfoMixin<ClamBCWriter>, public InstVisitor<Clam

void visitCallInst(CallInst &CI)
{
//DEBUG_VALUE(&CI);
Function *F = CI.getCalledFunction();
if (!F) {
stop("Indirect calls are not implemented yet!", &CI);
Expand Down

0 comments on commit 9ee2941

Please sign in to comment.