[PATCH] c: Silently ignore pragma region [PR85487]

Richard Biener richard.guenther@gmail.com
Fri Aug 28 07:20:52 GMT 2020


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


More information about the Gcc-patches mailing list