[LLVMdev] Queries regarding function's arguments data type

teja tamboli tamboli.teja at gmail.com
Mon Mar 4 20:17:00 PST 2013

Hi John,

Thanks John. I tried using SequentialType::getElementType() function and it

I have one more question how can we do function permutation at intermediate
representation byte code level?

If I have lets say C program having three functions and its corresponding
IR bytecode.

void findLen(char a[10])
   int tmp = strlen(a);
   printf("Len is : %d\n", tmp);
void muladd(int a, int b, int c)
   int tmp = a + b;
   int tmp1 = tmp * c;
   printf("Addition is : %d Multiplication is : %d\n", tmp, tmp1);
   char d[10] =  "abhd";
void main()
   int x = 8, y = 5, z = 3;
   muladd(x, y, z);

In its corresponding .s / .ll IR bytecode file function sequence will be
same first findLen() then muladd() and then main(). Suppose I want to
change this sequence i.e. swap findLen() and muladd() function's positions.
I am expecting to have IR bytecode of first muladd() then findLen() and
then main() in the output file.

Can you please tell me how can I achieve it ?


On Mon, Feb 25, 2013 at 11:54 AM, John Criswell <criswell at illinois.edu>wrote:

>  On 2/25/13 1:44 PM, teja tamboli wrote:
> Hi all,
>  I am working on my Master's project in security and I am trying to
> iterate over the argument list of the function. Basically I need to do
> following things :
> Interesting.  Just out of curiosity, can you tell us what your project is
> about?
>  1.  Check data type of each argument of the argument list of the
> function.
> 2. Based on its data type like character array or integer array, pointer,
> int, char, take different action.
> 3. I have added following code to check its data type.
> There is one caveat when working with LLVM types: the type indicates what
> the function *expects* to get as an argument; it does not represent what
> the type of the actual memory object passed into the function will be.  A
> caller can cast a pointer of one structure type to a different structure
> type and pass that into a function.
> // F is any function basically of type function *
>  FunctionType *FTy = F->getFunctionType();
> unsigned int numArgs = FTy->getNumParams();
> //Currently just checking data type of the 0th argument. Eventually will
> be running it in the loop from 0 to numArgs.
>    errs() << "\n1 Argument type int 32 : " <<
> FTy->getParamType(0)->isIntegerTy(32);
>   errs() << "\n2 Argument type char : " <<
> FTy->getParamType(0)->isIntegerTy(8);
>   errs() << "\n4 Argument type pointer : " <<
> FTy->getParamType(0)->isPointerTy();
>   errs() << "\n5 Argument type array : " <<
> FTy->getParamType(0)->isArrayTy();
>   errs() << "\n6 Argument type structure : " <<
> FTy->getParamType(0)->isStructTy();
> I can just find these many data types for integer and characters. This
> just tells me that parameter is of type pointer or array or structure.
> My question is if function's parameter type is pointer / array, how can I
> figure it out whether its character pointer or integer pointer?
> You need to use dyn_cast<SequentialType> to convert the Type * into a
> SequentialType *.  With that, you can use SequentialType::getElementType()
> to see what type of pointer type/array type it is.
> You can also use dyn_cast<> to cast to an ArrayType to get the declared
> size of the array, or to a StructType so that you can examine the structure
> type's fields.
> You should be familiar with how to use dyn_cast<>(), and you should be
> familiar with the LLVM type classes.  The former is documented in the LLVM
> Programmer's Manual, and the latter can be found within the doxygen
> documentation.
> -- John T.
> Also if it is a array then how can I find size of the array?
> In case of structure how to check exact structure definition I mean
> exactly it is instance of which structure?
> Please let me know.
> Thanks,
> --Teja
> _______________________________________________
> LLVM Developers mailing listLLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.eduhttp://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130304/be6a5baa/attachment.html>

More information about the llvm-dev mailing list