How to recognize pointer variable & ordinary variable? I have tried with “isa(V->getType())”, but failed.
Hi Soumya_Prasad_Ukil,
How to recognize pointer variable & ordinary variable? I have tried with
"isa<PointerType>(V->getType())", but failed.
I'm not sure what you are asking, but if you are asking whether an
alloca instruction A represents local memory of pointer type, you
can use A->getAllocatedType(). You can also use
cast<PointerType>(A->getType())->getElementType(). The reason that
an alloca instruction always has pointer type is that the instruction
represents a pointer to the allocated memory.
Ciao,
Duncan.
Your last statement is correct. But still my stand does not change. I want to differentiate ordinary local variable & pointer variables.
Let’s have a program,
int a,b,c,*ptr;
I want to extract only the local variables. That’s what my question was. I think it is clear now. cast(A->getType()
Hi Soumya_Prasad_Ukil,
Your last statement is correct. But still my stand does not change. I
want to differentiate ordinary local variable & pointer variables.
Let's have a program,
int a,b,c,*ptr;
This is not LLVM IR.
I want to extract only the local variables. That's what my question was.
I think it is clear now. cast<PointerType>(A->getType())->getElementType() is not working.
I should have said: isa<PointerType>(cast<PointerType>(A->getType())->getElementType())
(forgot the pointer type test)
I am also getting error with
A->getAllocatedType().
If you look closely you will see I said you can do this with an alloca
instruction. It will not compile if you have something else. If you only\
have a Value*, you can do this: isa<PointerType>(cast<AllocaInst>(V)->getAllocatedType())
Ciao,
Duncan.