在IAR 6.3以上编译环境中,如果在源码中(比如声明在某个头文件中)存在以下的代码会出现错误,无法正常静态分析。
报告的错误如下:
Starting "Parasoft's Recommended Rules" (Coding Standards) for /stuct ...
[paraConfig.c] Checking Coding Standards for:
/stuct/ppexample/paraConfig.c
/stuct/ppexample/paraConfig.h
/stuct/ppexample/typedef.h
[main.c] Checking Coding Standards for:
/stuct/ppexample/main.c
[paraConfig.c] "D:\ppexample\paraConfig.h", line 33: internal error: assertion failed at:
[paraConfig.c] "class_decl.c", line 16130
[paraConfig.c]
[paraConfig.c] struct ParamCfgHead B1553head;
[paraConfig.c] ^
[paraConfig.c]
[paraConfig.c] 1 catastrophic error detected in the compilation of "C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ParaSoft.3856.18467.c".
[paraConfig.c] Compilation aborted.
[main.c] ...done.
[paraConfig.c] ...failed.
No violations found.
Files checked:
/stuct/ppexample/main.c
"Parasoft's Recommended Rules" (Coding Standards) for /stuct finished with error(s). Examine the log above for details.
Technical Support archive created: D:\tutor\TechnicalSupport_33.zip
原因是在结构体中嵌套了结构体,但是内层结构体又包含了一个大小为零的数组。如下所示:
struct SysParamHead {
short usNum;
char ucData[0];
};
struct SysParam {
struct SysParamHead head;
char c1;
char c2;
};
因为IAR FOR ARM的版本是6.3.所以需要修改 6.3的EDG设置。具体设置如下:
1、 定位到本地安装目录的如下文件夹 C:\Program Files\Parasoft\C++test\9.5\engine\etc\compilers\iccarm_6_3
2、 因为代码是C语言,所以用编辑器打开c.psrc文件(最好在这之前备份该文件到某个一地方)。
3、 修改里面的两个地方:
- 设置'edg.p_type_with_flexible_array_allowed_as_any_member' 为 'FALSE'.
- 设置'edg.gcc_mode' 为 'TRUE'
4、 保存退出,然后再次用C++test跑这个实例项目/客户的项目,问题就应该解决。
- 对于有些编译器,可能有其他问题,比如
'check_target_config: invalid integer sizes for GNU IA-32 vector functions'.
需要设置 'nios_mode' 为 'TRUE' 。