Skip to content

Commit f8ed225

Browse files
zmodemdexonsmith
authored andcommitted
Re-land "Add an -fno-temp-file flag for compilation"
This time making sure to initialize FrontendOptions::UseTemporary. Patch by Zachary Henkel! Differential revision: https://reviews.llvm.org/D70615 (cherry picked from commit dde7b6b) Conflicts: clang/include/clang/Frontend/FrontendOptions.h clang/lib/Frontend/FrontendActions.cpp
1 parent 9e168c3 commit f8ed225

File tree

7 files changed

+15
-4
lines changed

7 files changed

+15
-4
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,6 +1530,9 @@ def fno_strict_enums : Flag<["-"], "fno-strict-enums">, Group<f_Group>;
15301530
def fno_strict_vtable_pointers: Flag<["-"], "fno-strict-vtable-pointers">,
15311531
Group<f_Group>;
15321532
def fno_strict_overflow : Flag<["-"], "fno-strict-overflow">, Group<f_Group>;
1533+
def fno_temp_file : Flag<["-"], "fno-temp-file">, Group<f_Group>,
1534+
Flags<[CC1Option, CoreOption]>, HelpText<
1535+
"Directly create compilation output files. This may lead to incorrect incremental builds if the compiler crashes">;
15331536
def fno_threadsafe_statics : Flag<["-"], "fno-threadsafe-statics">, Group<f_Group>,
15341537
Flags<[CC1Option]>, HelpText<"Do not emit code to make initialization of local statics thread safe">;
15351538
def fno_use_cxa_atexit : Flag<["-"], "fno-use-cxa-atexit">, Group<f_Group>, Flags<[CC1Option]>,

clang/include/clang/Frontend/FrontendOptions.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,9 @@ class FrontendOptions {
291291
/// Whether timestamps should be written to the produced PCH file.
292292
unsigned IncludeTimestamps : 1;
293293

294+
/// Should a temporary file be used during compilation.
295+
unsigned UseTemporary : 1;
296+
294297
CodeCompleteOptions CodeCompleteOpts;
295298

296299
/// Specifies the output format of the AST.
@@ -440,8 +443,8 @@ class FrontendOptions {
440443
UseGlobalModuleIndex(true), GenerateGlobalModuleIndex(true),
441444
ASTDumpDecls(false), ASTDumpLookups(false),
442445
BuildingImplicitModule(false), ModulesEmbedAllFiles(false),
443-
IncludeTimestamps(true), IndexIgnoreSystemSymbols(false),
444-
IndexRecordCodegenName(false) {}
446+
IncludeTimestamps(true), UseTemporary(true),
447+
IndexIgnoreSystemSymbols(false), IndexRecordCodegenName(false) {}
445448

446449
/// getInputKindForExtension - Return the appropriate input kind for a file
447450
/// extension. For example, "c" would return Language::C.

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4785,6 +4785,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
47854785
Args.AddLastArg(CmdArgs, options::OPT_ftime_trace);
47864786
Args.AddLastArg(CmdArgs, options::OPT_ftrapv);
47874787
Args.AddLastArg(CmdArgs, options::OPT_malign_double);
4788+
Args.AddLastArg(CmdArgs, options::OPT_fno_temp_file);
47884789

47894790
if (Arg *A = Args.getLastArg(options::OPT_ftrapv_handler_EQ)) {
47904791
CmdArgs.push_back("-ftrapv-handler");

clang/lib/Frontend/CompilerInstance.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ CompilerInstance::createDefaultOutputFile(bool Binary, StringRef InFile,
687687
StringRef Extension) {
688688
return createOutputFile(getFrontendOpts().OutputFile, Binary,
689689
/*RemoveFileOnSignal=*/true, InFile, Extension,
690-
/*UseTemporary=*/true);
690+
getFrontendOpts().UseTemporary);
691691
}
692692

693693
std::unique_ptr<raw_pwrite_stream> CompilerInstance::createNullOutputFile() {

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,6 +1868,7 @@ static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
18681868
Opts.ModulesEmbedFiles = Args.getAllArgValues(OPT_fmodules_embed_file_EQ);
18691869
Opts.ModulesEmbedAllFiles = Args.hasArg(OPT_fmodules_embed_all_files);
18701870
Opts.IncludeTimestamps = !Args.hasArg(OPT_fno_pch_timestamp);
1871+
Opts.UseTemporary = !Args.hasArg(OPT_fno_temp_file);
18711872

18721873
Opts.CodeCompleteOpts.IncludeMacros
18731874
= Args.hasArg(OPT_code_completion_macros);

clang/lib/Frontend/FrontendActions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ GeneratePCHAction::CreateOutputFile(CompilerInstance &CI, StringRef InFile,
140140
std::unique_ptr<raw_pwrite_stream> OS =
141141
CI.createOutputFile(CI.getFrontendOpts().OutputFile, /*Binary=*/true,
142142
/*RemoveFileOnSignal=*/false, InFile,
143-
/*Extension=*/"", /*useTemporary=*/true);
143+
/*Extension=*/"", CI.getFrontendOpts().UseTemporary);
144144
if (!OS)
145145
return nullptr;
146146

clang/test/Driver/clang_f_opts.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,3 +571,6 @@
571571
// CHECK-TRIVIAL-PATTERN-NOT: hasn't been enabled
572572
// CHECK-TRIVIAL-ZERO-GOOD-NOT: hasn't been enabled
573573
// CHECK-TRIVIAL-ZERO-BAD: hasn't been enabled
574+
575+
// RUN: %clang -### -S -fno-temp-file %s 2>&1 | FileCheck -check-prefix=CHECK-NO-TEMP-FILE %s
576+
// CHECK-NO-TEMP-FILE: "-fno-temp-file"

0 commit comments

Comments
 (0)