[英]How to use resolve MISRA C error for assembly language inline function?
I am using compiler related assembly language function asm() in my PIC32 MCU C code.我在 PIC32 MCU C 代码中使用与编译器相关的汇编语言函数 asm()。 My code is compiled and working fine with just using asm("reset") function in my C code.When checking MISRA compliance I am getting following MISRA error:
我的代码在我的 C 代码中只使用 asm("reset") 函数就可以编译并正常工作。检查 MISRA 合规性时,我收到以下 MISRA 错误:
function 'asm' undeclared, assumed to return int [MISRA 2012 Rule 17.3, mandatory]asm("reset");
函数 'asm' 未声明,假定返回 int [MISRA 2012 Rule 17.3,强制]asm("reset");
asm("reset");
How can I resolve this MISRA error for this assembly language function?如何解决此汇编语言函数的 MISRA 错误? I also tried creating function macro to use it but still getting an error.
我也尝试创建函数宏来使用它,但仍然出现错误。
function 'asm' undeclared, assumed to return int [MISRA 2012 Rule 17.3, mandatory]ASM_RESET(void);
函数 'asm' 未声明,假设返回 int [MISRA 2012 Rule 17.3,强制]ASM_RESET(void);
#define ASM_RESET(void) asm("reset")
ASM_RESET(void);
It looks like PC-Lint isn't recognizing asm
as a keyword.看起来 PC-Lint 没有将
asm
识别为关键字。 It is treating it as a function which has no prototype.它把它当作一个没有原型的函数。 You could try adding
+rw(asm)
to the options.您可以尝试将
+rw(asm)
添加到选项中。
On the other hand, this forum post suggests that the legal way is to define a reset
function in standalone file that includes only assembly, and show the C file a prototype for it.另一方面,这个论坛帖子建议合法的方法是在仅包含程序集的独立文件中定义
reset
函数,并为 C 文件显示它的原型。
reset.c:重置.c:
void reset(void) {
asm("reset");
}
test.c:测试.c:
#include "reset.h"
...
reset();
asm
is a compiler extension keyword , not a function. asm
是编译器扩展关键字,而不是函数。 Being compiler specific, it is not automatically recognised by your static analysis tool,and your compiler's inline assembly syntax is "function-like", so it applies the function prototyping rule.由于编译器特定,它不会被您的静态分析工具自动识别,并且您的编译器的内联汇编语法是“类函数”,因此它应用了函数原型规则。
You need to configure PC-Lint correctly using a configuration file or command line options that describe the implementation defined behaviour of your compiler.您需要使用描述编译器实现定义行为的配置文件或命令行选项来正确配置 PC-Lint。 That may include a great many options, but in this case you should use:
这可能包括很多选项,但在这种情况下,您应该使用:
-dasm()=
which will cause the analyser to ignore inline assembly code with the function-like syntax asm(...)
这将导致分析器忽略具有类似函数语法
asm(...)
Alternatively you can ignore the inline assembler syntax during static analysis by conditionally defining a macro that hides all such directives:或者,您可以在静态分析期间通过有条件地定义一个隐藏所有此类指令的宏来忽略内联汇编器语法:
#if defined _lint
#define asm( asmstr )
#endif
This however would hide other deviations from the checker, such as rules about encapsulation and isolation of in-line assembly.然而,这会隐藏检查器的其他偏差,例如有关内嵌装配的封装和隔离的规则。 For that reason you should not use a macro or inline assembly mixed with C code lines, but rather define a wrapper function:
出于这个原因,您不应该使用与 C 代码行混合的宏或内联程序集,而应该定义一个包装函数:
void reset(void)
{
asm("reset");
}
and place the reset()
function defined above in a separate translation unit and simply omit that source code from the analysis - as if it were library code.并将上面定义的
reset()
函数放在一个单独的翻译单元中,并简单地从分析中省略该源代码 - 就好像它是库代码一样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.