3

I am looking for the best way to convert large amounts of code to 64bit. It was suggested to me that I look into some static code analysis tools such as cpptest to spot the portability problems. Does anyone have any suggestions for me as to what I could use? Or an efficient way to port code to 64-bit?

environment: windows, vs2008 (I know about the "Detect 64-bit Portability Issues" option in VS but I need better).

example: a tool that would pick up this obvious type of 64bit portability bugs.

for (int i = 0; i < 64; i++)
{
    __int64 n64 = (1 << i); // Does not generate warning
}
  • 1
    How's that a _64bit portability issue_ ? Seems like it's already broken before porting. I'd be more worried about `for (int i = 0; i != 32; ++i) { unsigned long k = 1< – MSalters Sep 19 '11 at 13:13
  • A 64-bit compiler is a pretty good diagnostic tool, as long as you turn the warning level to 11. – Hans Passant Sep 19 '11 at 13:21
  • See also http://stackoverflow.com/questions/4871267/what-static-analysis-tools-are-available-to-assist-in-porting-a-linux-app-to-64-b/4888996#4888996 – Flash Sheridan Sep 19 '11 at 14:39

2 Answers2

4

Try PVS-Studio: http://pvs-studio.viva64.com/, it provides specific rule set to spot 64-bit portability issues

Alex Z
  • 1,867
  • 1
  • 29
  • 27
Mike
  • 1,717
  • 2
  • 15
  • 19
  • I was in the midst of looking over that website as your replied. Its an option that was suggested to me but it is expensive... – Padawan Learner Sep 19 '11 at 13:57
  • 4
    Yes, but they have trial version that may help, I used it some time ago, sometimes it is really useful – Mike Sep 19 '11 at 14:26
1

Frama-C is an extensible analysis framework for C (only) with a plug-in for detecting undefined behaviors.

Let's try it on your example:

main(){
  for (int i = 0; i < 64; i++)
  {
    long long n64 = (1 << i);
  }
}

This plug-in is not originally intended for casual bug-finding, so you'll have to excuse the poor interface and rather strict use conditions:

$ frama-c -val t.c
...
t.c:4:[kernel] warning: invalid shift: assert i ≥ 0 ∧ i < 32;

The condition i ≥ 0 ∧ i < 32 expresses the condition that should be true at line 4 for the shift to be defined. As you can infer once the problem has been pointed out to you, 1 is of type int, and it's undefined to shift it by more than 32 on this architecture.

Is this the warning you wanted to see?

Again, Frama-C is only for C, so you may only take advantage of it if parts of the project you want to investigate are in C.

Pascal Cuoq
  • 79,187
  • 7
  • 161
  • 281
  • Yes that is the warning that I want to see, it was just an example of a problem that we weren't able to catch. Unfortunatly most of our code is in c++. – Padawan Learner Sep 19 '11 at 13:54