mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-17 13:40:27 +00:00
Sadly, the Clang driver unconditionally injects the `-disable-free` flag to CC1 invocations. =/ This ends up with us leaking memory when invoking Clang programmatically, for example in unit tests. I've fixed this by post-processing the flags. The alternatives I see all involve duplicating even more code from within Clang's internals into our runner, and we already have a lot of that. I have left a TODO to try and follow up with upstream about fixing this in a more sustainable way, but wanted to get the testing in place anyways. I've also threaded a flag through the various layers so that when we're on the command line we can actually skip this and get the same compile time benefits that Clang itself gets from disabling freeing all of the internal data structures. --------- Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
71 lines
2.4 KiB
C++
71 lines
2.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
|
|
|
|
#ifndef CARBON_TOOLCHAIN_DRIVER_DRIVER_ENV_H_
|
|
#define CARBON_TOOLCHAIN_DRIVER_DRIVER_ENV_H_
|
|
|
|
#include <cstdio>
|
|
#include <utility>
|
|
|
|
#include "common/ostream.h"
|
|
#include "llvm/Support/VirtualFileSystem.h"
|
|
#include "toolchain/diagnostics/diagnostic_emitter.h"
|
|
#include "toolchain/install/install_paths.h"
|
|
|
|
namespace Carbon {
|
|
|
|
// Driver environment information, encapsulated for easy passing to subcommands.
|
|
struct DriverEnv {
|
|
explicit DriverEnv(llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs,
|
|
const InstallPaths* installation, FILE* input_stream,
|
|
llvm::raw_pwrite_stream* output_stream,
|
|
llvm::raw_pwrite_stream* error_stream, bool fuzzing,
|
|
bool enable_leaking)
|
|
: fs(std::move(fs)),
|
|
installation(installation),
|
|
input_stream(input_stream),
|
|
output_stream(output_stream),
|
|
error_stream(error_stream),
|
|
fuzzing(fuzzing),
|
|
enable_leaking(enable_leaking),
|
|
consumer(error_stream),
|
|
emitter(&consumer) {}
|
|
|
|
// The filesystem for source code.
|
|
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs;
|
|
|
|
// Helper to locate the toolchain installation's files.
|
|
const InstallPaths* installation;
|
|
|
|
// Standard input; stdin. May be null, to prevent accidental use.
|
|
FILE* input_stream;
|
|
// Standard output; stdout.
|
|
llvm::raw_pwrite_stream* output_stream;
|
|
// Error output; stderr.
|
|
llvm::raw_pwrite_stream* error_stream;
|
|
|
|
// Tracks when the driver is being fuzzed. This allows specific commands to
|
|
// error rather than perform operations that aren't well behaved during
|
|
// fuzzing.
|
|
bool fuzzing;
|
|
|
|
// Tracks whether the driver can leak resources, typically because it is being
|
|
// invoked as part of a single command line program execution. Defaults to
|
|
// `false` for safe and correct library execution.
|
|
bool enable_leaking = false;
|
|
|
|
// A diagnostic consumer, to be able to connect output.
|
|
StreamDiagnosticConsumer consumer;
|
|
|
|
// A diagnostic emitter that has no locations.
|
|
NoLocDiagnosticEmitter emitter;
|
|
|
|
// For CARBON_VLOG.
|
|
llvm::raw_pwrite_stream* vlog_stream = nullptr;
|
|
};
|
|
|
|
} // namespace Carbon
|
|
|
|
#endif // CARBON_TOOLCHAIN_DRIVER_DRIVER_ENV_H_
|