Hi all,
so I’m working on a simple LLVM plugin and I need some help to identify the type of instruction. The ll
is roughly the following:
; ModuleID = 'globalString.bc'
source_filename = "llvm-link"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"
@.str = private unnamed_addr constant [12 x i8] c"Hello Hello\00", align 1
@string = dso_local global i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i32 0, i32 0), align 8
; Function Attrs: noinline nounwind optnone uwtable
define dso_local i32 @main() #0 {
...
%3 = load i8*, i8** @string, align 8
...
Inside the visitLoadinst
of my plugin I added the following code:
if (GlobalVariable *G = dyn_cast<GlobalVariable>(I.getOperand(0))) {
if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(G->getOperand(0))) {
I.dump();
} else {
std::cout << "Unsupported!" << "\n";
G->getOperand(0)->dump();
G->getOperand(0)->getType()->dump();
I.dump();
}
}
Unfortunately I can only see the Unsupported
message so it means it cannot be casted to a GEP
.
What kind of cast
should I use in this case? I have a feeling that the cast does not work because it is not a GEP
instruction but some sort of pointer to a GEP
.
Thanks
Alberto