3

Is it possible to disable MISRA checks of external libraries? I've tried this, but it doesn't seem to work (this header uses C++ style comments and incompatible @ tags).

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

Update 10/4/18: Minimal example

#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);
}

Compiler output: AFAIU these lines are related to includes embraced by #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"
     ^
Minor Threat
  • 2,025
  • 1
  • 18
  • 32
  • What actual error are you seeing? Can you provide a [MCVE]? Wrapping the include with `#pragma ghs startnomisra` and `#pragma ghs endnomisra` works for me. – Tim Sep 04 '18 at 16:52
  • Mostly C++ style comments starting with double slash and @ symbols in comments plus something else in much lower quantities. Alas, I can't revisit this log again very soon as I've changed the whole approach, returned to step 1 and killed the branch. At the moment I'm trying to make dependencies per compilation unit in the project as local as possible prior to moving to MISRA. – Minor Threat Sep 04 '18 at 17:18
  • 1
    I'll try to make a minimal example tomorrow if you think it should work. – Minor Threat Sep 04 '18 at 17:19
  • did a minimal example – Minor Threat Oct 04 '18 at 16:06
  • @MinorThreat These errors are compiler errors and not MISRA errors. ` identifier "__inline" is undefined` , `"Value" has already been declared in the current scope` etc. Even the last one `#error directive: "(Misra Rule 20.12): the header not allowed"` is a `#error` and the text is part of the code. Somewhere the include files are not added correctly or path is not correct. – Rishikesh Raje Oct 11 '18 at 03:46
  • It does compile without MISRA though – Minor Threat Oct 11 '18 at 09:26

2 Answers2

1

Solution The #pragma diag_suppress=tag[,tag,...] can also be used to suppress messages from the MISRA C checker.

To avoid that you have to write a long list of MISRA C tags for every #include, you can use the following two macros:

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

To disable the MISRA C check for a header file, you can write ...

MISRAC_DISABLE
#include "myincludes.h"
MISRAC_ENABLE

for more details refer https://www.iar.com/support/tech-notes/compiler/disable-misra-c-for-include-files/

kiner_shah
  • 3,939
  • 7
  • 23
  • 37
1

You can disable MISRA checks per library unit or per file by adding --misra_2004=none (or --misra_2012=none) to the relevant project file, e.g.:

Library:

#!gbuild
[Library]
    -object_dir=$__OUT_DIR
    -o $__OUT_DIR/lib/libfoo.a
    --misra_2004=none

Single file in program:

#!gbuild
[Program]
:
src/foo/bar.c
    --misra_2004=none

I don't know why, but this is necessary for everything which includes INTEGRITY.h.

FrodeTennebo
  • 531
  • 3
  • 13