Improper Function::iterator increment

void Wave::init (const Function &F){

Function::const_iterator ie = F.end();

outs() << ie << “\n\n”;

for (Function::const_iterator I = F.begin(), IE = F.end(); I != IE; I++, K++){

outs() << I << “\n”;

// some manipulation with I

}
}

I used the above shown function in my pass in LLVM 3.4.2 and it used to work fine but when I am compiling this pass with 3.5.0, this is a never ending loop. Can someone please suggest me what can be wrong here ?

Upon some debugging, I found out that const_iterator I never becomes equal to IE, rather it goes past IE when incremented and hence loop never ends.

Following is the output upon executing above code.

0x2e08248 ← address of ie
0x2e16630 ← address of I initially
0x2e08250 ← incremented I
0x2e165e0
0x2e16630
0x2e08250
0x2e165e0
0x2e16630
0x2e08250

This may be difficult yo reproduce or debug without a more complete (though preferably minimal) test case.

So, you mean to say that the above implementation is correct and should work fine.

I initially thought that the above way is not the correct way anymore since 3.5.0 might have changed few things.

Anyways here is my dirty code I have written for my research project that I took the above snippet from :

https://github.com/pranavk/spatial-computing/blob/master/waves.cpp#L105

So, you mean to say that the above implementation is correct and should
work fine.

So far as I can see - but I could be missing something.

I initially thought that the above way is not the correct way anymore
since 3.5.0 might have changed few things.

Anyways here is my dirty code I have written for my research project that
I took the above snippet from :

https://github.com/pranavk/spatial-computing/blob/master/waves.cpp#L105

Someone (not necessarily me) will presumably need the
input/command/arguments/whatever required to trigger the infinite loop in
this code that you're seeing, as well as the code there.

Input to this pass is the bitcode format of simple code below :

int sum_single_loop (int a){
int su = 0, i;
for (i=0;i<a;i++)
su = su + i;
return su;
}

This is a bit of a long shot, but your loop looks fine, and I noticed a bug in one of the functions you call from your loop body. Try this for WaveScalar::setLabel:

- Twine twine(k);
- (*succ)->setName(twine);
+ (*succ)->setName(Twine(k));

and see whether that makes any difference?

Nick

Pranav Kant wrote:

Sorry but that didn’t make any difference. Loop is still infinite.