aboutsummaryrefslogtreecommitdiff
path: root/gcc/edit-context.cc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2023-09-28 11:59:10 +0200
committerJakub Jelinek <jakub@redhat.com>2023-09-28 12:06:03 +0200
commit73cd319b72ca45a537688cc8cc5751d86a00a0e9 (patch)
treeddd9a53aabcc4dab86d92ae74b8d9b3e7b44800f /gcc/edit-context.cc
parent46595ce72e5855189e3c60a140c3ca5aaddfb58c (diff)
downloadgcc-73cd319b72ca45a537688cc8cc5751d86a00a0e9.zip
gcc-73cd319b72ca45a537688cc8cc5751d86a00a0e9.tar.gz
gcc-73cd319b72ca45a537688cc8cc5751d86a00a0e9.tar.bz2
vec.h: Make some ops work with non-trivially copy constructible and/or destructible types
We have some very limited support for non-POD types in vec.h (in particular grow_cleared will invoke default ctors on the cleared elements and vector copying invokes copy ctors. My pending work on wide_int/widest_int which makes those two non-trivially default constructible, copyable and destructible shows this isn't enough though. In particular the uses of it in irange shows that quick_push still uses just assignment operator rather than copy construction and we never invoke destructors on anything. The following patch does that for quick_push (copy construction using placement new rather than assignment, for trivially copy constructible types I think it should be the same) and invokes destructors (only if non-trivially destructible) in pop, release and truncate. Now as discussed last night on IRC, the pop case is problematic, because our pop actually does two things, it decreases length (so the previous last element should be destructed) but also returns a reference to it. We have some 300+ uses of this and the reference rather than returning it by value is useful at least for the elements which are (larger) POD structures, so I'm not prepared to change that. Though obviously for types with non-trivial destructors returning a reference to just destructed element is not a good idea. So, this patch for that case only makes pop return void instead and any users wishing to get the last element need to use last () and pop () separately (currently there are none). Note, a lot of vec.h operations is still not friendly for non-POD types, and the patch tries to enforce that through static asserts. Some operations are now only allowed on trivially copyable types, sorting operations as an extension on trivially copyable types or std::pair of 2 trivially copyable types, quick_grow/safe_grow (but not _cleared variants) for now have a commented out assert on trivially default constructible types - this needs some further work before the assert can be enabled - and finally all va_gc/va_gc_atomic vectors require trivially destructible types. 2023-09-28 Jakub Jelinek <jakub@redhat.com> Jonathan Wakely <jwakely@redhat.com> * vec.h: Mention in file comment limited support for non-POD types in some operations. (vec_destruct): New function template. (release): Use it for non-trivially destructible T. (truncate): Likewise. (quick_push): Perform a placement new into slot instead of assignment. (pop): For non-trivially destructible T return void rather than T & and destruct the popped element. (quick_insert, ordered_remove): Note that they aren't suitable for non-trivially copyable types. Add static_asserts for that. (block_remove): Assert T is trivially copyable. (vec_detail::is_trivially_copyable_or_pair): New trait. (qsort, sort, stablesort): Assert T is trivially copyable or std::pair with both trivally copyable types. (quick_grow): Add assert T is trivially default constructible, for now commented out. (quick_grow_cleared): Don't call quick_grow, instead inline it by hand except for the new static_assert. (gt_ggc_mx): Assert T is trivially destructable. (auto_vec::operator=): Formatting fixes. (auto_vec::auto_vec): Likewise. (vec_safe_grow_cleared): Don't call vec_safe_grow, instead inline it manually and call quick_grow_cleared method rather than quick_grow. (safe_grow_cleared): Likewise. * edit-context.cc (class line_event): Move definition earlier. * tree-ssa-loop-im.cc (seq_entry::seq_entry): Make default ctor defaulted. * ipa-fnsummary.cc (evaluate_properties_for_edge): Use safe_grow_cleared instead of safe_grow followed by placement new constructing the elements.
Diffstat (limited to 'gcc/edit-context.cc')
-rw-r--r--gcc/edit-context.cc52
1 files changed, 26 insertions, 26 deletions
diff --git a/gcc/edit-context.cc b/gcc/edit-context.cc
index 6f5bc6b..09b000c 100644
--- a/gcc/edit-context.cc
+++ b/gcc/edit-context.cc
@@ -122,6 +122,32 @@ class added_line
int m_len;
};
+/* Class for representing edit events that have occurred on one line of
+ one file: the replacement of some text betweeen some columns
+ on the line.
+
+ Subsequent events will need their columns adjusting if they're
+ are on this line and their column is >= the start point. */
+
+class line_event
+{
+ public:
+ line_event (int start, int next, int len) : m_start (start),
+ m_delta (len - (next - start)) {}
+
+ int get_effective_column (int orig_column) const
+ {
+ if (orig_column >= m_start)
+ return orig_column += m_delta;
+ else
+ return orig_column;
+ }
+
+ private:
+ int m_start;
+ int m_delta;
+};
+
/* The state of one edited line within an edited_file.
As well as the current content of the line, it contains a record of
the changes, so that further changes can be applied in the correct
@@ -172,32 +198,6 @@ class edited_line
auto_vec <added_line *> m_predecessors;
};
-/* Class for representing edit events that have occurred on one line of
- one file: the replacement of some text betweeen some columns
- on the line.
-
- Subsequent events will need their columns adjusting if they're
- are on this line and their column is >= the start point. */
-
-class line_event
-{
- public:
- line_event (int start, int next, int len) : m_start (start),
- m_delta (len - (next - start)) {}
-
- int get_effective_column (int orig_column) const
- {
- if (orig_column >= m_start)
- return orig_column += m_delta;
- else
- return orig_column;
- }
-
- private:
- int m_start;
- int m_delta;
-};
-
/* Forward decls. */
static void