Search code examples
llvmllvm-clang

Check for printf in call instruction


 %1 = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([22 x i8]* @.str, i64 0, i64 0), i32 7) #3

For the above instruction, how can I check whether the call instruction contains printf ?


Solution

  • Just compare the name of the called function:

    bool isPrintfCall(CallInst &C) {
       auto *F = C.getCalledFunction();
       auto isPrintf = (F->getName() == "printf");
       return isPrintf;
    }