* [pushed] recog: Fix insn_change_watermark destructor
@ 2021-01-15 16:49 Richard Sandiford
0 siblings, 0 replies; only message in thread
From: Richard Sandiford @ 2021-01-15 16:49 UTC (permalink / raw)
To: gcc-patches
Noticed while working on something else that the insn_change_watermark
destructor could call cancel_changes for changes that no longer exist.
The loop in cancel_changes is a nop in that case, but:
num_changes = num;
can mess things up.
I think this would only affect nested uses of insn_change_watermark.
Tested on aarch64-linux-gnu, aarch64_be-elf and x86_64-linux-gnu,
pushed as obvious.
Richard
gcc/
* recog.h (insn_change_watermark::~insn_change_watermark): Avoid
calling cancel_changes for changes that no longer exist.
---
gcc/recog.h | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/gcc/recog.h b/gcc/recog.h
index 269094a30f1..e96e66e99f2 100644
--- a/gcc/recog.h
+++ b/gcc/recog.h
@@ -547,13 +547,19 @@ class insn_change_watermark
{
public:
insn_change_watermark () : m_old_num_changes (num_validated_changes ()) {}
- ~insn_change_watermark () { cancel_changes (m_old_num_changes); }
+ ~insn_change_watermark ();
void keep () { m_old_num_changes = num_validated_changes (); }
private:
int m_old_num_changes;
};
+inline insn_change_watermark::~insn_change_watermark ()
+{
+ if (m_old_num_changes < num_validated_changes ())
+ cancel_changes (m_old_num_changes);
+}
+
#endif
#endif /* GCC_RECOG_H */
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-01-15 16:49 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-15 16:49 [pushed] recog: Fix insn_change_watermark destructor Richard Sandiford
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).