I noticed that Coccinelle skips over much of QEMU's hw/arm/armsse.c.
I append a minimized test case.  Observations:

* spatch seems to have trouble parsing

    ARMSSE *s = ARMSSE(opaque);

  where ARMSSE is a typedef, and ARMSSE() is a function-like macro.
  Yes, I know that's in rather poor taste.

* Workaround #1: rename the typedef to ARMSSE_

* Workaround #2: move the typedef and the macro from the .h to the .c.



$ cat armsse.c
#include "armsse.h"

void nsccfg_handler(void *opaque, int n, int level)
{
    ARMSSE *s = ARMSSE(opaque);

    s->nsccfg = level;
}
$ cat armsse.h
#ifndef ARMSSE_H
#define ARMSSE_H

typedef struct {
    int nsccfg;
} ARMSSE;

#define ARMSSE(obj) ((ARMSSE *)(obj))

#endif
$ spatch --parse-c armsse.c
init_defs_builtins: /usr/lib64/coccinelle/standard.h

PARSING: armsse.c
including ./armsse.h
ERROR-RECOV: found sync '}' at line 8
parsing pass2: try again
ERROR-RECOV: found sync '}' at line 8
parsing pass3: try again
ERROR-RECOV: found sync '}' at line 8
parse error 
 = File "armsse.c", line 5, column 16, charpos = 91
  around = 'ARMSSE',
  whole content =     ARMSSE *s = ARMSSE(opaque);
badcount: 7
bad: #include "armsse.h"
bad: 
bad: void nsccfg_handler(void *opaque, int n, int level)
bad: {
BAD:!!!!!     ARMSSE *s = ARMSSE(opaque);
bad: 
bad:     s->nsccfg = level;
bad: }
-----------------------------------------------------------------------
maybe 10 most problematic tokens
-----------------------------------------------------------------------
ARMSSE: present in 2 parsing errors
example: 
       void nsccfg_handler(void *opaque, int n, int level)
       {
           ARMSSE *s = ARMSSE(opaque);
       
opaque: present in 2 parsing errors
example: 
       void nsccfg_handler(void *opaque, int n, int level)
       {
           ARMSSE *s = ARMSSE(opaque);
       
level: present in 1 parsing errors
example: 
       void nsccfg_handler(void *opaque, int n, int level)
       {
           ARMSSE *s = ARMSSE(opaque);
       
n: present in 1 parsing errors
example: 
       void nsccfg_handler(void *opaque, int n, int level)
       {
           ARMSSE *s = ARMSSE(opaque);
       
nsccfg_handler: present in 1 parsing errors
example: 
       void nsccfg_handler(void *opaque, int n, int level)
       {
           ARMSSE *s = ARMSSE(opaque);
       
s: present in 1 parsing errors
example: 
       void nsccfg_handler(void *opaque, int n, int level)
       {
           ARMSSE *s = ARMSSE(opaque);
       
-----------------------------------------------------------------------
NB total files = 1; perfect = 0; pbs = 1; timeout = 0; =========> 0%
nb good = 0,  nb passed = 0 =========> 0.00% passed
nb good = 0,  nb bad = 7 =========> 0.00% good or passed
$ spatch --version
spatch version 1.0.7 compiled with OCaml version 4.07.0
Flags passed to the configure script: --build=x86_64-redhat-linux-gnu 
--host=x86_64-redhat-linux-gnu --program-prefix= --disable-dependency-tracking 
--prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin 
--sysconfdir=/etc --datadir=/usr/share --includedir=/usr/include 
--libdir=/usr/lib64 --libexecdir=/usr/libexec --localstatedir=/var 
--sharedstatedir=/var/lib --mandir=/usr/share/man --infodir=/usr/share/info 
--with-python=/usr/bin/python3 --with-menhir=/usr/bin/menhir
OCaml scripting support: yes
Python scripting support: yes
Syntax of regular expresssions: PCRE

_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

Reply via email to