public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] rs6000: avoid peeking eof after __vector
@ 2022-05-09 10:19 Jiufu Guo
  2022-05-09 14:01 ` Segher Boessenkool
  0 siblings, 1 reply; 3+ messages in thread
From: Jiufu Guo @ 2022-05-09 10:19 UTC (permalink / raw)
  To: gcc-patches; +Cc: segher, dje.gcc, linkw, guojiufu

Hi!

This patch is based on:
https://gcc.gnu.org/pipermail/gcc-patches/2022-March/592102.html
And update the 'function comment' to make it consistent with code.

There is a rare corner case: where vector is followed only by one
valid identifer and the ";" which is near the end of the file.

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

For this case, "vector double" is followed by CPP_SEMICOLON and then
EOF.  There is no more tokens need to check for this case.

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               | 9 +++++----
 gcc/testsuite/g++.target/powerpc/pr101168.C | 6 ++++++
 2 files changed, 11 insertions(+), 4 deletions(-)
 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 84bb98f94fb..9c8cbd7a66e 100644
--- a/gcc/config/rs6000/rs6000-c.cc
+++ b/gcc/config/rs6000/rs6000-c.cc
@@ -178,9 +178,8 @@ rid_int128(void)
   return RID_MAX + 1;
 }
 
-/* Called to decide whether a conditional macro should be expanded.
-   Since we have exactly one such macro (i.e, 'vector'), we do not
-   need to examine the 'tok' parameter.  */
+/* Called to decide whether a conditional macro should be expanded
+   by peeking two or more tokens(_bool/_pixel/int/long/double/...).  */
 
 static cpp_hashnode *
 rs6000_macro_to_expand (cpp_reader *pfile, const cpp_token *tok)
@@ -282,7 +281,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 there are more tokens to check.  */
+	      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] 3+ messages in thread

* Re: [PATCH] rs6000: avoid peeking eof after __vector
  2022-05-09 10:19 [PATCH] rs6000: avoid peeking eof after __vector Jiufu Guo
@ 2022-05-09 14:01 ` Segher Boessenkool
  2022-05-10  6:26   ` Jiufu Guo
  0 siblings, 1 reply; 3+ messages in thread
From: Segher Boessenkool @ 2022-05-09 14:01 UTC (permalink / raw)
  To: Jiufu Guo; +Cc: gcc-patches, dje.gcc, linkw

Hi!

On Mon, May 09, 2022 at 06:19:45PM +0800, Jiufu Guo wrote:
> There is a rare corner case: where vector is followed only by one
> valid identifer and the ";" which is near the end of the file.
> 
> Like the case in PR101168:
> using vdbl =  __vector double;
> #define BREAK 1
> 
> For this case, "vector double" is followed by CPP_SEMICOLON and then
> EOF.  There is no more tokens need to check for this case.

One tiny comment/hint:

> --- /dev/null
> +++ b/gcc/testsuite/g++.target/powerpc/pr101168.C
> @@ -0,0 +1,6 @@
> +/* { dg-do compile } */

This is the default, you can leave it out if you want.

Okay for trunk with or without it.  Thanks!


Segher

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

* Re: [PATCH] rs6000: avoid peeking eof after __vector
  2022-05-09 14:01 ` Segher Boessenkool
@ 2022-05-10  6:26   ` Jiufu Guo
  0 siblings, 0 replies; 3+ messages in thread
From: Jiufu Guo @ 2022-05-10  6:26 UTC (permalink / raw)
  To: Segher Boessenkool; +Cc: gcc-patches, dje.gcc, linkw

Segher Boessenkool <segher@kernel.crashing.org> writes:

> Hi!
>
> On Mon, May 09, 2022 at 06:19:45PM +0800, Jiufu Guo wrote:
>> There is a rare corner case: where vector is followed only by one
>> valid identifer and the ";" which is near the end of the file.
>> 
>> Like the case in PR101168:
>> using vdbl =  __vector double;
>> #define BREAK 1
>> 
>> For this case, "vector double" is followed by CPP_SEMICOLON and then
>> EOF.  There is no more tokens need to check for this case.
>
> One tiny comment/hint:
>
>> --- /dev/null
>> +++ b/gcc/testsuite/g++.target/powerpc/pr101168.C
>> @@ -0,0 +1,6 @@
>> +/* { dg-do compile } */
>
> This is the default, you can leave it out if you want.
>
> Okay for trunk with or without it.  Thanks!
Thanks!  Committed as r13-220.

BR,
Jiufu

>
>
> Segher

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

end of thread, other threads:[~2022-05-10  6:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-09 10:19 [PATCH] rs6000: avoid peeking eof after __vector Jiufu Guo
2022-05-09 14:01 ` Segher Boessenkool
2022-05-10  6:26   ` 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).