【问题标题】:some checkers of clang static analyzer do not work under linux一些clang静态分析器的检查器在linux下不起作用
【发布时间】:2013-10-25 12:47:12
【问题描述】:

首先我输入命令:

clang -cc1 -analyzer-checker-help 

列出所有可用的检查器如下。

alpha.core.BoolAssignment       Warn about assigning non-{0,1} values to Boolean variables
  alpha.core.CastSize             Check when casting a malloc'ed type T, whether the size is a multiple of the size of T
  alpha.core.CastToStruct         Check for cast from non-struct pointer to struct pointer
  alpha.core.FixedAddr            Check for assignment of a fixed address to a pointer
  alpha.core.PointerArithm        Check for pointer arithmetic on locations other than array elements
  alpha.core.PointerSub           Check for pointer subtractions on two pointers pointing to different memory chunks
  alpha.core.SizeofPtr            Warn about unintended use of sizeof() on pointer expressions
  alpha.cplusplus.VirtualCall     Check virtual function calls during construction or destruction
......................................

然后我选择两个(BoolAssignment 和 VirtualCall)来测试,代码如下:

int f1(){
int a=5;
short b=4;
bool a1=a;//maybe warn
bool b1=b;//maybe warn
if(a1&&b1)return 1;
return 0;
}
class M{
public:
    virtual int GetAge(){return 0;}
};
class P:public M{
public:
    virtual int GetAge(){return 1;}
    P(){GetAge();}//maybe warn
    ~P(){GetAge();}//maybe warn
};

但是什么也没发生,怎么了? 这是我调用检查的命令

scan-build --use-analyzer=/usr/bin/clang clang++ test.cpp -c -o test.o

【问题讨论】:

    标签: linux static clang analyzer


    【解决方案1】:

    alpha.core.BoolAssignment 默认不勾选。您必须使用 -enable-checker 选项启用它。所以命令是:

    scan-build --use-analyzer=/usr/bin/clang -enable-checker alpha.core.BoolAssignment clang++ test.cpp -c -o test.o

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-20
      • 1970-01-01
      • 2016-10-07
      • 2010-12-24
      • 2016-11-17
      • 1970-01-01
      • 2018-06-22
      • 2022-08-10
      相关资源
      最近更新 更多