开发者

static code analysis tools for spotting 64bit portability problems?

开发者 https://www.devze.com 2023-04-06 08:49 出处:网络
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 portab开发者_JAVA百科ility p

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 portab开发者_JAVA百科ility 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
}


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消