是否可以禁用外部库的MISRA检查?我已经尝试过了,但是似乎不起作用(此标头使用C ++样式注释和不兼容的@标记)。
#pragma ghs startnomisra
#include <qcarcam.h>
#pragma ghs endnomisra
更新10/4/18:最小示例
#pragma ghs startnomisra
#include <INTEGRITY.h>
#include <unistd.h>
#include <stdlib.h>
#pragma ghs endnomisra
int main(void)
{
const char* msg = "Hello world";
write(1, msg, strlen(msg));
Exit(0);
}
编译器输出:AFAIU这些行与#pragmas所包含的内容有关
Output from Compiling stm-testbed_as0.c:
"/mnt/part2/apq8096au-hgh-1-0_hlos_dev_boot/ghs_apps_proc/integrity/INTEGRITY-include/INTEGRITY_types.h", line 226: error #20:
identifier "__inline" is undefined
static INLINE Value __LssbValue(Value TheValue)
^
"/mnt/part2/apq8096au-hgh-1-0_hlos_dev_boot/ghs_apps_proc/integrity/INTEGRITY-include/INTEGRITY_types.h", line 226: error #101:
"Value" has already been declared in the current scope
static INLINE Value __LssbValue(Value TheValue)
^
"/mnt/part2/apq8096au-hgh-1-0_hlos_dev_boot/ghs_apps_proc/integrity/INTEGRITY-include/INTEGRITY_types.h", line 226: error #65:
expected a ";"
static INLINE Value __LssbValue(Value TheValue)
^
"/mnt/part2/apq8096au-hgh-1-0_hlos_dev_boot/ghs_apps_proc/integrity/INTEGRITY-include/INTEGRITY_types.h", line 242: warning #12-D:
parsing restarts here after previous syntax error
typedef unsigned char MemoryLocation;
^
"/mnt/part2/apq8096au-hgh-1-0_hlos_dev_boot/ghs_apps_proc/integrity/INTEGRITY-include/time.h", line 67: fatal error #35:
#error directive: "(Misra Rule 20.12): the header <time.h> not
allowed"
# error "(Misra Rule 20.12): the header <time.h> not allowed"
^
答案 0 :(得分:1)
解决方案
#pragma diag_suppress=tag[,tag,...]
也可用于禁止来自MISRA C检查器的消息。
为避免必须为每个#include编写一列MISRA C标签,可以使用以下两个宏:
#define MISRAC_DISABLE _Pragma ("diag_suppress= \
Pm001,Pm002,Pm003,Pm004,Pm005,Pm006,Pm007,Pm008,Pm009,Pm010,Pm011,\
Pm012,Pm013,Pm014,Pm015,Pm016,Pm017,Pm018,Pm019,Pm020,Pm021,Pm022,\
Pm023,Pm024,Pm025,Pm026,Pm027,Pm028,Pm029,Pm030,Pm031,Pm032,Pm033,\
Pm034,Pm035,Pm036,Pm037,Pm038,Pm039,Pm040,Pm041,Pm042,Pm043,Pm044,\
Pm045,Pm046,Pm047,Pm048,Pm049,Pm050,Pm051,Pm052,Pm053,Pm054,Pm055,\
Pm056,Pm057,Pm058,Pm059,Pm060,Pm061,Pm062,Pm063,Pm064,Pm065,Pm066,\
Pm067,Pm068,Pm069,Pm070,Pm071,Pm072,Pm073,Pm074,Pm075,Pm076,Pm077,\
Pm078,Pm079,Pm080,Pm081,Pm082,Pm083,Pm084,Pm085,Pm086,Pm087,Pm088,\
Pm089,Pm090,Pm091,Pm092,Pm093,Pm094,Pm095,Pm096,Pm097,Pm098,Pm099,\
Pm100,Pm101,Pm102,Pm103,Pm104,Pm105,Pm106,Pm107,Pm108,Pm109,Pm110,\
Pm111,Pm112,Pm113,Pm114,Pm115,Pm116,Pm117,Pm118,Pm119,Pm120,Pm121,\
Pm122,Pm123,Pm124,Pm125,Pm126,Pm127,Pm128,Pm129,Pm130,Pm131,Pm132,\
Pm133,Pm134,Pm135,Pm136,Pm137,Pm138,Pm139,Pm140,Pm141,Pm142,Pm143,\
Pm144,Pm145,Pm146,Pm147,Pm148,Pm149,Pm150,Pm151,Pm152,Pm153,Pm154,\
Pm155")
#define MISRAC_ENABLE _Pragma ("diag_default= \
Pm001,Pm002,Pm003,Pm004,Pm005,Pm006,Pm007,Pm008,Pm009,Pm010,Pm011,\
Pm012,Pm013,Pm014,Pm015,Pm016,Pm017,Pm018,Pm019,Pm020,Pm021,Pm022,\
Pm023,Pm024,Pm025,Pm026,Pm027,Pm028,Pm029,Pm030,Pm031,Pm032,Pm033,\
Pm034,Pm035,Pm036,Pm037,Pm038,Pm039,Pm040,Pm041,Pm042,Pm043,Pm044,\
Pm045,Pm046,Pm047,Pm048,Pm049,Pm050,Pm051,Pm052,Pm053,Pm054,Pm055,\
Pm056,Pm057,Pm058,Pm059,Pm060,Pm061,Pm062,Pm063,Pm064,Pm065,Pm066,\
Pm067,Pm068,Pm069,Pm070,Pm071,Pm072,Pm073,Pm074,Pm075,Pm076,Pm077,\
Pm078,Pm079,Pm080,Pm081,Pm082,Pm083,Pm084,Pm085,Pm086,Pm087,Pm088,\
Pm089,Pm090,Pm091,Pm092,Pm093,Pm094,Pm095,Pm096,Pm097,Pm098,Pm099,\
Pm100,Pm101,Pm102,Pm103,Pm104,Pm105,Pm106,Pm107,Pm108,Pm109,Pm110,\
Pm111,Pm112,Pm113,Pm114,Pm115,Pm116,Pm117,Pm118,Pm119,Pm120,Pm121,\
Pm122,Pm123,Pm124,Pm125,Pm126,Pm127,Pm128,Pm129,Pm130,Pm131,Pm132,\
Pm133,Pm134,Pm135,Pm136,Pm137,Pm138,Pm139,Pm140,Pm141,Pm142,Pm143,\
Pm144,Pm145,Pm146,Pm147,Pm148,Pm149,Pm150,Pm151,Pm152,Pm153,Pm154,\
Pm155")
要禁用头文件的MISRA C检查,您可以编写...
MISRAC_DISABLE
#include "myincludes.h"
MISRAC_ENABLE
有关更多详细信息,请参见https://www.iar.com/support/tech-notes/compiler/disable-misra-c-for-include-files/
答案 1 :(得分:1)
您可以通过将--misra_2004=none
(或--misra_2012=none
)添加到相关项目文件中来禁用每个库单元或每个文件的MISRA检查,例如:
图书馆:
#!gbuild
[Library]
-object_dir=$__OUT_DIR
-o $__OUT_DIR/lib/libfoo.a
--misra_2004=none
程序中的单个文件:
#!gbuild
[Program]
:
src/foo/bar.c
--misra_2004=none
我不知道为什么,但这对于包括INTEGRITY.h
在内的所有内容都是必需的。
答案 2 :(得分:-2)
简单的答案是:这取决于您的工具链-但我希望如此。
通常,您可以配置要检查的头文件-例如,可以将LDRA ToolSuite配置为检查项目头(#include "xxx.h"
),但不能检查系统头(#include <xxx.h>
)
静态分析选项->包含搜索->不要扩展
更新:注意到了GreenHills标签...我敢肯定会有类似的东西
注意:请查看会员的个人资料!