[LLVMdev] Re : How do I find all memory allocations in an llvm ir code file?

Matthieu Wipliez mwipliez at yahoo.fr
Fri Oct 15 05:42:00 PDT 2010


Hi Theresia,

I am no LLVM expert, but c++filt indicates that _Znwj and _Znaj are the mangled 
names for new and new[] operators respectively:

$ c++filt __Znwj
operator new(unsigned int)

$ c++filt __Znaj
operator new[](unsigned int)

Hope this helps,
Matthieu



----- Message d'origine ----
> De : Theresia Hansson <theresia.hansson at gmail.com>
> À : llvmdev at cs.uiuc.edu
> Envoyé le : Ven 15 octobre 2010, 13h 37min 37s
> Objet : [LLVMdev] How do I find all memory allocations in an llvm ir code 
file?
> 
> I tried to compile this snippet of C++ code:
> 
> void FuncTest() {
>      int* a = new int;
>     int* b = new int[2];
> }
> 
> using:
> 
> clang  test.cpp -S -emit-llvm -o - > test.llvm
> 
> and obtained  this:
> 
> define void @_Z8FuncTestv() {
> entry:
>   %a = alloca i32*,  align 4
>   %b = alloca i32*, align 4
>   %call = call noalias i8* @_Znwj(i32  4)
>   %0 = bitcast i8* %call to i32*
>   store i32* %0, i32** %a, align  4
>   %call1 = call noalias i8* @_Znaj(i32 8)
>   %1 = bitcast i8* %call1 to  i32*
>   store i32* %1, i32** %b, align 4
>   ret void
> }
> 
> declare  noalias i8* @_Znwj(i32)
> declare noalias i8* @_Znaj(i32)
> 
> What I am  wondering now is: where do the _Znwj and _Znaj symbols come
> from? Are they  just randomly assigned or is there a system to it? I
> would like to be able to  tell that the lines
> 
> %call = call noalias i8* @_Znwj(i32  4)
> 
> and
> 
> %call1 = call noalias i8* @_Znaj(i32 8)
> 
> perform  memory allocations. But it does not look that promising...
> Some llvm expert  here who has an  idea?
> 
> _______________________________________________
> LLVM Developers  mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
> 


      




More information about the llvm-dev mailing list