Reconciling Polyspace Unused Parameter and MISRA 2.2 No Dead Code Warning

조회 수: 2 (최근 30일)
Kier
Kier 2017년 4월 13일
답변: Kier 2018년 6월 4일
I followed the advice of Polyspace help for avoiding unused parameter warnings, i.e. void cast the parameter:
void func( char x )
{
(void)x;
/* This function doesn't use x. */
}
But this in itself creates a MISRA violation 2.2: "There shall be no dead code." for the void cast.
Short of justification, is there a way to silence both MISRA 2.2 AND Polyspace Unsed Parameter warning for those few functions over which I have no control over the prototype?
Thank you.

답변 (2개)

Alexandre De Barros
Alexandre De Barros 2017년 4월 14일
Hi,
what about using a code annotation to automatically justify the defect? In this case, the annotation is:
/* polyspace<DEFECT:UNUSED_PARAMETER:Not a defect:No action planned> */
void func( char x )
The next time the analysis is launched, the defect will still be there but will have the severity "not a defect" (and the status "not action planned"). You can even use filters in the Results List to hide it from this view.
Alex
  댓글 수: 1
Kier
Kier 2017년 4월 24일
Thank you but I was wondering if there's a way to avoid justification because, for me, justification is a last resort. A justification is an artefact that has to be reviewed and managed but I think there are so few of these that it doesn't make much difference in this particular case.
The other complication is that we have semi-automatic code generation from Rhapsody. It's possible but not straightforward to add justifications before the function body declaration.

댓글을 달려면 로그인하십시오.


Kier
Kier 2018년 6월 4일
The answer is to use the following macros. This stops Polyspace raising a violation but of course is optimised away by a compiler.
/* Acknowledge and prevent Unused Parameter warning for values. */
#define UNUSED_PARAMETER_VAL(x) {if((x) != 0U){/* Do Nothing */}}
/* Acknowledge and prevent Unused Parameter warning for pointers. */
#define UNUSED_PARAMETER_PTR(x) {if((x) != NULL){/* Do Nothing */}}

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by