1
votes

Given some source code, I would like to create an llvm pass that extracts the information related to all the functions parameter list. How can I extract the size of an array passed as input to a function?

For example:

foo(int A[100]){
 ...
}

I would like to obtain the following information: 1) Type of the elements in the array 2) Size of the array (in the case of a multidimensional array the sizes associated with the different dimensions).

In my llvm pass I have a function that given a llvm::Type in input checks which kind of type it is and extracts the information that I need and, if needed, recursively call itself to analyze other Type elements:

if ( argType->isPointerTy() ){
    errs() << "Is a pointer.\n";
    Type *Pointer_Type = argType->getPointerElementType();
    IdentifyArgType(Pointer_Type);
}

However, with this function I am able to obtain only the information realated to the type of the array (int). How can I extract the size of the array?

My guess is that I have to retrieve the llvm::Type of the pointed element but I cannot figure out how to have access to that object.

1
@WeatherVane: The question is not about C or C++ semantics. It is about LLVM data. - Eric Postpischil
Thanks, I've just changed the tag. - Lorenzo Ferretti

1 Answers

0
votes

Try to cast the parameter type to ArrayType (not the element type) and then use getNumElements function. See http://llvm.org/doxygen/classllvm_1_1ArrayType.html