Parse a Value of Struct Type to extract the item type

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Parse a Value of Struct Type to extract the item type

Yvan Roux via cfe-dev
Hello

I am working on clang codegen module to parse some information in compile time. So, here is an example LLVM Value:

{ i64, i64 } { i64 ptrtoint (void (%class.Testpm*)* @_ZN6Testpm7m_func1Ev to i64), i64 0 }

I want to parse this Value so that I can check the source type using in ptrtoint casting instruction (i.e. void (%class.Testpm*)*). I have tried following:

if (isa<llvm::PtrToIntInst>(Val)) {
llvm::IntToPtrInst *iptr = dyn_cast<llvm::PtrToIntInst>(Val);
}

but it is not working. Any idea?
Open Tracking
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Parse a Value of Struct Type to extract the item type

Yvan Roux via cfe-dev
Hi

For this following code:

class Testpm {
public:
void m_func1() { cout << "m_func1\n"; }
int a;
};

void (Testpm::*pmfn)();
int orig61One_main()
{
Testpm ATestpm;

pmfn = &Testpm::m_func1;
}
the clang generates following LLVM IR for the 'pmfn = &Testpm::m_func1':

store { i64, i64 } { i64 ptrtoint (void (%class.Testpm*)* @_ZN6Testpm7m_func1Ev to i64), i64 0 }, { i64, i64 }* @pmfn, align 8

I want to add instruction after or before this to extract what have stored in 'pmfn' (the target address). What I have is the StoreInst and associated Value (source) and Address (destination). Can anyone suggest a way to solve this problem?

On Sep 25 2018, at 5:08 pm, Mustakimur Rahman Khandaker (Mustakim) <[hidden email]> wrote:

Hello

I am working on clang codegen module to parse some information in compile time. So, here is an example LLVM Value:

{ i64, i64 } { i64 ptrtoint (void (%class.Testpm*)* @_ZN6Testpm7m_func1Ev to i64), i64 0 }

I want to parse this Value so that I can check the source type using in ptrtoint casting instruction (i.e. void (%class.Testpm*)*). I have tried following:

if (isa<llvm::PtrToIntInst>(Val)) {
llvm::IntToPtrInst *iptr = dyn_cast<llvm::PtrToIntInst>(Val);
}

but it is not working. Any idea?
Open Tracking
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev