Commit f49d8c64 authored by Adéla Štěpková's avatar Adéla Štěpková
Browse files

strip pointer casts from a CallInst when identifying functions

parent 63539591
Loading
Loading
Loading
Loading
+8 −21
Original line number Diff line number Diff line
@@ -4,10 +4,7 @@

using namespace llvm;

bool identify::isAssert(const Function* F)
{
    return isAssert(F->getName());
}
bool identify::isAssert(const Function* F) { return isAssert(F->getName()); }

bool identify::isAssert(const StringRef name)
{
@@ -16,16 +13,13 @@ bool identify::isAssert(const StringRef name)

bool identify::isAssert(const CallInst* I)
{
    if (Function* calledFunc = I->getCalledFunction()) {
    if (Function* calledFunc = dyn_cast<Function>(I->getCalledOperand()->stripPointerCasts())) {
        return identify::isAssert(calledFunc);
    }
    return false;
}

bool identify::isAssume(const Function* F)
{
    return isAssume(F->getName());
}
bool identify::isAssume(const Function* F) { return isAssume(F->getName()); }

bool identify::isAssume(const StringRef name)
{
@@ -35,7 +29,7 @@ bool identify::isAssume(const StringRef name)

bool identify::isAssume(const CallInst* I)
{
    if (Function* calledFunc = I->getCalledFunction()) {
    if (Function* calledFunc = dyn_cast<Function>(I->getCalledOperand()->stripPointerCasts())) {
        return isAssume(calledFunc);
    }
    return false;
@@ -57,16 +51,13 @@ bool identify::isNondetGenerator(const StringRef name)

bool identify::isNondetGenerator(const CallInst* I)
{
    if (Function* calledFunc = I->getCalledFunction()) {
    if (Function* calledFunc = dyn_cast<Function>(I->getCalledOperand()->stripPointerCasts())) {
        return isNondetGenerator(calledFunc);
    }
    return false;
}

bool identify::isError(const Function* F)
{
    return isError(F->getName());
}
bool identify::isError(const Function* F) { return isError(F->getName()); }

bool identify::isError(const StringRef name)
{
@@ -81,10 +72,6 @@ bool identify::isSVCompInternal(const Function* F)
           identify::isNondetGenerator(funcName);
}

bool identify::isAbort(const Function* F) {
    return isAbort(F->getName());
}
bool identify::isAbort(const Function* F) { return isAbort(F->getName()); }

bool identify::isAbort(const StringRef name) {
    return name == "abort";
}
 No newline at end of file
bool identify::isAbort(const StringRef name) { return name == "abort"; }
 No newline at end of file
+9 −9
Original line number Diff line number Diff line
@@ -683,18 +683,24 @@ public:
    void visitCallInst(CallInst& I)
    {
        // outs() << I << '\n';
        if (identify::isNondetGenerator(&I)) {

        auto* origCalledVal = I.getCalledOperand()->stripPointerCasts();
        Function* origCalledFunc = dyn_cast<Function>(origCalledVal);
        assert(origCalledFunc && "function called in CallInst not identified");
        // outs() << *origCalledFunc << '\n';

        if (identify::isNondetGenerator(origCalledFunc)) {
            return; // reverse calls to generators do not have any effect anyway
        }

        if (identify::isAssert(&I) || identify::isAssume(&I)) {
        if (identify::isAssert(origCalledFunc) || identify::isAssume(origCalledFunc)) {
            // assert needs to be turned into assume
            auto* origAssertCond = I.getArgOperand(0);
            assert(origAssertCond && "assert call has 0 operands");
            auto* revAssertCond = getInitializedValue(origAssertCond);
            auto* assume = instBuilder.addAssumePlaceholder(revAssertCond);

            if (identify::isAssert(&I)) {
            if (identify::isAssert(origCalledFunc)) {
                directAsserts[&I] = assume;
            }
            // instBuilder.printMapForBB(assume->getParent());
@@ -702,12 +708,6 @@ public:
        }

        // reverse the call: arguments are return values, return values are arguments

        auto* origCalledVal = I.getCalledOperand()->stripPointerCasts();
        Function* origCalledFunc = llvm::dyn_cast<llvm::Function>(origCalledVal);
        assert(origCalledFunc && "function called in CallInst not identified");

        // outs() << origCalledFunc->getName() << '\n';
        auto* revCalledFunc = funcMap.at(origCalledFunc).revFunction;
        int origNumArgs = origCalledFunc->getFunctionType()->getNumParams();