2016-09-14 5 views
1

LLVM StoreInstのストアターゲットがファンクションポインタであるかどうかをチェックする方法は?LLVM StoreInstのターゲットがファンクションポインタであるかどうかをチェックする方法

+0

保存先の種類を意味していますか?または、その場所が関数ポインタのエイリアスかどうか? – Brian

+0

私は、rvalueが格納されている場所のタイプを意味します。 – Razer

答えて

2

LLVMロード/ストア命令が与えられると、計算する2つの別個の部分がある。まず、場所の種類は何ですか。第2に、そのタイプは一定の特性などを満たすかどうか。

if (StoreInst *si = dyn_cast<StoreInst>(&*I)) 
{ 
    Value* v = si->getPointerOperand(); 
    Type* ptrType = v->getType()->getPointerElementType(); 

ここで、ポインタタイプは、データが格納されているタイプです。しかし、基になる型が実際に関数であるかどうかを知りたいので、これを関数ポインタ(またはポインタポインタなど)にします。 store i8* (i8*)* @tFunc, i8* (i8*)** %8, align 8、別の場所にtFuncを関数へのポインタを格納する -

if (PointerType* pt = dyn_cast<PointerType>(ptrType)) 
    { 
     do { 
      // The call to getTypeAtIndex has to be made on a composite type 
      // And needs explicitly an unsigned int, otherwise 0 
      // can ambiguously be NULL. 
      Type* pointedType = pt->getTypeAtIndex((unsigned int)0); 
      if (pointedType->isFunctionTy()) 
      { 
       errs() << "Found the underlying function type\n"; 
       break; 
      } 

      // This may be a pointer to a pointer to ... 
      ptrType = pointedType; 
     } while (pt = dyn_cast<PointerType>(ptrType)); 

このコードは、次のストアを検出します。

関連する問題