Search code examples
cmisragreenhills

Is it possible to disable MISRA checks of external libraries?


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

Solution

  • 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.