From: Pierre Gousseau Date: Wed, 13 Jul 2016 14:21:11 +0000 (+0000) Subject: [PCH] Add a fno-pch-timestamp option to cc1 to disable inclusion of timestamps in... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4e7c8ba2f78c17974062fc0f239f4ed0b87ed611;p=clang [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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@275267 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td index 3402d8d624..1401984c2a 100644 --- a/include/clang/Driver/CC1Options.td +++ b/include/clang/Driver/CC1Options.td @@ -509,6 +509,8 @@ def find_pch_source_EQ : Joined<["-"], "find-pch-source=">, 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 diff --git a/include/clang/Frontend/FrontendOptions.h b/include/clang/Frontend/FrontendOptions.h index d49d8de6f5..a75523f256 100644 --- a/include/clang/Frontend/FrontendOptions.h +++ b/include/clang/Frontend/FrontendOptions.h @@ -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 diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 59cb40108a..7bc91ad79b 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -1197,6 +1197,7 @@ static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args, 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); diff --git a/lib/Frontend/FrontendActions.cpp b/lib/Frontend/FrontendActions.cpp index dd5479ca71..6ddb316fd0 100644 --- a/lib/Frontend/FrontendActions.cpp +++ b/lib/Frontend/FrontendActions.cpp @@ -92,7 +92,10 @@ GeneratePCHAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { std::vector> Consumers; Consumers.push_back(llvm::make_unique( 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)); diff --git a/test/PCH/Inputs/pragma-once2-pch.h b/test/PCH/Inputs/pragma-once2-pch.h new file mode 100644 index 0000000000..642b50f15a --- /dev/null +++ b/test/PCH/Inputs/pragma-once2-pch.h @@ -0,0 +1 @@ +#include "pragma-once2.h" diff --git a/test/PCH/Inputs/pragma-once2.h b/test/PCH/Inputs/pragma-once2.h new file mode 100644 index 0000000000..7ed4a95520 --- /dev/null +++ b/test/PCH/Inputs/pragma-once2.h @@ -0,0 +1,3 @@ +#pragma once + +inline void f() {} diff --git a/test/PCH/include-timestamp.cpp b/test/PCH/include-timestamp.cpp new file mode 100644 index 0000000000..1add189c69 --- /dev/null +++ b/test/PCH/include-timestamp.cpp @@ -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: