r275267 - [PCH] Add a fno-pch-timestamp option to cc1 to disable inclusion of timestamps in PCH files.
Pierre Gousseau via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 13 07:21:11 PDT 2016
Author: pgousseau
Date: Wed Jul 13 09:21:11 2016
New Revision: 275267
URL: http://llvm.org/viewvc/llvm-project?rev=275267&view=rev
Log:
[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
Added:
cfe/trunk/test/PCH/Inputs/pragma-once2-pch.h
cfe/trunk/test/PCH/Inputs/pragma-once2.h
cfe/trunk/test/PCH/include-timestamp.cpp
Modified:
cfe/trunk/include/clang/Driver/CC1Options.td
cfe/trunk/include/clang/Frontend/FrontendOptions.h
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/lib/Frontend/FrontendActions.cpp
Modified: cfe/trunk/include/clang/Driver/CC1Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=275267&r1=275266&r2=275267&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)
+++ cfe/trunk/include/clang/Driver/CC1Options.td Wed Jul 13 09:21:11 2016
@@ -509,6 +509,8 @@ def find_pch_source_EQ : Joined<["-"], "
HelpText<"When building a pch, try to find the input file in include "
"directories, as if it had been included by the argument passed "
"to this flag.">;
+def fno_pch_timestamp : Flag<["-"], "fno-pch-timestamp">,
+ HelpText<"Disable inclusion of timestamp in precompiled headers">;
//===----------------------------------------------------------------------===//
// Language Options
Modified: cfe/trunk/include/clang/Frontend/FrontendOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/FrontendOptions.h?rev=275267&r1=275266&r2=275267&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/FrontendOptions.h (original)
+++ cfe/trunk/include/clang/Frontend/FrontendOptions.h Wed Jul 13 09:21:11 2016
@@ -154,6 +154,8 @@ public:
///< implicit module build.
unsigned ModulesEmbedAllFiles : 1; ///< Whether we should embed all used
///< files into the PCM file.
+ unsigned IncludeTimestamps : 1; ///< Whether timestamps should be
+ ///< written to the produced PCH file.
CodeCompleteOptions CodeCompleteOpts;
@@ -278,8 +280,8 @@ public:
SkipFunctionBodies(false), UseGlobalModuleIndex(true),
GenerateGlobalModuleIndex(true), ASTDumpDecls(false), ASTDumpLookups(false),
BuildingImplicitModule(false), ModulesEmbedAllFiles(false),
- ARCMTAction(ARCMT_None), ObjCMTAction(ObjCMT_None),
- ProgramAction(frontend::ParseSyntaxOnly)
+ IncludeTimestamps(true), ARCMTAction(ARCMT_None),
+ ObjCMTAction(ObjCMT_None), ProgramAction(frontend::ParseSyntaxOnly)
{}
/// getInputKindForExtension - Return the appropriate input kind for a file
Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=275267&r1=275266&r2=275267&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Wed Jul 13 09:21:11 2016
@@ -1197,6 +1197,7 @@ static InputKind ParseFrontendArgs(Front
Opts.ModuleFiles = Args.getAllArgValues(OPT_fmodule_file);
Opts.ModulesEmbedFiles = Args.getAllArgValues(OPT_fmodules_embed_file_EQ);
Opts.ModulesEmbedAllFiles = Args.hasArg(OPT_fmodules_embed_all_files);
+ Opts.IncludeTimestamps = !Args.hasArg(OPT_fno_pch_timestamp);
Opts.CodeCompleteOpts.IncludeMacros
= Args.hasArg(OPT_code_completion_macros);
Modified: cfe/trunk/lib/Frontend/FrontendActions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendActions.cpp?rev=275267&r1=275266&r2=275267&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/FrontendActions.cpp (original)
+++ cfe/trunk/lib/Frontend/FrontendActions.cpp Wed Jul 13 09:21:11 2016
@@ -92,7 +92,10 @@ GeneratePCHAction::CreateASTConsumer(Com
std::vector<std::unique_ptr<ASTConsumer>> Consumers;
Consumers.push_back(llvm::make_unique<PCHGenerator>(
CI.getPreprocessor(), OutputFile, nullptr, Sysroot,
- Buffer, CI.getFrontendOpts().ModuleFileExtensions));
+ Buffer, CI.getFrontendOpts().ModuleFileExtensions,
+ /*AllowASTWithErrors*/false,
+ /*IncludeTimestamps*/
+ +CI.getFrontendOpts().IncludeTimestamps));
Consumers.push_back(CI.getPCHContainerWriter().CreatePCHContainerGenerator(
CI, InFile, OutputFile, OS, Buffer));
Added: cfe/trunk/test/PCH/Inputs/pragma-once2-pch.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/Inputs/pragma-once2-pch.h?rev=275267&view=auto
==============================================================================
--- cfe/trunk/test/PCH/Inputs/pragma-once2-pch.h (added)
+++ cfe/trunk/test/PCH/Inputs/pragma-once2-pch.h Wed Jul 13 09:21:11 2016
@@ -0,0 +1 @@
+#include "pragma-once2.h"
Added: cfe/trunk/test/PCH/Inputs/pragma-once2.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/Inputs/pragma-once2.h?rev=275267&view=auto
==============================================================================
--- cfe/trunk/test/PCH/Inputs/pragma-once2.h (added)
+++ cfe/trunk/test/PCH/Inputs/pragma-once2.h Wed Jul 13 09:21:11 2016
@@ -0,0 +1,3 @@
+#pragma once
+
+inline void f() {}
Added: cfe/trunk/test/PCH/include-timestamp.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/include-timestamp.cpp?rev=275267&view=auto
==============================================================================
--- cfe/trunk/test/PCH/include-timestamp.cpp (added)
+++ cfe/trunk/test/PCH/include-timestamp.cpp Wed Jul 13 09:21:11 2016
@@ -0,0 +1,27 @@
+// Test that the timestamp is not included in the produced pch file with
+// -fno-pch-timestamp.
+
+// Check timestamp is included by default.
+// RUN: %clang_cc1 -x c++-header -emit-pch -o %t %S/Inputs/pragma-once2-pch.h
+// RUN: touch -m -a -t 201008011501 %S/Inputs/pragma-once2.h
+// RUN: not %clang_cc1 -include-pch %t %s 2>&1 | FileCheck -check-prefix=CHECK-TIMESTAMP %s
+
+// Check bitcode output as well.
+// RUN: llvm-bcanalyzer -dump %t | FileCheck -check-prefix=CHECK-BITCODE-TIMESTAMP-ON %s
+
+// Check timestamp inclusion is disabled by -fno-pch-timestamp.
+// RUN: %clang_cc1 -x c++-header -emit-pch -o %t %S/Inputs/pragma-once2-pch.h -fno-pch-timestamp
+// RUN: touch -m -a -t 201008011502 %S/Inputs/pragma-once2.h
+// RUN: %clang_cc1 -include-pch %t %s 2>&1
+
+// Check bitcode output as well.
+// RUN: llvm-bcanalyzer -dump %t | FileCheck -check-prefix=CHECK-BITCODE-TIMESTAMP-OFF %s
+
+#include "Inputs/pragma-once2.h"
+
+void g() { f(); }
+
+// CHECK-BITCODE-TIMESTAMP-ON: <INPUT_FILE abbrevid={{.*}} op0={{.*}} op1={{.*}} op2={{[^0]}}
+// CHECK-BITCODE-TIMESTAMP-OFF: <INPUT_FILE abbrevid={{.*}} op0={{.*}} op1={{.*}} op2={{[0]}}
+
+// CHECK-TIMESTAMP: fatal error: file {{.*}} has been modified since the precompiled header {{.*}} was built
More information about the cfe-commits
mailing list