<div dir="ltr"><br clear="all"><div><div>If I have an operand as a Value from an instruction like: <font face="monospace, monospace">Value* V = opnd->get();</font> and I am sure this is a variable, I want to know the variable name (in source code) for this Value object. I am doing it like this:</div><div>              </div><div>                                   <font face="monospace, monospace">const Function* Func;</font></div><div><font face="monospace, monospace">                if (const Argument* Arg = dyn_cast<Argument>(V)) </font></div><div><font face="monospace, monospace">                {</font></div><div><font face="monospace, monospace">                  Func = Arg->getParent();</font></div><div><font face="monospace, monospace">                }</font></div><div><font face="monospace, monospace">                else if (const Instruction* I = dyn_cast<Instruction>(V)) </font></div><div><font face="monospace, monospace">                {</font></div><div><font face="monospace, monospace">                  Func = I->getParent()->getParent();</font></div><div><font face="monospace, monospace">                }</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">                StringRef name;</font></div><div><font face="monospace, monospace">                if (!Func) </font></div><div><font face="monospace, monospace">                   name = V->getName();</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">                else</font></div><div><font face="monospace, monospace">                {</font></div><div><font face="monospace, monospace">                  const DILocalVariable* Var = NULL;</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">                  for (const_inst_iterator Iter = inst_begin(Func), End = inst_end(Func); Iter != End; ++Iter) </font></div><div><font face="monospace, monospace">                  {</font></div><div><font face="monospace, monospace">                    if (const DbgDeclareInst* DbgDeclare = dyn_cast<DbgDeclareInst>(&*Iter)) </font></div><div><font face="monospace, monospace">                    {</font></div><div><font face="monospace, monospace">                      if (DbgDeclare->getAddress() == V) Var = DbgDeclare->getVariable();</font></div><div><font face="monospace, monospace">                    } </font></div><div><font face="monospace, monospace">                    else if (const DbgValueInst* DbgValue = dyn_cast<DbgValueInst>(&*Iter)) </font></div><div><font face="monospace, monospace">                    {</font></div><div><font face="monospace, monospace">                      if (DbgValue->getValue() == V) Var = DbgValue->getVariable();</font></div><div><font face="monospace, monospace">                    }</font></div><div><font face="monospace, monospace">                  }</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">                  name = Var->getName();</font></div><div><font face="monospace, monospace">                }</font></div><div><font face="monospace, monospace">                errs() << "\nVariableName: " << name.str() << "\n";</font></div><div><br></div><div>But  this condition: <font face="monospace, monospace">if(DbgDeclare->getAddress() == V)</font> produces false result as the address for the Value object differs from every Value object found in dbg.declare intrinsic. Is this not how one finds the variable name??</div><div>What am I doing wrong?</div></div><div><br></div><div>--</div><div>Regards</div><div>Dhriti Khanna</div>
</div>