Reviewers: Benedikt Meurer,
Message:
According to the C++ style guide all usages of alloca() are disallowed.
Some of
our existing usages even weren't bounded enough and hence might have already
lead to undefined behavior due to stack overflow.
http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Variable-Length_Arrays_and_alloca__
Description:
Remove usages of alloca() according to style guide.
[email protected]
Please review this at https://codereview.chromium.org/535133002/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files (+7, -12 lines):
M src/compiler/ast-graph-builder.cc
M src/compiler/graph-builder.cc
M src/compiler/machine-node-factory.h
M src/compiler/structured-machine-assembler.cc
Index: src/compiler/ast-graph-builder.cc
diff --git a/src/compiler/ast-graph-builder.cc
b/src/compiler/ast-graph-builder.cc
index
afc58e91454b95a560c96ebdca3c57ca838b8bef..5ad8269ca9a19c1f6eec61fc86d2621870a509ab
100644
--- a/src/compiler/ast-graph-builder.cc
+++ b/src/compiler/ast-graph-builder.cc
@@ -1652,7 +1652,7 @@ void
AstGraphBuilder::VisitLogicalExpression(BinaryOperation* expr) {
Node* AstGraphBuilder::ProcessArguments(Operator* op, int arity) {
DCHECK(environment()->stack_height() >= arity);
- Node** all = info()->zone()->NewArray<Node*>(arity); // XXX: alloca?
+ Node** all = info()->zone()->NewArray<Node*>(arity);
for (int i = arity - 1; i >= 0; --i) {
all[i] = environment()->Pop();
}
Index: src/compiler/graph-builder.cc
diff --git a/src/compiler/graph-builder.cc b/src/compiler/graph-builder.cc
index
504d25ec2f00fe42801b0a4a12d71fe993ba3f58..c41fd6fac58d615d895694712d12f3dc413f9087
100644
--- a/src/compiler/graph-builder.cc
+++ b/src/compiler/graph-builder.cc
@@ -49,8 +49,7 @@ Node* StructuredGraphBuilder::MakeNode(Operator* op, int
value_input_count,
if (has_framestate) ++input_count_with_deps;
if (has_control) ++input_count_with_deps;
if (has_effect) ++input_count_with_deps;
- void* raw_buffer = alloca(kPointerSize * input_count_with_deps);
- Node** buffer = reinterpret_cast<Node**>(raw_buffer);
+ Node** buffer = zone()->NewArray<Node*>(input_count_with_deps);
memcpy(buffer, value_inputs, kPointerSize * value_input_count);
Node** current_input = buffer + value_input_count;
if (has_context) {
@@ -163,8 +162,7 @@ void
StructuredGraphBuilder::Environment::PrepareForLoop() {
Node* StructuredGraphBuilder::NewPhi(int count, Node* input, Node*
control) {
Operator* phi_op = common()->Phi(count);
- void* raw_buffer = alloca(kPointerSize * (count + 1));
- Node** buffer = reinterpret_cast<Node**>(raw_buffer);
+ Node** buffer = zone()->NewArray<Node*>(count + 1);
MemsetPointer(buffer, input, count);
buffer[count] = control;
return graph()->NewNode(phi_op, count + 1, buffer);
@@ -175,8 +173,7 @@ Node* StructuredGraphBuilder::NewPhi(int count, Node*
input, Node* control) {
Node* StructuredGraphBuilder::NewEffectPhi(int count, Node* input,
Node* control) {
Operator* phi_op = common()->EffectPhi(count);
- void* raw_buffer = alloca(kPointerSize * (count + 1));
- Node** buffer = reinterpret_cast<Node**>(raw_buffer);
+ Node** buffer = zone()->NewArray<Node*>(count + 1);
MemsetPointer(buffer, input, count);
buffer[count] = control;
return graph()->NewNode(phi_op, count + 1, buffer);
Index: src/compiler/machine-node-factory.h
diff --git a/src/compiler/machine-node-factory.h
b/src/compiler/machine-node-factory.h
index
7b2e5ff82b07dd9f93e4b841290ba4b3dd35f8a2..a2605d9fd21a7fd0db0028cfb22ae959d002a7ec
100644
--- a/src/compiler/machine-node-factory.h
+++ b/src/compiler/machine-node-factory.h
@@ -349,8 +349,7 @@ class MachineNodeFactory {
MachineType* arg_types, Node** args, int n_args) {
CallDescriptor* descriptor =
Linkage::GetSimplifiedCDescriptor(ZONE(), MACHINE_SIG());
- Node** passed_args =
- static_cast<Node**>(alloca((n_args + 1) * sizeof(args[0])));
+ Node** passed_args = ZONE()->NewArray<Node*>(n_args + 1);
passed_args[0] = function_address;
for (int i = 0; i < n_args; ++i) {
passed_args[i + 1] = args[i];
Index: src/compiler/structured-machine-assembler.cc
diff --git a/src/compiler/structured-machine-assembler.cc
b/src/compiler/structured-machine-assembler.cc
index
6475809e0e8e2c0f52b77cf27000f593b870a712..432b84c64a9e8e89ed0a39e870efffbba97c0919
100644
--- a/src/compiler/structured-machine-assembler.cc
+++ b/src/compiler/structured-machine-assembler.cc
@@ -213,8 +213,7 @@ void
StructuredMachineAssembler::Merge(EnvironmentVector* environments,
vars.reserve(n_vars);
Node** scratch = NULL;
size_t n_envs = environments->size();
- Environment** live_environments = reinterpret_cast<Environment**>(
- alloca(sizeof(environments->at(0)) * n_envs));
+ Environment** live_environments = zone()->NewArray<Environment*>(n_envs);
size_t n_live = 0;
for (size_t i = 0; i < n_envs; i++) {
if (environments->at(i)->is_dead_) continue;
@@ -250,7 +249,7 @@ void
StructuredMachineAssembler::Merge(EnvironmentVector* environments,
CHECK(resolved != NULL);
// Init scratch buffer.
if (scratch == NULL) {
- scratch = static_cast<Node**>(alloca(n_envs * sizeof(resolved)));
+ scratch = zone()->NewArray<Node*>(n_envs);
}
for (size_t k = 0; k < i; k++) {
scratch[k] = resolved;
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.