c++ - How to get the arguments of a function pointer from a CallExpr in Clang? -
i trying analyse c source code function calls within them. able analyse normal function calls arguments without problem using source code below ce callexpr
object:
1. if(ce != null) { 2. qualtype q = ce->gettype(); 3. const type *t = q.gettypeptrornull(); 4. 5. if (t != null) { 6. llvm::errs() << "type: " << t->isfunctionpointertype() << " " << q.getasstring() << " " << t->ispointertype() << "\n"; 7. } else { 8. llvm::errs() << "function ce has no type?\n"; 9. } 10. 11. 12. const decl* d = ce ->getcalleedecl(); 13. while(d->getpreviousdecl() != null) 14. d = d->getpreviousdecl(); 15. 16. llvm::errs() << "kind: " << d->getdeclkindname() << "\n"; 17. 18. functiondecl* fd = (functiondecl*) llvm::dyn_cast<functiondecl>(d); 19. for(int x = 0; x< fd ->getnumparams(); x++) { 20. if(fd ->getparamdecl(x)->gettype()->isanypointertype()) { 21. // stuff here 22. } 23. } 24. }
the problem above source code comes on line 18, when try typecast decl callexpr
functiondecl
, results in fd becoming null
if callexpr
function pointer call.
i tried debug trying print kind on line 16. function pointers, specifies decl on 12
vardecl
, not functiondecl normal function calls.
i tried using isfunctionpointertype()
, returning false.
here piece of source code results in segfault:
#include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { void* (*mp)(size_t size); void *mpp; mp = &malloc; mpp = mp(30); free(mpp); return (0); }
is there way using clang detect whether callexpr
function pointer call? , if so, how list of arguments?
i using clang 3.1
thanks
use getdirectcallee()
function (i not sure if available in clang 3.1
or not) functiondecl *func = ce->getdirectcallee();
if (func != null){ for(int = 0; < func->getnumparams(); i++){ if(func->getparamdecl(i)->gettype()->isfunctionpointertype()){ // stuff here } } }
Comments
Post a Comment