Files
carbon-lang/common/init_llvm.cpp
T
Jon Ross-Perkins 16942e4d07 Move errs tie to LLVM to include test infrastructure. (#4006)
The lack of flushing can sometimes be observed when streaming test
output, particularly with --dump_output. My thought is moving it into
our LLVM init is probably reasonable, given the driver's already doing
this for similar reasons; this means it's used in tests through our
gtest_main.cpp in addition to the driver.
2024-05-30 21:08:44 +00:00

45 lines
1.4 KiB
C++

// 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 "common/init_llvm.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Support/raw_ostream.h"
namespace Carbon {
InitLLVM::InitLLVM(int& argc, char**& argv)
: init_llvm_(argc, argv),
// LLVM assumes that argc and argv won't change, and registers them with
// an `llvm::PrettyStackTraceProgram` that will crash if an argv element
// gets nulled out, which for example `testing::InitGoogleTest` does. So
// make a copy of the argv that LLVM produces in order to support
// mutation.
args_(argv, argv + argc) {
// Return our mutable copy of argv for the program to use.
argc = args_.size();
argv = args_.data();
// `argv[argc]` is expected to be a null pointer.
args_.push_back(nullptr);
llvm::setBugReportMsg(
"Please report issues to "
"https://github.com/carbon-language/carbon-lang/issues and include the "
"crash backtrace.\n");
// Initialize LLVM targets if //common:all_llvm_targets was linked in.
if (InitializeTargets) {
InitializeTargets();
}
// Printing to stderr should flush stdout. This is most noticeable when stderr
// is piped to stdout.
llvm::errs().tie(&llvm::outs());
}
InitLLVM::InitializeTargetsFn* InitLLVM::InitializeTargets = nullptr;
} // namespace Carbon