[gcc r14-7656] gccrs: libproc_macro: Fix Tokenstream growth
Arthur Cohen
cohenarthur@gcc.gnu.org
Tue Jan 16 17:51:07 GMT 2024
https://gcc.gnu.org/g:cf58150bea85a633247c77f1989c6389c8eb7974
commit r14-7656-gcf58150bea85a633247c77f1989c6389c8eb7974
Author: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Date: Tue May 23 16:45:08 2023 +0200
gccrs: libproc_macro: Fix Tokenstream growth
TokenStream did not copy back enough old data to the new location. This
commit also add more explicit memcpy usages in order to facilitate
change to utf-8 later.
libgrust/ChangeLog:
* libproc_macro/ffistring.cc (FFIString::make_ffistring):
Add explicit sizeof and utf-8 warning.
(FFIString::clone): Add explicit sizeof and utf-8 warning.
* libproc_macro/ident.cc (Ident::clone): Likewise.
(Ident::make_ident): Likewise.
* libproc_macro/tokenstream.cc (TokenStream::grow):
Fix vector growth.
(TokenStream__clone): Add explicit sizeof.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diff:
---
libgrust/libproc_macro/ffistring.cc | 6 ++++--
libgrust/libproc_macro/ident.cc | 10 ++++++----
libgrust/libproc_macro/tokenstream.cc | 4 ++--
3 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/libgrust/libproc_macro/ffistring.cc b/libgrust/libproc_macro/ffistring.cc
index 06e4e81dc24..2de674cfcfb 100644
--- a/libgrust/libproc_macro/ffistring.cc
+++ b/libgrust/libproc_macro/ffistring.cc
@@ -42,7 +42,8 @@ FFIString
FFIString::make_ffistring (const unsigned char *data, std::uint64_t len)
{
unsigned char *inner = new unsigned char[len];
- std::memcpy (inner, data, len);
+ // FIXME: UTF-8 Update this with sizeof codepoint instead
+ std::memcpy (inner, data, len * sizeof (unsigned char));
return {inner, len};
}
@@ -50,7 +51,8 @@ FFIString
FFIString::clone () const
{
unsigned char *inner = new unsigned char[this->len];
- std::memcpy (inner, this->data, this->len);
+ // FIXME: UTF-8 Update this with sizeof codepoint instead
+ std::memcpy (inner, this->data, this->len * sizeof (unsigned char));
return {inner, this->len};
}
diff --git a/libgrust/libproc_macro/ident.cc b/libgrust/libproc_macro/ident.cc
index 236970519da..6c8472dad20 100644
--- a/libgrust/libproc_macro/ident.cc
+++ b/libgrust/libproc_macro/ident.cc
@@ -56,8 +56,9 @@ Ident
Ident::clone () const
{
unsigned char *val = new unsigned char[this->len];
- std::memcpy (val, this->val, this->len);
- return {this->is_raw, val, this->len, this->span};
+ // FIXME: UTF-8 Update this with sizeof codepoint instead
+ std::memcpy (val, this->val, this->len * sizeof (char));
+ return {this->is_raw, val, this->len};
}
Ident
@@ -73,8 +74,9 @@ Ident::make_ident (const unsigned char *str, std::uint64_t len, Span span,
bool raw)
{
unsigned char *val = new unsigned char[len];
- std::memcpy (val, str, len);
- return {raw, val, len, span};
+ // FIXME: UTF-8 Update this with sizeof codepoint instead
+ std::memcpy (val, str, len * sizeof (char));
+ return {raw, val, len};
}
void
diff --git a/libgrust/libproc_macro/tokenstream.cc b/libgrust/libproc_macro/tokenstream.cc
index 25e42dc3dc9..d1116fff7ee 100644
--- a/libgrust/libproc_macro/tokenstream.cc
+++ b/libgrust/libproc_macro/tokenstream.cc
@@ -51,7 +51,7 @@ TokenStream::grow (std::uint64_t delta)
auto new_capacity = capacity + (delta != 0 ? delta : 1);
auto *new_data = new TokenTree[new_capacity];
capacity = new_capacity;
- std::memcpy (new_data, data, size);
+ std::memcpy (new_data, data, size * sizeof (TokenTree));
delete[] data;
data = new_data;
}
@@ -107,7 +107,7 @@ extern "C" TokenStream
TokenStream__clone (const TokenStream *ts)
{
auto *data = new TokenTree[ts->capacity];
- std::memcpy (data, ts->data, ts->size);
+ std::memcpy (data, ts->data, ts->size * sizeof (TokenTree));
return {data, ts->size, ts->capacity};
}
More information about the Gcc-cvs
mailing list