error: incomplete type 'llvm::CallInst' named in nested name specifier

Hello,

I am trying to write a pass. Here is a short and simplified version of it
bool MyPass:: runOnFunction( Function &F){
errs() << "Visiting function " << F.getName();
errs() << “\n”;

for (auto &BB : F) {
for (auto &II : BB) {
if (CallInst *c = dyn_cast (&II)){

}
}
}
return false; // We did not change anything in the IR
}

The code is straight forward and very much in line with the examples LLVM pass on the web.

However, when I compile it, I am getting the following error.

In file included from MyPass.cpp:1:
In file included from /home/amalik/LLVM/llvm-8.0.0.src/include/llvm/Pass.h:365:
In file included from /home/amalik/LLVM/llvm_install/include/llvm/PassSupport.h:26:
In file included from /home/amalik/LLVM/llvm_install/include/llvm/PassRegistry.h:23:
In file included from /home/amalik/LLVM/llvm_install/include/llvm/Support/CBindingWrapping.h:18:
/home/amalik/LLVM/llvm_install/include/llvm/Support/Casting.h:59:12: error: incomplete type ‘llvm::CallInst’ named in nested name
specifier
return To::classof(&Val);
^~~~
/home/amalik/LLVM/llvm_install/include/llvm/Support/Casting.h:107:32: note: in instantiation of member function
‘llvm::isa_impl<llvm::CallInst, llvm::Instruction, void>::doit’ requested here
return isa_impl<To, From>::doit(*Val);
^
/home/amalik/LLVM/llvm_install/include/llvm/Support/Casting.h:133:36: note: in instantiation of member function
‘llvm::isa_impl_cl<llvm::CallInst, const llvm::Instruction *>::doit’ requested here
return isa_impl_cl<To,FromTy>::doit(Val);
^
/home/amalik/LLVM/llvm_install/include/llvm/Support/Casting.h:124:56: note: in instantiation of member function
‘llvm::isa_impl_wrap<llvm::CallInst, const llvm::Instruction *, const llvm::Instruction *>::doit’ requested here
typename simplify_type::SimpleType>::doit(
^
/home/amalik/LLVM/llvm_install/include/llvm/Support/Casting.h:144:70: note: in instantiation of member function
‘llvm::isa_impl_wrap<llvm::CallInst, llvm::Instruction *const, const llvm::Instruction *>::doit’ requested here
typename simplify_type::SimpleType>::doit(Val);
^
/home/amalik/LLVM/llvm_install/include/llvm/Support/Casting.h:334:10: note: in instantiation of function template specialization
‘llvm::isa<llvm::CallInst, llvm::Instruction *>’ requested here
return isa(Val) ? cast(Val) : nullptr;
^
DummyPass.cpp:30:21: note: in instantiation of function template specialization ‘llvm::dyn_cast<llvm::CallInst, llvm::Instruction>’
requested here
if (CallInst *c = dyn_cast (&II)){
^
/home/amalik/LLVM/llvm_install/include/llvm/IR/BasicBlock.h:35:7: note: forward declaration of ‘llvm::CallInst’
class CallInst;
^
1 error generated

------>

Thanks,

Looks like you forgot to include the header that defined CallInst. You
need that to be able to do most things with it, including (as you've
discovered) an RTTI-based cast. In this case the header is
"llvm/IR/Instructions.h".

Cheers.

Tim.