[10/10] Add spaceship operator to cp-name-parser.y

Message ID 20240421-canon-fixes-v1-10-4dc4791d270d@tromey.com
State New
Headers
Series Fix some C++ name canonicalizer problems |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 fail Patch failed to apply
linaro-tcwg-bot/tcwg_gdb_build--master-arm fail Patch failed to apply

Commit Message

Tom Tromey April 21, 2024, 5 p.m. UTC
  While debugging gdb, I saw this:

During symbol reading: unexpected demangled name 'operator<=><std::chrono::_V2::system_clock, std::chrono::duration<long int>, std::chrono::duration<long int> >'

This happens because cp-name-parser.y does not handle the spaceship
operator.  This patch implements this.
---
 gdb/cp-name-parser.y | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
  

Comments

John Baldwin April 22, 2024, 5:31 p.m. UTC | #1
On 4/21/24 10:00 AM, Tom Tromey wrote:
> While debugging gdb, I saw this:
> 
> During symbol reading: unexpected demangled name 'operator<=><std::chrono::_V2::system_clock, std::chrono::duration<long int>, std::chrono::duration<long int> >'
> 
> This happens because cp-name-parser.y does not handle the spaceship
> operator.  This patch implements this.

Approved-By: John Baldwin <jhb@FreeBSD.org>
  

Patch

diff --git a/gdb/cp-name-parser.y b/gdb/cp-name-parser.y
index e820faa2db9..db5c349d212 100644
--- a/gdb/cp-name-parser.y
+++ b/gdb/cp-name-parser.y
@@ -297,7 +297,7 @@  static void yyerror (cpname_state *, const char *);
 %left '^'
 %left '&'
 %left EQUAL NOTEQUAL
-%left '<' '>' LEQ GEQ
+%left '<' '>' LEQ GEQ SPACESHIP
 %left LSH RSH
 %left '@'
 %left '+' '-'
@@ -451,6 +451,8 @@  oper	:	OPERATOR NEW
 			{ $$ = state->make_operator ("<=", 2); }
 		|	OPERATOR GEQ
 			{ $$ = state->make_operator (">=", 2); }
+		|	OPERATOR SPACESHIP
+			{ $$ = state->make_operator ("<=>", 2); }
 		|	OPERATOR ANDAND
 			{ $$ = state->make_operator ("&&", 2); }
 		|	OPERATOR OROR
@@ -1077,6 +1079,10 @@  exp	:	exp GEQ exp
 		{ $$ = state->d_binary (">=", $1, $3); }
 	;
 
+exp	:	exp SPACESHIP exp
+		{ $$ = state->d_binary ("<=>", $1, $3); }
+	;
+
 exp	:	exp '<' exp
 		{ $$ = state->d_binary ("<", $1, $3); }
 	;
@@ -1783,6 +1789,7 @@  yylex (YYSTYPE *lvalp, cpname_state *state)
       return c;
     case '<':
       HANDLE_TOKEN3 ("<<=", ASSIGN_MODIFY);
+      HANDLE_TOKEN3 ("<=>", SPACESHIP);
       HANDLE_TOKEN2 ("<=", LEQ);
       HANDLE_TOKEN2 ("<<", LSH);
       state->lexptr++;
@@ -2052,6 +2059,14 @@  should_be_the_same (const char *one, const char *two)
   SELF_CHECK (strcmp (one, two) == 0);
 }
 
+static void
+should_parse (const char *name)
+{
+  std::string err;
+  auto parsed = cp_demangled_name_to_comp (name, &err);
+  SELF_CHECK (parsed != nullptr);
+}
+
 static void
 canonicalize_tests ()
 {
@@ -2070,6 +2085,8 @@  canonicalize_tests ()
 
   should_be_the_same ("something<void ()>", "something<  void()  >");
   should_be_the_same ("something<void ()>", "something<void (void)>");
+
+  should_parse ("void whatever::operator<=><int, int>");
 }
 
 #endif