是否可以禁用外部库的 MISRA 检查?

Is it possible to disable MISRA checks of external libraries?

是否可以禁用外部库的 MISRA 检查?我试过这个,但它似乎不起作用(这个 header 使用 C++ 风格的注释和不兼容的 @ 标签)。

#pragma ghs startnomisra
#include <qcarcam.h>
#pragma ghs endnomisra

2018 年 10 月 4 日更新:最小示例

#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"
     ^

简单的答案是:这取决于您的工具链 - 但我希望如此。

通常,您可以配置它将检查哪些头文件 - 例如,LDRA ToolSuite 可以配置为检查项目头文件 (#include "xxx.h"),但不检查系统头文件 (#include <xxx.h>)

静态分析选项 --> 包括搜索 --> 不展开

更新:注意到 GreenHills 标签...我相信会有类似的东西

注意:查看个人资料以了解隶属关系!

解决方案 #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/

您可以通过将 --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.

在内的所有内容都是必需的