3

我在 windows 上使用 MPLAB X (3.26) 和 PIC32(XC32 v1.40 编译器)。作为审查的一部分,我正在尝试使用夹板对某人的代码进行静态代码分析。我已经对大多数编译器定义和搜索路径进行了排序,但是在避免 PIC32 std 包含文件中的解析错误方面有点难过。

我用来运行夹板的命令是

splint ^
-D"__32MX370F512L__" ^
-D"__PIC32_FEATURE_SET__"=370 ^
-D"__LANGUAGE_C__" ^
+I"C:/Program Files (x86)/Microchip/xc32/v1.40/pic32mx/include/" ^
main.c

然后输出给出

< Location unknown >: Field name reused:
Code cannot be parsed.  For help on parse errors, see splint -help
parseerrors. (Use -syntax to inhibit warning)
< Location unknown >: Previous use of
< Location unknown >: Previous use of

.... approx 100 times then...

C:\Program Files (x86)\Microchip\xc32\v1.40\pic32mx\include\\stddef.h(4,18):
Datatype ptrdiff_t declared with inconsistent type: long int
A function, variable or constant is redefined with a different type. (Use
-incondefs to inhibit warning)
load file standard.lcd: Specification of ptrdiff_t: arbitrary integral type
C:\Program Files (x86)\Microchip\xc32\v1.40\pic32mx\include\\stddef.h(5,27):
Datatype size_t declared with inconsistent type: unsigned long int
load file standard.lcd: Specification of size_t:
arbitrary unsigned integral type
C:\Program Files (x86)\Microchip\xc32\v1.40\pic32mx\include\\stddef.h(6,13):
Datatype wchar_t declared with inconsistent type: int
load file standard.lcd: Specification of wchar_t: arbitrary integral type
C:\Program Files (x86)\Microchip\xc32\v1.40\pic32mx\include\\stdarg.h(75,36):
No type before declaration name (implicit int type): __builtin_va_list :
int
A variable declaration has no explicit type.  The type is implicitly int.
(Use -imptype to inhibit warning)
C:\Program Files (x86)\Microchip\xc32\v1.40\pic32mx\include\\stdarg.h(75,36):
Parse Error: Suspect missing struct or union keyword: __builtin_va_list :
int. (For help on parse errors, see splint -help parseerrors.)
*** Cannot continue.

最后一个导致事情停止。我试过 -skip-iso-headers 之类的东西,但没有运气。似乎它的 standard.lcd 文件和 xc32 std 文件存在问题

谁能告诉我

  • < Location unknown >: Field name reused:手段或可能指的是什么?
  • 解决由于 std 头文件引起的解析错误的方法?

到目前为止,解决头文件问题的唯一方法是定义类型,例如

-D"__builtin_va_list"=int ^
4

2 回答 2

0

我正在使用不同的处理器、编译器和静态分析工具(PRQA / Helix QAC),但我认为我们在标准头文件的解析问题上面临同样的问题。我花了一些时间才弄清楚发生了什么。

一方面,我可以说你的解决方法已经足够好了,显然你不应该太担心它。我使用了这里描述的稍微不同的解决方法: Pycparser not working on preprocessed code

-D __builtin_va_list = struct __builtin_va_list {}

我想另一种方法是使用存根标准标头而不是真实标头。例如,我的工具手册声称该工具应该提供这样的头文件,尽管我还没有找到/获得它们。

于 2020-12-22T20:15:24.890 回答
0

我认为您的代码(或您#include 的某些代码)正在使用匿名位域或/和结构。GNU 扩展为 C11 之前的 C 版本提供了匿名结构和匿名联合。由于 Splint 不了解 C11(我只发现手册中提到了 C99 ,并且google 同意)并且仅部分支持 GNU 扩展(搜索 gnu-extensions),因此很难解析它们。

尽管我使用的是 sdcc 而不是 XC8,但我在为 PIC18f46k22 编写的一些代码中遇到了类似的问题。

问题在于 pic18f46k22.h,它在 typedef 联合中具有匿名结构(特别是位域)。

这段代码...

typedef union
  {
  struct
    {
    unsigned name0              : 1;
    unsigned name1              : 1;
    unsigned name2              : 1;
    unsigned name3              : 1;
    unsigned name4              : 1;
    unsigned                    : 1;
    unsigned                    : 1;
    unsigned                    : 1;
    };

  struct
    {
    unsigned name               : 6;
    unsigned                    : 2;
    };
  } __NAMEbits_t;

...会产生这些错误...

< Location unknown >: Field name reused:
Code cannot be parsed.  For help on parse errors, see splint -help
parseerrors. (Use -syntax to inhibit warning)
< Location unknown >: Previous use of

...但这段代码不会。

  struct indv
    {
    unsigned name0              : 1;
    unsigned name1              : 1;
    unsigned name2              : 1;
    unsigned name3              : 1;
    unsigned name4              : 1;
    unsigned                    : 1;
    unsigned                    : 1;
    unsigned                    : 1;
    };
  struct all
    {
    unsigned name               : 6;
    unsigned                    : 2;
    };

  typedef union
    {
    struct indv individualbits;
    struct all  allbits;
    } __NAMEbits_t;
于 2016-10-24T16:54:07.877 回答