aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2021-11-22 22:29:20 +0100
committerJakub Jelinek <jakub@redhat.com>2021-11-22 22:29:20 +0100
commita6e0d593707ae44dec0bdf2bcdc4f539050b46db (patch)
treefe7bb778fb701be58becd51ac8c669b2f4bba8a6 /gcc
parenta944b5dec3adb28ed199234d2116145ca9010d6a (diff)
downloadgcc-a6e0d593707ae44dec0bdf2bcdc4f539050b46db.zip
gcc-a6e0d593707ae44dec0bdf2bcdc4f539050b46db.tar.gz
gcc-a6e0d593707ae44dec0bdf2bcdc4f539050b46db.tar.bz2
libcpp: Fix _Pragma stringification [PR103165]
As the testcase show, sometimes _Pragma is turned into CPP_PRAGMA .. CPP_PRAGMA_EOL tokens, even when it might still need to be stringized later on. We are then ICEing because we don't handle stringification of CPP_PRAGMA or CPP_PRAGMA_EOL, but trying to reconstruct the exact tokens with exact spacing after it has been lowered is very hard. So, instead this patch ensures we don't lower _Pragma during expand_arg calls, but only later when cpp_get_token_1 is called outside of expand_arg. 2021-11-22 Jakub Jelinek <jakub@redhat.com> Tobias Burnus <tobias@codesourcery.com> PR preprocessor/103165 libcpp/ * internal.h (struct lexer_state): Add ignore__Pragma field. * macro.c (builtin_macro): Don't interpret _Pragma if pfile->state.ignore__Pragma. (expand_arg): Temporarily set pfile->state.ignore__Pragma to 1. gcc/testsuite/ * c-c++-common/gomp/pragma-3.c: New test. * c-c++-common/gomp/pragma-4.c: New test. * c-c++-common/gomp/pragma-5.c: New test. Co-Authored-By: Tobias Burnus <tobias@codesourcery.com>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/testsuite/c-c++-common/gomp/pragma-3.c20
-rw-r--r--gcc/testsuite/c-c++-common/gomp/pragma-4.c20
-rw-r--r--gcc/testsuite/c-c++-common/gomp/pragma-5.c20
3 files changed, 60 insertions, 0 deletions
diff --git a/gcc/testsuite/c-c++-common/gomp/pragma-3.c b/gcc/testsuite/c-c++-common/gomp/pragma-3.c
new file mode 100644
index 0000000..c1dee1b
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/gomp/pragma-3.c
@@ -0,0 +1,20 @@
+/* { dg-additional-options "-fdump-tree-original" } */
+/* PR preprocessor/103165 */
+
+#define inner(...) #__VA_ARGS__ ; _Pragma("omp error severity(warning) message (\"Test\") at(compilation)")
+#define outer(...) inner(__VA_ARGS__)
+
+void
+f (void)
+{
+ const char *str = outer(inner(1,2)); /* { dg-warning "'pragma omp error' encountered: Test" } */
+}
+
+#if 0
+After preprocessing, the expected result are the following three lines:
+ const char *str = "\"1,2\" ; _Pragma(\"omp error severity(warning) message (\\\"Test\\\") at(compilation)\")" ;
+#pragma omp error severity(warning) message ("Test") at(compilation)
+ ;
+#endif
+
+/* { dg-final { scan-tree-dump "const char \\* str = \\(const char \\*\\) \"\\\\\"1,2\\\\\" ; _Pragma\\(\\\\\"omp error severity\\(warning\\) message \\(\\\\\\\\\\\\\"Test\\\\\\\\\\\\\"\\) at\\(compilation\\)\\\\\"\\)\";" "original" } } */
diff --git a/gcc/testsuite/c-c++-common/gomp/pragma-4.c b/gcc/testsuite/c-c++-common/gomp/pragma-4.c
new file mode 100644
index 0000000..419c4ac
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/gomp/pragma-4.c
@@ -0,0 +1,20 @@
+/* { dg-additional-options "-fdump-tree-original -save-temps" } */
+/* PR preprocessor/103165 */
+
+#define inner(...) #__VA_ARGS__ ; _Pragma("omp error severity(warning) message (\"Test\") at(compilation)")
+#define outer(...) inner(__VA_ARGS__)
+
+void
+f (void)
+{
+ const char *str = outer(inner(1,2)); /* { dg-warning "'pragma omp error' encountered: Test" } */
+}
+
+#if 0
+After preprocessing, the expected result are the following three lines:
+ const char *str = "\"1,2\" ; _Pragma(\"omp error severity(warning) message (\\\"Test\\\") at(compilation)\")" ;
+#pragma omp error severity(warning) message ("Test") at(compilation)
+ ;
+#endif
+
+/* { dg-final { scan-tree-dump "const char \\* str = \\(const char \\*\\) \"\\\\\"1,2\\\\\" ; _Pragma\\(\\\\\"omp error severity\\(warning\\) message \\(\\\\\\\\\\\\\"Test\\\\\\\\\\\\\"\\) at\\(compilation\\)\\\\\"\\)\";" "original" } } */
diff --git a/gcc/testsuite/c-c++-common/gomp/pragma-5.c b/gcc/testsuite/c-c++-common/gomp/pragma-5.c
new file mode 100644
index 0000000..af54b68
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/gomp/pragma-5.c
@@ -0,0 +1,20 @@
+/* { dg-additional-options "-fdump-tree-original" } */
+/* PR preprocessor/103165 */
+
+#define inner(...) #__VA_ARGS__ ; _Pragma ( " omp error severity (warning) message (\"Test\") at(compilation)" )
+#define outer(...) inner(__VA_ARGS__)
+
+void
+f (void)
+{
+ const char *str = outer(inner(1,2)); /* { dg-warning "'pragma omp error' encountered: Test" } */
+}
+
+#if 0
+After preprocessing, the expected result are the following three lines:
+ const char *str = "\"1,2\" ; _Pragma ( \" omp error severity (warning) message (\\\"Test\\\") at(compilation)\" )" ;
+#pragma omp error severity(warning) message ("Test") at(compilation)
+ ;
+#endif
+
+/* { dg-final { scan-tree-dump "const char \\* str = \\(const char \\*\\) \"\\\\\"1,2\\\\\" ; _Pragma \\( \\\\\" omp\\\\t\\\\terror severity \\(warning\\)\\\\tmessage \\(\\\\\\\\\\\\\"Test\\\\\\\\\\\\\"\\) at\\(compilation\\)\\\\\" \\)\";" "original" } } */