All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christopher Li <sparse@chrisli.org>
To: foobar <foobar@redchan.it>
Cc: Linux-Sparse <linux-sparse@vger.kernel.org>
Subject: Re: [RFC] proper handling of #pragma
Date: Fri, 5 Jan 2018 01:42:40 +0800	[thread overview]
Message-ID: <CANeU7QkPd43nBga-YOMv6p8NYesH4U7ao+AsZiz=ZCc12diJMA@mail.gmail.com> (raw)
In-Reply-To: <20180103161419.a43208d5469c43ff36b3d2e1@redchan.it>

On Thu, Jan 4, 2018 at 12:14 AM, foobar <foobar@redchan.it> wrote:
> #pragma directives other than #pragma once are not really meant for the preprocessor to consume.

I am not sure I understand this. #pragma is not part of the normal C
language grammar.
It should be consumed at the preprocessor stage, it has some side effect
for the compiler.

>
> in preprocessor_only mode, apart from pragma once, they should all be printed to stdout (unless they are under #ifdef that's not taken).

I wonder what does the C spec say about this.

> i've produced a patch that does that, however i'm not really happy about it, since i'm unclear about how to deal
> with the pragma in non-preprocessor mode.
>
> i suppose the token-stream of the pragma-directive should be converted into some kind of special symbol, which can then be either consumed or ignored when doing the usual iteration over the symbol list.
> but i didn't find an obvious symbol type to assign...

If it is preprocessor symbol. It does not need to have C type. It can
have the name space
set to preprocessor. In theory you can also have a symbol_list keep track of
all the pragma you see in the source file. Not sure that will serve
you any purpose.

> (my plan is to create a build tool based on sparse that gets directives as a special pragma).
>
> thanks!
>
> testcode:
> #pragma once
> #if 1
> #pragma omp wanna "see this" in cpp output
> #else
> #pragma omp nope "this one not"
> #endif
>
> here's the initial version of my patch
>
> Subject: [PATCH] preprocessor: properly emit #pragma directives
>
> 3 months after the first commit, handling of pragma directives was
> implemented, with the idea of turning the token into __pragma__ for
> later internal consumption. however never anything came out of this idea,
> and #pragma was basically left broken. apart from #pragma once, the
> directive needs to persist in the preprocessor output, it is for later
> consumption of the compiler (apparently the assumption was that sparse
> would never be used as a stand-alone preprocessor).

If __pragma__ exist pass the preprocessor stage.
It can appear in any part of the C source file. The C parser need
to consume it at almost any context. That will really complicate stuff.
I think that is a bad idea.

There might be other ways to do what you want.

If it is pre-processor only, then that might be fine. Because there is
no C parser to consume the output.

Chris

  reply	other threads:[~2018-01-04 17:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-03 16:14 [RFC] proper handling of #pragma foobar
2018-01-04 17:42 ` Christopher Li [this message]
2018-01-20 15:12 ` Luc Van Oostenryck

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='CANeU7QkPd43nBga-YOMv6p8NYesH4U7ao+AsZiz=ZCc12diJMA@mail.gmail.com' \
    --to=sparse@chrisli.org \
    --cc=foobar@redchan.it \
    --cc=linux-sparse@vger.kernel.org \
    /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.