public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH]rs6000: avoid peeking eof after __vector keyword
@ 2022-03-21  9:13 Jiufu Guo
  2022-03-21 18:14 ` David Edelsohn
  0 siblings, 1 reply; 6+ messages in thread
From: Jiufu Guo @ 2022-03-21  9:13 UTC (permalink / raw)
  To: gcc-patches; +Cc: segher, dje.gcc, guojiufu

Hi!

There is a rare corner case: where __vector is followed only with ";"
and near the end of the file.

Like the case in PR101168:
using vdbl =  __vector double;
#define BREAK 1

For this case, "__vector double" is not followed by a PP_NAME, it is
followed by CPP_SEMICOLON and then EOF.  In this case, there is no
more tokens in the file.  Then, do not need to continue to parse the
file.

This patch pass bootstrap and regtest on ppc64 and ppc64le.


BR,
Jiufu


	PR preprocessor/101168

gcc/ChangeLog:

	* config/rs6000/rs6000-c.cc (rs6000_macro_to_expand):
	Avoid empty identifier.

gcc/testsuite/ChangeLog:

	* g++.target/powerpc/pr101168.C: New test.


---
 gcc/config/rs6000/rs6000-c.cc               | 4 +++-
 gcc/testsuite/g++.target/powerpc/pr101168.C | 6 ++++++
 2 files changed, 9 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.target/powerpc/pr101168.C

diff --git a/gcc/config/rs6000/rs6000-c.cc b/gcc/config/rs6000/rs6000-c.cc
index 3b62b499df2..f8cc7bad812 100644
--- a/gcc/config/rs6000/rs6000-c.cc
+++ b/gcc/config/rs6000/rs6000-c.cc
@@ -282,7 +282,9 @@ rs6000_macro_to_expand (cpp_reader *pfile, const cpp_token *tok)
 		expand_bool_pixel = __pixel_keyword;
 	      else if (ident == C_CPP_HASHNODE (__bool_keyword))
 		expand_bool_pixel = __bool_keyword;
-	      else
+
+	      /* If it needs to check tokens continue.  */
+	      else if (ident)
 		{
 		  /* Try two tokens down, too.  */
 		  do
diff --git a/gcc/testsuite/g++.target/powerpc/pr101168.C b/gcc/testsuite/g++.target/powerpc/pr101168.C
new file mode 100644
index 00000000000..284e77fdc88
--- /dev/null
+++ b/gcc/testsuite/g++.target/powerpc/pr101168.C
@@ -0,0 +1,6 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target powerpc_altivec_ok } */
+/* { dg-options "-maltivec" } */
+
+using vdbl =  __vector double;
+#define BREAK 1
-- 
2.25.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-03-23  3:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-21  9:13 [PATCH]rs6000: avoid peeking eof after __vector keyword Jiufu Guo
2022-03-21 18:14 ` David Edelsohn
2022-03-21 18:34   ` Segher Boessenkool
2022-03-22  5:50     ` Jiufu Guo
2022-03-22 14:25       ` Segher Boessenkool
2022-03-23  3:37         ` Jiufu Guo

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).