[PATCH] D98554: Save strings for CC_PRINT env vars
Sean via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 12 13:52:41 PST 2021
SeanP created this revision.
SeanP added reviewers: hubert.reinterpretcast, uweigand, Kai.
SeanP requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
The contents of the string returned by getenv() is not guaranteed across calls to getenv(). The code to handle the CC_PRINT etc env vars calls getenv() and saves the results in just a char *. The string returned by getenv() needs to be copied and saved. Switching the type of the strings from char * to std::string will do this and manage the alloated memory.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D98554
Files:
clang/include/clang/Driver/Driver.h
clang/lib/Driver/Compilation.cpp
clang/lib/Driver/Driver.cpp
clang/lib/Driver/ToolChains/Clang.cpp
Index: clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -5107,7 +5107,7 @@
if (D.CCPrintHeaders && !D.CCGenDiagnostics) {
CmdArgs.push_back("-header-include-file");
- CmdArgs.push_back(D.CCPrintHeadersFilename ? D.CCPrintHeadersFilename
+ CmdArgs.push_back(!D.CCPrintHeadersFilename.empty() ? D.CCPrintHeadersFilename.c_str()
: "-");
CmdArgs.push_back("-sys-header-deps");
}
@@ -5116,7 +5116,7 @@
if (D.CCLogDiagnostics && !D.CCGenDiagnostics) {
CmdArgs.push_back("-diagnostic-log-file");
- CmdArgs.push_back(D.CCLogDiagnosticsFilename ? D.CCLogDiagnosticsFilename
+ CmdArgs.push_back(!D.CCLogDiagnosticsFilename.empty() ? D.CCLogDiagnosticsFilename.c_str()
: "-");
}
Index: clang/lib/Driver/Driver.cpp
===================================================================
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -135,9 +135,9 @@
: Diags(Diags), VFS(std::move(VFS)), Mode(GCCMode),
SaveTemps(SaveTempsNone), BitcodeEmbed(EmbedNone), LTOMode(LTOK_None),
ClangExecutable(ClangExecutable), SysRoot(DEFAULT_SYSROOT),
- DriverTitle(Title), CCPrintStatReportFilename(nullptr),
- CCPrintOptionsFilename(nullptr), CCPrintHeadersFilename(nullptr),
- CCLogDiagnosticsFilename(nullptr), CCCPrintBindings(false),
+ DriverTitle(Title), CCPrintStatReportFilename(),
+ CCPrintOptionsFilename(), CCPrintHeadersFilename(),
+ CCLogDiagnosticsFilename(), CCCPrintBindings(false),
CCPrintOptions(false), CCPrintHeaders(false), CCLogDiagnostics(false),
CCGenDiagnostics(false), CCPrintProcessStats(false),
TargetTriple(TargetTriple), CCCGenericGCCName(""), Saver(Alloc),
@@ -4040,7 +4040,7 @@
else
LinkingOutput = getDefaultImageName();
- if (!CCPrintStatReportFilename) {
+ if (CCPrintStatReportFilename.empty()) {
using namespace llvm;
// Human readable output.
outs() << sys::path::filename(Cmd.getExecutable()) << ": "
@@ -4063,7 +4063,7 @@
<< '\n';
Out.flush();
std::error_code EC;
- llvm::raw_fd_ostream OS(CCPrintStatReportFilename, EC,
+ llvm::raw_fd_ostream OS(CCPrintStatReportFilename.c_str(), EC,
llvm::sys::fs::OF_Append);
if (EC)
return;
Index: clang/lib/Driver/Compilation.cpp
===================================================================
--- clang/lib/Driver/Compilation.cpp
+++ clang/lib/Driver/Compilation.cpp
@@ -170,10 +170,10 @@
// Follow gcc implementation of CC_PRINT_OPTIONS; we could also cache the
// output stream.
- if (getDriver().CCPrintOptions && getDriver().CCPrintOptionsFilename) {
+ if (getDriver().CCPrintOptions && !getDriver().CCPrintOptionsFilename.empty()) {
std::error_code EC;
OwnedStream.reset(new llvm::raw_fd_ostream(
- getDriver().CCPrintOptionsFilename, EC,
+ getDriver().CCPrintOptionsFilename.c_str(), EC,
llvm::sys::fs::OF_Append | llvm::sys::fs::OF_Text));
if (EC) {
getDriver().Diag(diag::err_drv_cc_print_options_failure)
Index: clang/include/clang/Driver/Driver.h
===================================================================
--- clang/include/clang/Driver/Driver.h
+++ clang/include/clang/Driver/Driver.h
@@ -157,16 +157,16 @@
std::string HostBits, HostMachine, HostSystem, HostRelease;
/// The file to log CC_PRINT_PROC_STAT_FILE output to, if enabled.
- const char *CCPrintStatReportFilename;
+ std::string CCPrintStatReportFilename;
/// The file to log CC_PRINT_OPTIONS output to, if enabled.
- const char *CCPrintOptionsFilename;
+ std::string CCPrintOptionsFilename;
/// The file to log CC_PRINT_HEADERS output to, if enabled.
- const char *CCPrintHeadersFilename;
+ std::string CCPrintHeadersFilename;
/// The file to log CC_LOG_DIAGNOSTICS output to, if enabled.
- const char *CCLogDiagnosticsFilename;
+ std::string CCLogDiagnosticsFilename;
/// A list of inputs and their types for the given arguments.
typedef SmallVector<std::pair<types::ID, const llvm::opt::Arg *>, 16>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98554.330362.patch
Type: text/x-patch
Size: 4379 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210312/dedfe69a/attachment.bin>
More information about the cfe-commits
mailing list