public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <richard.guenther@gmail.com>
To: Austin Morton <austinpmorton@gmail.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] c: Silently ignore pragma region [PR85487]
Date: Fri, 28 Aug 2020 09:20:52 +0200	[thread overview]
Message-ID: <CAFiYyc0qt5yJe8BYK0uT55HzcinWFM915Z-sdOY9YCS4ogMCWw@mail.gmail.com> (raw)
In-Reply-To: <CAPWKHJSJnSZ+ak5aDOiV4za5XYQKyyvvs_6zEKpVadEaWTq64w@mail.gmail.com>

On Fri, Aug 28, 2020 at 3:26 AM Austin Morton via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> #pragma region is a feature introduced by Microsoft in order to allow
> manual grouping and folding of code within Visual Studio.  It is
> entirely ignored by the compiler.  Clang has supported this feature
> since 2012 when in MSVC compatibility mode, and enabled it across the
> board 3 months ago.
>
> As it stands, you cannot use #pragma region within GCC without
> disabling unknown pragma warnings, which is not advisable.
>
> I propose GCC adopt "#pragma region" and "#pragma endregion" in order
> to alleviate these issues.  Because the pragma has no purpose at
> compile time, the implementation is trivial.

The patch misses documentation of the pragma.

Richard.

>
> Microsoft Documentation on the feature:
> https://docs.microsoft.com/en-us/cpp/preprocessor/region-endregion
>
> LLVM change which enabled pragma region across the board:
> https://reviews.llvm.org/D42248
>
> ---
>  gcc/c-family/ChangeLog               |  5 +++++
>  gcc/c-family/c-pragma.c              | 10 ++++++++++
>  gcc/testsuite/ChangeLog              |  5 +++++
>  gcc/testsuite/gcc.dg/pragma-region.c | 21 +++++++++++++++++++++
>  4 files changed, 41 insertions(+)
>  create mode 100644 gcc/testsuite/gcc.dg/pragma-region.c
>
> diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
> index 1eaa99f31..97ba259cd 100644
> --- a/gcc/c-family/ChangeLog
> +++ b/gcc/c-family/ChangeLog
> @@ -1,3 +1,8 @@
> +2020-08-27  Austin Morton  <austinpmorton@gmail.com>
> +
> + PR c/85487
> + * c-pragma.c (handle_pragma_region): Declare.
> +
>  2020-08-11  Jakub Jelinek  <jakub@redhat.com>
>
>   PR c/96545
> diff --git a/gcc/c-family/c-pragma.c b/gcc/c-family/c-pragma.c
> index e3169e68f..de0411d07 100644
> --- a/gcc/c-family/c-pragma.c
> +++ b/gcc/c-family/c-pragma.c
> @@ -1166,6 +1166,13 @@ handle_pragma_message (cpp_reader *ARG_UNUSED(dummy))
>      TREE_STRING_POINTER (message));
>  }
>
> +/* Silently ignore region pragmas.  */
> +
> +static void
> +handle_pragma_region (cpp_reader *ARG_UNUSED(dummy))
> +{
> +}
> +
>  /* Mark whether the current location is valid for a STDC pragma.  */
>
>  static bool valid_location_for_stdc_pragma;
> @@ -1584,6 +1591,9 @@ init_pragma (void)
>
>    c_register_pragma_with_expansion (0, "message", handle_pragma_message);
>
> +  c_register_pragma (0, "region", handle_pragma_region);
> +  c_register_pragma (0, "endregion", handle_pragma_region);
> +
>  #ifdef REGISTER_TARGET_PRAGMAS
>    REGISTER_TARGET_PRAGMAS ();
>  #endif
> diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
> index 5c1a45716..4033c111c 100644
> --- a/gcc/testsuite/ChangeLog
> +++ b/gcc/testsuite/ChangeLog
> @@ -1,3 +1,8 @@
> +2020-08-27  Austin Morton  <austinpmorton@gmail.com>
> +
> + PR c/85487
> + * gcc.dg/pragma-region.c: New test.
> +
>  2020-08-26  Jeff Law  <law@redhat.com>
>
>   * gcc.target/i386/387-7.c: Add dg-require-effective-target c99_runtime.
> diff --git a/gcc/testsuite/gcc.dg/pragma-region.c
> b/gcc/testsuite/gcc.dg/pragma-region.c
> new file mode 100644
> index 000000000..72cc2c144
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/pragma-region.c
> @@ -0,0 +1,21 @@
> +/* Verify #pragma region and #pragma endregion do not emit warnings.  */
> +
> +/* { dg-options "-Wunknown-pragmas" } */
> +
> +#pragma region
> +
> +#pragma region name
> +
> +#pragma region "name"
> +
> +#pragma region()
> +
> +#pragma region("name")
> +
> +#pragma endregion
> +
> +#pragma endregion garbage
> +
> +#pragma endregion()
> +
> +#pragma endregion("garbage")
> --
> 2.17.1

  reply	other threads:[~2020-08-28  7:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-28  1:25 Austin Morton
2020-08-28  7:20 ` Richard Biener [this message]
2020-08-28 20:04   ` Austin Morton
2020-08-31  8:06     ` Richard Biener

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=CAFiYyc0qt5yJe8BYK0uT55HzcinWFM915Z-sdOY9YCS4ogMCWw@mail.gmail.com \
    --to=richard.guenther@gmail.com \
    --cc=austinpmorton@gmail.com \
    --cc=gcc-patches@gcc.gnu.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).