Skip to content

Commit 533a893

Browse files
committedJul 13, 2016
[PCH] Add a fno-pch-timestamp option to cc1 to disable inclusion of timestamps in PCH files.
This is to allow distributed build systems, that do not preserve time stamps, to use PCH files. Second and last part of the patch proposed at: Differential Revision: http://reviews.llvm.org/D20867 llvm-svn: 275267
1 parent c1d8d4b commit 533a893

File tree

7 files changed

+42
-3
lines changed

7 files changed

+42
-3
lines changed
 

‎clang/include/clang/Driver/CC1Options.td

+2
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,8 @@ def find_pch_source_EQ : Joined<["-"], "find-pch-source=">,
509509
HelpText<"When building a pch, try to find the input file in include "
510510
"directories, as if it had been included by the argument passed "
511511
"to this flag.">;
512+
def fno_pch_timestamp : Flag<["-"], "fno-pch-timestamp">,
513+
HelpText<"Disable inclusion of timestamp in precompiled headers">;
512514

513515
//===----------------------------------------------------------------------===//
514516
// Language Options

‎clang/include/clang/Frontend/FrontendOptions.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ class FrontendOptions {
154154
///< implicit module build.
155155
unsigned ModulesEmbedAllFiles : 1; ///< Whether we should embed all used
156156
///< files into the PCM file.
157+
unsigned IncludeTimestamps : 1; ///< Whether timestamps should be
158+
///< written to the produced PCH file.
157159

158160
CodeCompleteOptions CodeCompleteOpts;
159161

@@ -278,8 +280,8 @@ class FrontendOptions {
278280
SkipFunctionBodies(false), UseGlobalModuleIndex(true),
279281
GenerateGlobalModuleIndex(true), ASTDumpDecls(false), ASTDumpLookups(false),
280282
BuildingImplicitModule(false), ModulesEmbedAllFiles(false),
281-
ARCMTAction(ARCMT_None), ObjCMTAction(ObjCMT_None),
282-
ProgramAction(frontend::ParseSyntaxOnly)
283+
IncludeTimestamps(true), ARCMTAction(ARCMT_None),
284+
ObjCMTAction(ObjCMT_None), ProgramAction(frontend::ParseSyntaxOnly)
283285
{}
284286

285287
/// getInputKindForExtension - Return the appropriate input kind for a file

‎clang/lib/Frontend/CompilerInvocation.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1197,6 +1197,7 @@ static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
11971197
Opts.ModuleFiles = Args.getAllArgValues(OPT_fmodule_file);
11981198
Opts.ModulesEmbedFiles = Args.getAllArgValues(OPT_fmodules_embed_file_EQ);
11991199
Opts.ModulesEmbedAllFiles = Args.hasArg(OPT_fmodules_embed_all_files);
1200+
Opts.IncludeTimestamps = !Args.hasArg(OPT_fno_pch_timestamp);
12001201

12011202
Opts.CodeCompleteOpts.IncludeMacros
12021203
= Args.hasArg(OPT_code_completion_macros);

‎clang/lib/Frontend/FrontendActions.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ GeneratePCHAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
9292
std::vector<std::unique_ptr<ASTConsumer>> Consumers;
9393
Consumers.push_back(llvm::make_unique<PCHGenerator>(
9494
CI.getPreprocessor(), OutputFile, nullptr, Sysroot,
95-
Buffer, CI.getFrontendOpts().ModuleFileExtensions));
95+
Buffer, CI.getFrontendOpts().ModuleFileExtensions,
96+
/*AllowASTWithErrors*/false,
97+
/*IncludeTimestamps*/
98+
+CI.getFrontendOpts().IncludeTimestamps));
9699
Consumers.push_back(CI.getPCHContainerWriter().CreatePCHContainerGenerator(
97100
CI, InFile, OutputFile, OS, Buffer));
98101

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "pragma-once2.h"

‎clang/test/PCH/Inputs/pragma-once2.h

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#pragma once
2+
3+
inline void f() {}

‎clang/test/PCH/include-timestamp.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Test that the timestamp is not included in the produced pch file with
2+
// -fno-pch-timestamp.
3+
4+
// Check timestamp is included by default.
5+
// RUN: %clang_cc1 -x c++-header -emit-pch -o %t %S/Inputs/pragma-once2-pch.h
6+
// RUN: touch -m -a -t 201008011501 %S/Inputs/pragma-once2.h
7+
// RUN: not %clang_cc1 -include-pch %t %s 2>&1 | FileCheck -check-prefix=CHECK-TIMESTAMP %s
8+
9+
// Check bitcode output as well.
10+
// RUN: llvm-bcanalyzer -dump %t | FileCheck -check-prefix=CHECK-BITCODE-TIMESTAMP-ON %s
11+
12+
// Check timestamp inclusion is disabled by -fno-pch-timestamp.
13+
// RUN: %clang_cc1 -x c++-header -emit-pch -o %t %S/Inputs/pragma-once2-pch.h -fno-pch-timestamp
14+
// RUN: touch -m -a -t 201008011502 %S/Inputs/pragma-once2.h
15+
// RUN: %clang_cc1 -include-pch %t %s 2>&1
16+
17+
// Check bitcode output as well.
18+
// RUN: llvm-bcanalyzer -dump %t | FileCheck -check-prefix=CHECK-BITCODE-TIMESTAMP-OFF %s
19+
20+
#include "Inputs/pragma-once2.h"
21+
22+
void g() { f(); }
23+
24+
// CHECK-BITCODE-TIMESTAMP-ON: <INPUT_FILE abbrevid={{.*}} op0={{.*}} op1={{.*}} op2={{[^0]}}
25+
// CHECK-BITCODE-TIMESTAMP-OFF: <INPUT_FILE abbrevid={{.*}} op0={{.*}} op1={{.*}} op2={{[0]}}
26+
27+
// CHECK-TIMESTAMP: fatal error: file {{.*}} has been modified since the precompiled header {{.*}} was built

0 commit comments

Comments
 (0)