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

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Louis Dionne via cfe-dev
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.

```
int func() {
  int sum = 0;
  unsigned i;
  for (i = 0; i < 10; ++i) {
    sum++;
  }
  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

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

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

Louis Dionne via cfe-dev
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 :) )

Cheers,
Peter

2018-03-23 4:42 GMT+01:00 Henry Wong via cfe-dev <[hidden email]>:
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) {
    sum++;
  }
  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

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev



_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev