mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 22:02:52 +01:00
Start handling stack depth issues in explorer (#2799)
Adds stack space handling similar to Clang's approach, but with more support for forwarding return values. Refactors ParseAndExecute for better sharing, and for centralization of the InitStackSpace handling. Fixes #2795
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
||||
// Exceptions. See /LICENSE for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
#include "explorer/parse_and_execute/parse_and_execute.h"
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace Carbon::Testing {
|
||||
namespace {
|
||||
|
||||
using ::testing::Eq;
|
||||
|
||||
TEST(ParseAndExecuteTest, Recursion) {
|
||||
std::string source = R"(
|
||||
package Test api;
|
||||
fn Main() -> i32 {
|
||||
return
|
||||
)";
|
||||
// A high depth that's expected to complete in a few seconds.
|
||||
static constexpr int Depth = 50000;
|
||||
for (int i = 0; i < Depth; ++i) {
|
||||
source += "if true then\n";
|
||||
}
|
||||
source += "1\n";
|
||||
for (int i = 0; i < Depth; ++i) {
|
||||
source += "else 0\n";
|
||||
}
|
||||
source += R"(
|
||||
;
|
||||
}
|
||||
)";
|
||||
auto err = ParseAndExecute("explorer/data/prelude.carbon", source);
|
||||
ASSERT_FALSE(err.ok());
|
||||
EXPECT_THAT(err.error().message(),
|
||||
Eq("RUNTIME ERROR: overflow:1: stack overflow: too many "
|
||||
"interpreter actions on stack"));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace Carbon::Testing
|
||||
Reference in New Issue
Block a user