Skip to content

Commit dde7b6b

Browse files
committed
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
1 parent d005df4 commit dde7b6b

File tree

7 files changed

+14
-3
lines changed

7 files changed

+14
-3
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,6 +1563,9 @@ def fno_strict_enums : Flag<["-"], "fno-strict-enums">, Group<f_Group>;
15631563
def fno_strict_vtable_pointers: Flag<["-"], "fno-strict-vtable-pointers">,
15641564
Group<f_Group>;
15651565
def fno_strict_overflow : Flag<["-"], "fno-strict-overflow">, Group<f_Group>;
1566+
def fno_temp_file : Flag<["-"], "fno-temp-file">, Group<f_Group>,
1567+
Flags<[CC1Option, CoreOption]>, HelpText<
1568+
"Directly create compilation output files. This may lead to incorrect incremental builds if the compiler crashes">;
15661569
def fno_threadsafe_statics : Flag<["-"], "fno-threadsafe-statics">, Group<f_Group>,
15671570
Flags<[CC1Option]>, HelpText<"Do not emit code to make initialization of local statics thread safe">;
15681571
def fno_use_cxa_atexit : Flag<["-"], "fno-use-cxa-atexit">, Group<f_Group>, Flags<[CC1Option]>,

clang/include/clang/Frontend/FrontendOptions.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,9 @@ class FrontendOptions {
294294
/// Whether timestamps should be written to the produced PCH file.
295295
unsigned IncludeTimestamps : 1;
296296

297+
/// Should a temporary file be used during compilation.
298+
unsigned UseTemporary : 1;
299+
297300
CodeCompleteOptions CodeCompleteOpts;
298301

299302
/// Specifies the output format of the AST.
@@ -442,7 +445,7 @@ class FrontendOptions {
442445
UseGlobalModuleIndex(true), GenerateGlobalModuleIndex(true),
443446
ASTDumpDecls(false), ASTDumpLookups(false),
444447
BuildingImplicitModule(false), ModulesEmbedAllFiles(false),
445-
IncludeTimestamps(true), TimeTraceGranularity(500) {}
448+
IncludeTimestamps(true), UseTemporary(true), TimeTraceGranularity(500) {}
446449

447450
/// getInputKindForExtension - Return the appropriate input kind for a file
448451
/// 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
@@ -5005,6 +5005,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
50055005
Args.AddLastArg(CmdArgs, options::OPT_ftime_trace_granularity_EQ);
50065006
Args.AddLastArg(CmdArgs, options::OPT_ftrapv);
50075007
Args.AddLastArg(CmdArgs, options::OPT_malign_double);
5008+
Args.AddLastArg(CmdArgs, options::OPT_fno_temp_file);
50085009

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

clang/lib/Frontend/CompilerInstance.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ CompilerInstance::createDefaultOutputFile(bool Binary, StringRef InFile,
672672
StringRef Extension) {
673673
return createOutputFile(getFrontendOpts().OutputFile, Binary,
674674
/*RemoveFileOnSignal=*/true, InFile, Extension,
675-
/*UseTemporary=*/true);
675+
getFrontendOpts().UseTemporary);
676676
}
677677

678678
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
@@ -1887,6 +1887,7 @@ static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
18871887
Opts.ModulesEmbedFiles = Args.getAllArgValues(OPT_fmodules_embed_file_EQ);
18881888
Opts.ModulesEmbedAllFiles = Args.hasArg(OPT_fmodules_embed_all_files);
18891889
Opts.IncludeTimestamps = !Args.hasArg(OPT_fno_pch_timestamp);
1890+
Opts.UseTemporary = !Args.hasArg(OPT_fno_temp_file);
18901891

18911892
Opts.CodeCompleteOpts.IncludeMacros
18921893
= 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
@@ -588,3 +588,6 @@
588588
// CHECK-TRIVIAL-PATTERN-NOT: hasn't been enabled
589589
// CHECK-TRIVIAL-ZERO-GOOD-NOT: hasn't been enabled
590590
// CHECK-TRIVIAL-ZERO-BAD: hasn't been enabled
591+
592+
// RUN: %clang -### -S -fno-temp-file %s 2>&1 | FileCheck -check-prefix=CHECK-NO-TEMP-FILE %s
593+
// CHECK-NO-TEMP-FILE: "-fno-temp-file"

0 commit comments

Comments
 (0)