代码之家  ›  专栏  ›  技术社区  ›  Minor Threat

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

  •  3
  • Minor Threat  · 技术社区  · 6 年前

    是否可以禁用外部库的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这些行与包含在pragma中的include相关

    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"
         ^
    
    3 回复  |  直到 6 年前
        1
  •  1
  •   FrodeTennebo    6 年前

    您可以通过添加 --misra_2004=none (或) --misra_2012=none )相关项目文件,例如:

    图书馆:

    #!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
  •  1
  •   kiner_shah Ahamed Raaseem    6 年前

    解决方案 这个 #pragma diag_suppress=tag[,tag,...] 也可用于抑制来自misra c检查器的消息。

    为了避免这种情况,您必须为每个包括的内容编写一长串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/

        3
  •  -2
  •   Andrew    6 年前

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

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

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

    更新:注意到格林希尔标签…我肯定会有类似的东西

    注意:有关隶属关系,请参见配置文件!