[analyzer] LoopUnrolling.cpp: when the type of counter is `unsigned`, the loop does not unroll

Hi all,

I have some confusion about LoopUnrolling.cpp.

For the code given below, the loop does not unroll because the counter is unsigned. I read the code of LoopUnrolling.cpp and I think the relevant function is forLoopMatcher(), see https://github.com/llvm-mirror/clang/blob/master/lib/StaticAnalyzer/Core/LoopUnrolling.cpp#L152.

Mirror of official clang git repository located at http://llvm.org/git/clang. Updated every five minutes.

  • | - |

int func() {
int sum = 0;
unsigned i;
for (i = 0; i < 10; ++i) {
return sum;

1.I want to known if loop-unrolling only considers the counter of type signed?
2.Since the IntegerLiteral is of signed type, when matching IntegerLiteral, does it need to add ignoringParenImpCasts to match the unsigned counter?

Henry Wong
Qihoo 360 Codesafe Team

Hi Henry,

I have probably missed this mail earlier, sorry for the late answer.

  1. The intention is to match as much “safe” cases as possible, and it should work for unsigned as well.

  2. I guess this would solve it but not sure, however, I can check this tomorrow. (Or if you have a solution (if this works) feel free to send a patch about it, it would help a lot :slight_smile: )