首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用夹板对窗口进行静态代码分析如何避免系统文件解析错误

用夹板对窗口进行静态代码分析如何避免系统文件解析错误
EN

Stack Overflow用户
提问于 2016-04-07 02:16:12
回答 2查看 892关注 0票数 3

我在windows上使用MPLAB (3.26)和PIC32 (XC32 v1.40编译器)。我试图使用夹板对某些人的代码进行静态代码分析,作为评审的一部分。我已经对大多数编译器定义和搜索路径进行了排序,但在避免PIC32 std包含文件中的解析错误时,会遇到一些困难。

我用来运行splint的命令是

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

然后输出

代码语言:javascript
复制
< 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.

最后一种导致事情停止。我试过像-跳过-等-头没有运气。它似乎看到了standard.lcd文件和xc32 std文件的问题。

有人能告诉我吗

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

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

代码语言:javascript
复制
-D"__builtin_va_list"=int ^
EN

回答 2

Stack Overflow用户

发布于 2016-10-24 16:54:07

我认为您的代码(或您#包含的一些代码)使用的是匿名位字段或/和结构。匿名结构和匿名联合是由GNU扩展为C的版本提供的,它们比C11更早。由于Splint不知道C11 (我只在手册中找到了提到C99的地方,以及谷歌 同意)和只部分支持GNU扩展 (搜索gnu-扩展),所以很难解析它们。

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

这个问题与pic18f46k22.h有关,它的类型联合中包含匿名结构(尤其是位字段)。

这个密码..。

代码语言:javascript
复制
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;

...would产生了这些错误..。

代码语言:javascript
复制
< 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

...but这段代码不会。

代码语言:javascript
复制
  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;
票数 0
EN

Stack Overflow用户

发布于 2020-12-22 20:15:24

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

首先,我可以说,你的解决办法足够好,显然你不应该太担心它。我使用了一个稍微不同的解决方法,在这里描述:不处理预处理代码的not解析器

代码语言:javascript
复制
-D __builtin_va_list = struct __builtin_va_list {}

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36465544

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档