llvm cannot iterate a [3 x i8]

Hello everyone,

I am trying to “parse” a part of LLVM IR. More exactly, from

@.str = private unnamed_addr constant [3 x i8] c"DS\00", section “llvm.metadata”

I want to get “DS”. It is the single place in the whole bytecode from where I can get it. I have :


Value VV = cast(LD100->getOperand(1)->getOperand(0));
errs()<<"\n VV "<<
(VV)<<"\n";
RESULT : VV @.str = private unnamed_addr constant [3 x i8] c"DS\00", section “llvm.metadata”

if(VV->getValueID() == Value::GlobalVariableVal){
GlobalVariable* FD = cast(VV);
Value VVV = cast(FD->getOperand(0));
errs()<<"\n VVV "<<
(VVV)<<"\n";
RESULT : VVV [3 x i8] c"DS\00"

if(VVV->getValueID() == Value::ConstantDataArrayVal){
ConstantArray *caa = (ConstantArray )VVV;
errs()<<"\n “<<(caa->getNumOperands())<<”\n";
errs()<<"\n "<<
(caa->getType())<<"\n";
RESULT : 0
[3 x i8]
}

From this point, I tried to cast to every enum llvm::Value::ValueTy in order to try to iterate through [3 X i8], in order to get “DS” (as a StringRef or std::string would be nice), but I cannot. How I can parse this structure?

Thank you for any help !

Alexandru Ionut Diaconescu <alexandruionutdiaconescu@gmail.com> writes:

Hello everyone,

I am trying to "parse" a part of LLVM IR. More exactly, from

    @.str = private unnamed_addr constant [3 x i8] c"DS\00", section
"llvm.metadata"

I want to get "DS". It is the single place in the whole bytecode from where
I can get it. I have :

[snip]

No specific help for your problem, but a generic one: pass your LLVM
bytecode to

llc -march=cpp <your-llvm-bytecode-file>

you'll obtain a C++ file with the API calls for *generating* the
bytecode. Seeing how the IR is generated, hopefully you will easily
figure out how to access it.

Hi,