All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: cocci@systeme.lip6.fr
Subject: [Cocci] Function-like macro with the same name as a typedef -> parse error
Date: Mon, 06 Apr 2020 09:46:58 +0200	[thread overview]
Message-ID: <875zed839p.fsf@dusky.pond.sub.org> (raw)

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	other threads:[~2020-04-06  8:05 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=875zed839p.fsf@dusky.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=cocci@systeme.lip6.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.