Hi,<br><br>The issue seems in the file x86ISelLowering.cpp where we dont have an implementation for returning the hidden pointer in the specified register for 32 bit. We do have it for 64bit. On adding the following:<br><br>
in function<br>X86TargetLowering::LowerReturn<br><br> if (!(Subtarget->is64Bit()) &&<br>      DAG.getMachineFunction().getFunction()->hasStructRetAttr()) {<br>    MachineFunction &MF = DAG.getMachineFunction();<br>
    X86MachineFunctionInfo *FuncInfo = MF.getInfo<X86MachineFunctionInfo>();<br>    unsigned Reg = FuncInfo->getSRetReturnReg();<br>    assert(Reg &&<br>           "SRetReturnReg should have been set in LowerFormalArguments().");<br>
    SDValue Val = DAG.getCopyFromReg(Chain, dl, Reg, getPointerTy());<br><br>    Chain = DAG.getCopyToReg(Chain, dl, X86::EAX, Val, Flag);<br>    Flag = Chain.getValue(1);<br><br>    MRI.addLiveOut(X86::EAX);<br>  }<br><br>
in function<br>X86TargetLowering::LowerFormalArguments<br><br> if (!(Is64Bit) && MF.getFunction()->hasStructRetAttr()) {<br>    X86MachineFunctionInfo *FuncInfo = MF.getInfo<X86MachineFunctionInfo>();<br>
    unsigned Reg = FuncInfo->getSRetReturnReg();<br>    if (!Reg) {<br>      Reg = MF.getRegInfo().createVirtualRegister(getRegClassFor(MVT::i32));<br>      FuncInfo->setSRetReturnReg(Reg);<br>    }<br>    SDValue Copy = DAG.getCopyToReg(DAG.getEntryNode(), dl, Reg, InVals[0]);<br>
    Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Copy, Chain);<br>  }<br><br>we get the correct output in gdb and the there are no side-effects also.<br><br>Please verify whether this is a genuine fix.<br><br>The<br>
<br><div class="gmail_quote">On Mon, Dec 3, 2012 at 4:46 PM, Renato Golin <span dir="ltr"><<a href="mailto:rengolin@systemcall.org" target="_blank">rengolin@systemcall.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On 3 December 2012 10:42, Mayur Pandey <<a href="mailto:mayurthebond@gmail.com">mayurthebond@gmail.com</a>> wrote:<br>
> So this seems to be the cause of the problem.<br>
<br>
</div>I guess you're mixing two different problems. First, is the possible<br>
lack of conformance with the ABI you state, which I can't comment<br>
since I don't know that ABI very well. Second, is the fact that clang<br>
is not printing correct debug information (or is not interoperating<br>
well enough with gdb).<br>
<br>
Fixing the first issue will not necessarily fix the second.<br>
<div class="im"><br>
<br>
> @Renato Golin:- Does the code execute correctly? Does a printf on the sum<br>
> outputs the<br>
> correct value? : yes the code executes correctly and some gives the correct<br>
> value. Its only in gdb that we face this problem as gdb expects the hidden<br>
> pointer in eax.<br>
<br>
</div>As I expected. Following the ABI is not a requirement to have working<br>
code, or a debuggable code. GDB is probably expecting programs to<br>
follow the ABI if they do not have decent Dwarf, which seems clang is<br>
failing on both.<br>
<br>
Debuggers have to deal with all sorts of user (and compiler) code, and<br>
to give users the "debug illusion", they make too many guesses.<br>
However, if the Dwarf information is correct to begin with, I<br>
seriously hope that GDB would rely on that, rather than "expect"<br>
values to be on specific registers.<br>
<br>
Have a look in the Dwarf symbols clang generates with your code and<br>
make sure that clang is not printing the correct location information<br>
for that variable on the ranges where it lives on registers and which<br>
registers.<br>
<br>
If clang's info is right, there's only the ABI bug and GDB is being<br>
silly. If the info is wrong, then we may need to fix *both* bugs (ABI<br>
+ Dwarf), not just the ABI one.<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
--<br>
cheers,<br>
--renato<br>
<br>
<a href="http://systemcall.org/" target="_blank">http://systemcall.org/</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><div>Thanx & Regards <br></div>
<div><b>Mayur Pandey </b><br></div>
<div style="color:rgb(0,0,0)">Senior Software Engineer</div>
<div>Samsung India Software Operations<br>Bangalore<br>+91-9742959541<br><font color="#3333ff"></font><font color="#3333ff"> <br></font></div>
<div> </div>
<div> </div><br>