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

2020-08-31 Thread Richard Biener via Gcc-patches
On Fri, Aug 28, 2020 at 10:04 PM Austin Morton  wrote:
>
> > The patch misses documentation of the pragma.
>
> This was an intentional omission - when looking for documentation of
> the pragma in clang I found none.
>
> If we do want to document the pragmas in GCC:
>  - what section of the documentation would that go in?
> - gcc/doc/cpp.texi, section 7, "Pragmas"
> - this section states: "This manual documents the pragmas
> which are meaningful to the preprocessor itself. Other pragmas are
> meaningful to the C or C++ compilers. They are documented in the GCC
> manual."
> - these pragmas aren't exactly meaningful to the preprocessor
> _or_ the C/C++ compiler, so it's not exactly clear where they fit.
> - gcc/doc/extend.texi, section 6.62, "Pragmas Accepted by GCC"
>  - what exactly would it say?
> - I guess just mention the existence and that they won't trigger
> unknown pragma warnings? They don't _do_ anything

Yes, documenting their existance and their zero effect.

Richard.

>
> Austin


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

2020-08-28 Thread Austin Morton via Gcc-patches
> The patch misses documentation of the pragma.

This was an intentional omission - when looking for documentation of
the pragma in clang I found none.

If we do want to document the pragmas in GCC:
 - what section of the documentation would that go in?
- gcc/doc/cpp.texi, section 7, "Pragmas"
- this section states: "This manual documents the pragmas
which are meaningful to the preprocessor itself. Other pragmas are
meaningful to the C or C++ compilers. They are documented in the GCC
manual."
- these pragmas aren't exactly meaningful to the preprocessor
_or_ the C/C++ compiler, so it's not exactly clear where they fit.
- gcc/doc/extend.texi, section 6.62, "Pragmas Accepted by GCC"
 - what exactly would it say?
- I guess just mention the existence and that they won't trigger
unknown pragma warnings? They don't _do_ anything

Austin


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

2020-08-28 Thread Richard Biener via Gcc-patches
On Fri, Aug 28, 2020 at 3:26 AM Austin Morton via Gcc-patches
 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  
> +
> + PR c/85487
> + * c-pragma.c (handle_pragma_region): Declare.
> +
>  2020-08-11  Jakub Jelinek  
>
>   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  
> +
> + PR c/85487
> + * gcc.dg/pragma-region.c: New test.
> +
>  2020-08-26  Jeff Law  
>
>   * 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 0..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


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

2020-08-27 Thread Austin Morton via Gcc-patches
#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.


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  
+
+ PR c/85487
+ * c-pragma.c (handle_pragma_region): Declare.
+
 2020-08-11  Jakub Jelinek  

  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  
+
+ PR c/85487
+ * gcc.dg/pragma-region.c: New test.
+
 2020-08-26  Jeff Law  

  * 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 0..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