0

In my LLVM IR, I have a number of function invocations that look like this:

%2 = invoke i16 @"_ZN41_$LT$std..sync..mpsc..Sender$LT$T$GT$$GT$4send17h3c94bf47bc6c3500E"(%"std::sync::mpsc::Sender<weather::Weather>"* dereferenceable(16) %weather_sender, i8 %1)
      to label %bb4 unwind label %cleanup, !dbg !717

I want to statically analyze them in order to find the value for the last argument, %_6. Is there a way to get its value? I tried to access the argument directly but this just gives me the instruction where the argument is loaded/allocated. So this:

if (InvokeInst* ii = dyn_cast<InvokeInst>(&instr)) {
    Value* v = ii->getArgOperand(ii->getNumArgOperands() - 1);
    v->dump();
}

just gives me %1 = load i8, i8* %_5, !dbg !717, the load instruction that gives me

  • Instructions produce values. The value returned by the load would be passed in as the last argument to the function call. – Brian Jul 22 '17 at 01:32
  • I should have added that this is part of a static analysis I'm conducting on the code, sorry. – Felix Suchert Jul 22 '17 at 05:40
  • Being static analysis, all that LLVM can say is that this instruction will produce the value. I am not not sure what other value you want. – Brian Jul 22 '17 at 13:00
  • The values used as arguments are known during compile-time. `%1` for instance is _1_. So I'll have to move back up through the instructions until I find the associated `store` instruction that stores the value that will be loaded and passed as argument later on? – Felix Suchert Jul 24 '17 at 09:57
  • 1
    Yes, depending on optimizations, the compiler might be able to reuse the value from the store without loading it again. Otherwise, you can try traversing the instructions to find a store that has the same address calculations as the load. – Brian Jul 24 '17 at 21:07

0 Answers0