Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable debug info by default #4232

Merged
merged 7 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions testing/file_test/file_test_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ auto FileTestBase::ProcessTestFileAndRun(TestContext& context)
auto FileTestBase::DoArgReplacements(
llvm::SmallVector<std::string>& test_args,
const llvm::SmallVector<TestFile>& test_files) -> ErrorOr<Success> {
auto replacements = GetReplacements();
for (auto* it = test_args.begin(); it != test_args.end(); ++it) {
auto percent = it->find("%");
if (percent == std::string::npos) {
Expand Down Expand Up @@ -362,6 +363,21 @@ auto FileTestBase::DoArgReplacements(
it->replace(percent, 2, llvm::formatv("{0}/temp_file", tmpdir));
break;
}
case '{': {
auto end_brace = it->find('}', percent);
if (end_brace == std::string::npos) {
return ErrorBuilder() << "%{ without closing }: " << *it;
}
llvm::StringRef substr(&*(it->begin() + percent + 2),
end_brace - percent - 2);
auto replacement = replacements.find(substr);
if (replacement == replacements.end()) {
return ErrorBuilder()
<< "unknown substitution: %{" << substr << "}: " << *it;
}
it->replace(percent, end_brace - percent + 1, replacement->second);
break;
}
default:
return ErrorBuilder() << "%" << c << " is not supported: " << *it;
}
Expand Down
3 changes: 3 additions & 0 deletions testing/file_test/file_test_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "common/ostream.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/VirtualFileSystem.h"
#include "testing/file_test/autoupdate.h"
Expand Down Expand Up @@ -86,6 +87,8 @@ class FileTestBase : public testing::Test {
// Returns default arguments. Only called when a file doesn't set ARGS.
virtual auto GetDefaultArgs() -> llvm::SmallVector<std::string> = 0;

virtual auto GetReplacements() -> llvm::StringMap<std::string> { return {}; }
jonmeow marked this conversation as resolved.
Show resolved Hide resolved

// Returns a regex to match the default file when a line may not be present.
// May return nullptr if unused. If GetLineNumberReplacements returns an entry
// with has_file=false, this is required.
Expand Down
13 changes: 5 additions & 8 deletions toolchain/driver/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,10 @@ Excludes files with the given prefix from dumps.
Emit DWARF debug information.
)""",
},
[&](auto& arg_b) { arg_b.Set(&include_debug_info); });
[&](auto& arg_b) {
arg_b.Default(true);
arg_b.Set(&include_debug_info);
});
}

Phase phase;
Expand All @@ -366,7 +369,7 @@ Emit DWARF debug information.
bool preorder_parse_tree = false;
bool builtin_sem_ir = false;
bool prelude_import = false;
bool include_debug_info = false;
bool include_debug_info = true;

llvm::StringRef exclude_dump_file_prefix;
};
Expand Down Expand Up @@ -532,12 +535,6 @@ auto Driver::ValidateCompileOptions(const CompileOptions& options) const
<< options.phase << "'.\n";
return false;
}
if (options.include_debug_info) {
error_stream_
<< "ERROR: Requested debug info but compile phase is limited to '"
<< options.phase << "'.\n";
return false;
}
[[fallthrough]];
case Phase::Lower:
case Phase::CodeGen:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// ARGS: compile --debug-info --phase=check %s
// ARGS: compile --no-debug-info --phase=lower --dump-llvm-ir --output=- --exclude-dump-file-prefix=%{core_package_dir} %s
//
// AUTOUPDATE
// TIP: To test this file alone, run:
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/driver/testdata/fail_flags.carbon
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/lower/testdata/debug/nodebug.carbon
// TIP: To dump output, run:
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/driver/testdata/fail_flags.carbon
// CHECK:STDERR: ERROR: Requested debug info but compile phase is limited to 'check'.
//
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/debug/nodebug.carbon

// CHECK:STDOUT: ; ModuleID = 'nodebug.carbon'
// CHECK:STDOUT: source_filename = "nodebug.carbon"
5 changes: 4 additions & 1 deletion toolchain/testing/file_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ class ToolchainFileTest : public FileTestBase {
component_(GetComponent(test_name)),
installation_(InstallPaths::MakeForBazelRunfiles(exe_path)) {}

auto GetReplacements() -> llvm::StringMap<std::string> override {
return {{"core_package_dir", installation_.core_package()}};
}

auto Run(const llvm::SmallVector<llvm::StringRef>& test_args,
llvm::vfs::InMemoryFileSystem& fs, llvm::raw_pwrite_stream& stdout,
llvm::raw_pwrite_stream& stderr) -> ErrorOr<RunResult> override {
Expand Down Expand Up @@ -70,7 +74,6 @@ class ToolchainFileTest : public FileTestBase {
args.push_back("--dump-sem-ir");
} else if (component_ == "lower") {
args.push_back("--dump-llvm-ir");
args.push_back("--debug-info");
} else {
CARBON_FATAL() << "Unexpected test component " << component_ << ": "
<< test_name();
Expand Down
Loading