aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/c-c++-common/cpp
diff options
context:
space:
mode:
authorLewis Hyatt <lhyatt@gmail.com>2023-01-14 13:29:22 -0500
committerLewis Hyatt <lhyatt@gmail.com>2023-03-13 07:40:50 -0400
commit336ce497fb266268a79544f00dd3bbd24cf3a4d6 (patch)
tree3762b202adc4ca0bb1ac761abf83fef2307e85ab /gcc/testsuite/c-c++-common/cpp
parent73dd5c6c887c8a5e849060cc8c9d03bdeeac6f72 (diff)
downloadgcc-336ce497fb266268a79544f00dd3bbd24cf3a4d6.zip
gcc-336ce497fb266268a79544f00dd3bbd24cf3a4d6.tar.gz
gcc-336ce497fb266268a79544f00dd3bbd24cf3a4d6.tar.bz2
libcpp: Fix ICE on directive inside _Pragma() operator [PR67046]
get__Pragma_string() in directives.cc is responsible for lexing the parens and the string argument from a _Pragma("...") operator. This function does not handle the case when the closing paren is not on the same line as the string; in that case, libcpp will by default reuse the token buffer it previously used for the string, so that the string token returned by get__Pragma_string() may be corrupted, as shown in the testcase. Fix using the existing keep_tokens mechanism that temporarily disables the reuse of token buffers. libcpp/ChangeLog: PR preprocessor/67046 * directives.cc (_cpp_do__Pragma): Increment pfile->keep_tokens to ensure the returned string token is valid. gcc/testsuite/ChangeLog: PR preprocessor/67046 * c-c++-common/cpp/pr67046.c: New test.
Diffstat (limited to 'gcc/testsuite/c-c++-common/cpp')
-rw-r--r--gcc/testsuite/c-c++-common/cpp/pr67046.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/gcc/testsuite/c-c++-common/cpp/pr67046.c b/gcc/testsuite/c-c++-common/cpp/pr67046.c
new file mode 100644
index 0000000..f37f20c
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/cpp/pr67046.c
@@ -0,0 +1,10 @@
+/* { dg-do preprocess } */
+
+_Pragma(
+"message(\"msg\")"
+)
+
+_Pragma(
+"message(\"msg\")"
+#
+)