public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH 1/3] Change 'v1' float and int code to fall back to v0
Date: Mon, 26 Feb 2024 20:12:54 -0700	[thread overview]
Message-ID: <20240226-gdb-compile-align-v1-1-0f95d6435299@tromey.com> (raw)
In-Reply-To: <20240226-gdb-compile-align-v1-0-0f95d6435299@tromey.com>

While working on another patch, I discovered that the libcc1 plugin
code never did version negotiation correctly.  So, the patches to
introduce v1 never did anything -- the new code, as far as I know, has
never been run.

Making version negotiation work shows that the existing code causes
crashes.  For example, safe_lookup_builtin_type might return
error_mark_node in some cases, which the callers aren't prepared to
accept.

Looking into it some more, I couldn't find any justification for this
v1 code for the C compiler plugin.  Since it's not run at all, it's
also clear that removing it doesn't cause any regressions in gdb.

However, rather than remove it, this patch changes it to handle
ERROR_MARK better, and then to fall back to the v0 code if the new
code fails to find the type it's looking for.

2024-02-26  Tom Tromey  <tom@tromey.com>

	* libcc1plugin.cc (safe_lookup_builtin_type): Handle ERROR_MARK.
	(plugin_int_type): Fall back to plugin_int_type_v0.
	(plugin_float_type): Fall back to plugin_float_type_v0.
---
 libcc1/ChangeLog       |  6 ++++++
 libcc1/libcc1plugin.cc | 19 ++++++++++---------
 2 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/libcc1/ChangeLog b/libcc1/ChangeLog
index f81fe389e71..b0b31ee6586 100644
--- a/libcc1/ChangeLog
+++ b/libcc1/ChangeLog
@@ -1,3 +1,9 @@
+2024-02-26  Tom Tromey  <tom@tromey.com>
+
+	* libcc1plugin.cc (safe_lookup_builtin_type): Handle ERROR_MARK.
+	(plugin_int_type): Fall back to plugin_int_type_v0.
+	(plugin_float_type): Fall back to plugin_float_type_v0.
+
 2024-02-09  Marek Polacek  <polacek@redhat.com>
 
 	PR c++/98388
diff --git a/libcc1/libcc1plugin.cc b/libcc1/libcc1plugin.cc
index 00d3963029d..f1082d8e9d3 100644
--- a/libcc1/libcc1plugin.cc
+++ b/libcc1/libcc1plugin.cc
@@ -555,7 +555,7 @@ safe_lookup_builtin_type (const char *builtin_name)
 
   gcc_assert (TREE_CODE (result) == TYPE_DECL);
   result = TREE_TYPE (result);
-  return result;
+  return TREE_CODE (result) == ERROR_MARK ? nullptr : result;
 }
 
 static gcc_type
@@ -592,13 +592,14 @@ plugin_int_type (cc1_plugin::connection *self,
 		 int is_unsigned, unsigned long size_in_bytes,
 		 const char *builtin_name)
 {
-  if (!builtin_name)
-    return plugin_int_type_v0 (self, is_unsigned, size_in_bytes);
-
-  tree result = safe_lookup_builtin_type (builtin_name);
-  gcc_assert (!result || TREE_CODE (result) == INTEGER_TYPE);
-
-  return plugin_int_check (self, is_unsigned, size_in_bytes, result);
+  if (builtin_name != nullptr)
+    {
+      tree result = safe_lookup_builtin_type (builtin_name);
+      gcc_assert (!result || TREE_CODE (result) == INTEGER_TYPE);
+      if (result != nullptr)
+	return plugin_int_check (self, is_unsigned, size_in_bytes, result);
+    }
+  return plugin_int_type_v0 (self, is_unsigned, size_in_bytes);
 }
 
 gcc_type
@@ -631,7 +632,7 @@ plugin_float_type (cc1_plugin::connection *self,
   tree result = safe_lookup_builtin_type (builtin_name);
 
   if (!result)
-    return convert_out (error_mark_node);
+    return plugin_float_type_v0 (self, size_in_bytes);
 
   gcc_assert (SCALAR_FLOAT_TYPE_P (result));
   gcc_assert (BITS_PER_UNIT * size_in_bytes == TYPE_PRECISION (result));

-- 
2.43.0


  reply	other threads:[~2024-02-27  3:13 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-27  3:12 [PATCH 0/3] Fix libcc1 failure Tom Tromey
2024-02-27  3:12 ` Tom Tromey [this message]
2024-02-27 15:14   ` [PATCH 1/3] Change 'v1' float and int code to fall back to v0 Jeff Law
2024-02-28 22:57     ` Tom Tromey
2024-02-28 23:26       ` Jeff Law
2024-02-29  0:43         ` Andrew Pinski
2024-02-29  1:35           ` Tom Tromey
2024-02-29  2:37             ` Andrew Pinski
2024-02-29 22:55         ` Tom Tromey
2024-02-27  3:12 ` [PATCH 2/3] Fix version negotiation in libcc1 plugins Tom Tromey
2024-02-27  3:12 ` [PATCH 3/3] Fix PR libcc1/113977 Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240226-gdb-compile-align-v1-1-0f95d6435299@tromey.com \
    --to=tom@tromey.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).