aboutsummaryrefslogtreecommitdiff
path: root/libcc1
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2021-05-04 15:26:58 -0600
committerTom Tromey <tom@tromey.com>2021-05-05 00:06:16 -0600
commite702c60e65cf9c13587d571cdd158bca74f4c2e2 (patch)
tree31d006d9df56bda3152d914660c879297844adab /libcc1
parent410d5719b78519d8c53855a4c789cc0d656b480a (diff)
downloadgcc-e702c60e65cf9c13587d571cdd158bca74f4c2e2.zip
gcc-e702c60e65cf9c13587d571cdd158bca74f4c2e2.tar.gz
gcc-e702c60e65cf9c13587d571cdd158bca74f4c2e2.tar.bz2
libcc1: use std::vector when building function types
This changes libcc1 to use std::vector in the code that builds function types. This avoids some explicit memory management. libcc1 * libcp1plugin.cc (plugin_build_function_type): Use std::vector. * libcc1plugin.cc (plugin_build_function_type): Use std::vector.
Diffstat (limited to 'libcc1')
-rw-r--r--libcc1/libcc1plugin.cc11
-rw-r--r--libcc1/libcp1plugin.cc11
2 files changed, 10 insertions, 12 deletions
diff --git a/libcc1/libcc1plugin.cc b/libcc1/libcc1plugin.cc
index 59e4851..65e7482 100644
--- a/libcc1/libcc1plugin.cc
+++ b/libcc1/libcc1plugin.cc
@@ -67,6 +67,8 @@
#include "rpc.hh"
#include "gcc-c-interface.h"
+#include <vector>
+
#ifdef __GNUC__
#pragma GCC visibility push(default)
#endif
@@ -672,24 +674,21 @@ plugin_build_function_type (cc1_plugin::connection *self,
const struct gcc_type_array *argument_types_in,
int is_varargs)
{
- tree *argument_types;
tree return_type = convert_in (return_type_in);
tree result;
- argument_types = new tree[argument_types_in->n_elements];
+ std::vector<tree> argument_types (argument_types_in->n_elements);
for (int i = 0; i < argument_types_in->n_elements; ++i)
argument_types[i] = convert_in (argument_types_in->elements[i]);
if (is_varargs)
result = build_varargs_function_type_array (return_type,
argument_types_in->n_elements,
- argument_types);
+ argument_types.data ());
else
result = build_function_type_array (return_type,
argument_types_in->n_elements,
- argument_types);
-
- delete[] argument_types;
+ argument_types.data ());
plugin_context *ctx = static_cast<plugin_context *> (self);
return convert_out (ctx->preserve (result));
diff --git a/libcc1/libcp1plugin.cc b/libcc1/libcp1plugin.cc
index 27a6175..1fc8e26 100644
--- a/libcc1/libcp1plugin.cc
+++ b/libcc1/libcp1plugin.cc
@@ -70,6 +70,8 @@
#include "marshall-cp.hh"
#include "rpc.hh"
+#include <vector>
+
#ifdef __GNUC__
#pragma GCC visibility push(default)
#endif
@@ -1980,24 +1982,21 @@ plugin_build_function_type (cc1_plugin::connection *self,
const struct gcc_type_array *argument_types_in,
int is_varargs)
{
- tree *argument_types;
tree return_type = convert_in (return_type_in);
tree result;
- argument_types = new tree[argument_types_in->n_elements];
+ std::vector<tree> argument_types (argument_types_in->n_elements);
for (int i = 0; i < argument_types_in->n_elements; ++i)
argument_types[i] = convert_in (argument_types_in->elements[i]);
if (is_varargs)
result = build_varargs_function_type_array (return_type,
argument_types_in->n_elements,
- argument_types);
+ argument_types.data ());
else
result = build_function_type_array (return_type,
argument_types_in->n_elements,
- argument_types);
-
- delete[] argument_types;
+ argument_types.data ());
plugin_context *ctx = static_cast<plugin_context *> (self);
return convert_out (ctx->preserve (result));