diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2022-03-20 11:40:34 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2022-05-14 11:43:05 +0000 |
commit | 349cc55c9796c4596a5b9904cd3281af295f878f (patch) | |
tree | 410c5a785075730a35f1272ca6a7adf72222ad03 /contrib/llvm-project/clang/lib/Frontend/CompilerInvocation.cpp | |
parent | cb2ae6163174b90e999326ecec3699ee093a5d43 (diff) | |
parent | c0981da47d5696fe36474fcf86b4ce03ae3ff818 (diff) |
Diffstat (limited to 'contrib/llvm-project/clang/lib/Frontend/CompilerInvocation.cpp')
-rw-r--r-- | contrib/llvm-project/clang/lib/Frontend/CompilerInvocation.cpp | 256 |
1 files changed, 158 insertions, 98 deletions
diff --git a/contrib/llvm-project/clang/lib/Frontend/CompilerInvocation.cpp b/contrib/llvm-project/clang/lib/Frontend/CompilerInvocation.cpp index 7025028bc94a..c104a6f40e20 100644 --- a/contrib/llvm-project/clang/lib/Frontend/CompilerInvocation.cpp +++ b/contrib/llvm-project/clang/lib/Frontend/CompilerInvocation.cpp @@ -78,6 +78,7 @@ #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/ErrorOr.h" #include "llvm/Support/FileSystem.h" +#include "llvm/Support/HashBuilder.h" #include "llvm/Support/Host.h" #include "llvm/Support/MathExtras.h" #include "llvm/Support/MemoryBuffer.h" @@ -453,6 +454,8 @@ static bool FixupInvocation(CompilerInvocation &Invocation, CodeGenOpts.XRayAlwaysEmitTypedEvents = LangOpts.XRayAlwaysEmitTypedEvents; CodeGenOpts.DisableFree = FrontendOpts.DisableFree; FrontendOpts.GenerateGlobalModuleIndex = FrontendOpts.UseGlobalModuleIndex; + if (FrontendOpts.ShowStats) + CodeGenOpts.ClearASTBeforeBackend = false; LangOpts.SanitizeCoverage = CodeGenOpts.hasSanitizeCoverage(); LangOpts.ForceEmitVTables = CodeGenOpts.ForceEmitVTables; LangOpts.SpeculativeLoadHardening = CodeGenOpts.SpeculativeLoadHardening; @@ -503,9 +506,10 @@ static bool FixupInvocation(CompilerInvocation &Invocation, // -cl-strict-aliasing needs to emit diagnostic in the case where CL > 1.0. // This option should be deprecated for CL > 1.0 because // this option was added for compatibility with OpenCL 1.0. - if (Args.getLastArg(OPT_cl_strict_aliasing) && LangOpts.OpenCLVersion > 100) + if (Args.getLastArg(OPT_cl_strict_aliasing) && + (LangOpts.getOpenCLCompatibleVersion() > 100)) Diags.Report(diag::warn_option_invalid_ocl_version) - << LangOpts.getOpenCLVersionTuple().getAsString() + << LangOpts.getOpenCLVersionString() << Args.getLastArg(OPT_cl_strict_aliasing)->getAsString(Args); if (Arg *A = Args.getLastArg(OPT_fdefault_calling_conv_EQ)) { @@ -608,9 +612,8 @@ using GenerateFn = llvm::function_ref<void( CompilerInvocation::StringAllocator)>; // May perform round-trip of command line arguments. By default, the round-trip -// is enabled if CLANG_ROUND_TRIP_CC1_ARGS was defined during build. This can be -// overwritten at run-time via the "-round-trip-args" and "-no-round-trip-args" -// command line flags. +// is enabled in assert builds. This can be overwritten at run-time via the +// "-round-trip-args" and "-no-round-trip-args" command line flags. // During round-trip, the command line arguments are parsed into a dummy // instance of CompilerInvocation which is used to generate the command line // arguments again. The real CompilerInvocation instance is then created by @@ -620,8 +623,7 @@ static bool RoundTrip(ParseFn Parse, GenerateFn Generate, CompilerInvocation &DummyInvocation, ArrayRef<const char *> CommandLineArgs, DiagnosticsEngine &Diags, const char *Argv0) { - // FIXME: Switch to '#ifndef NDEBUG' when possible. -#ifdef CLANG_ROUND_TRIP_CC1_ARGS +#ifndef NDEBUG bool DoRoundTripDefault = true; #else bool DoRoundTripDefault = false; @@ -995,7 +997,7 @@ static bool ParseAnalyzerArgs(AnalyzerOptions &Opts, ArgList &Args, diag::err_analyzer_config_no_value) << configVal; break; } - if (val.find('=') != StringRef::npos) { + if (val.contains('=')) { Diags.Report(SourceLocation(), diag::err_analyzer_config_multiple_values) << configVal; @@ -1118,10 +1120,9 @@ static void parseAnalyzerConfigs(AnalyzerOptions &AnOpts, for (const StringRef &CheckerOrPackage : CheckersAndPackages) { if (Diags) { bool IsChecker = CheckerOrPackage.contains('.'); - bool IsValidName = - IsChecker - ? llvm::find(Checkers, CheckerOrPackage) != Checkers.end() - : llvm::find(Packages, CheckerOrPackage) != Packages.end(); + bool IsValidName = IsChecker + ? llvm::is_contained(Checkers, CheckerOrPackage) + : llvm::is_contained(Packages, CheckerOrPackage); if (!IsValidName) Diags->Report(diag::err_unknown_analyzer_checker_or_package) @@ -1172,8 +1173,9 @@ ParseOptimizationRemark(DiagnosticsEngine &Diags, ArgList &Args, OptSpecifier OptEQ, StringRef Name) { CodeGenOptions::OptRemark Result; - auto InitializeResultPattern = [&Diags, &Args, &Result](const Arg *A) { - Result.Pattern = A->getValue(); + auto InitializeResultPattern = [&Diags, &Args, &Result](const Arg *A, + StringRef Pattern) { + Result.Pattern = Pattern.str(); std::string RegexError; Result.Regex = std::make_shared<llvm::Regex>(Result.Pattern); @@ -1198,19 +1200,23 @@ ParseOptimizationRemark(DiagnosticsEngine &Diags, ArgList &Args, Result.Kind = CodeGenOptions::RK_Disabled; else if (Value == "no-everything") Result.Kind = CodeGenOptions::RK_DisabledEverything; + else + continue; + + if (Result.Kind == CodeGenOptions::RK_Disabled || + Result.Kind == CodeGenOptions::RK_DisabledEverything) { + Result.Pattern = ""; + Result.Regex = nullptr; + } else { + InitializeResultPattern(A, ".*"); + } } else if (A->getOption().matches(OptEQ)) { Result.Kind = CodeGenOptions::RK_WithPattern; - if (!InitializeResultPattern(A)) + if (!InitializeResultPattern(A, A->getValue())) return CodeGenOptions::OptRemark(); } } - if (Result.Kind == CodeGenOptions::RK_Disabled || - Result.Kind == CodeGenOptions::RK_DisabledEverything) { - Result.Pattern = ""; - Result.Regex = nullptr; - } - return Result; } @@ -1406,6 +1412,13 @@ void CompilerInvocation::GenerateCodeGenArgs( llvm::DICompileUnit::DebugNameTableKind::Default)) GenerateArg(Args, OPT_gpubnames, SA); + auto TNK = Opts.getDebugSimpleTemplateNames(); + if (TNK != codegenoptions::DebugTemplateNamesKind::Full) { + if (TNK == codegenoptions::DebugTemplateNamesKind::Simple) + GenerateArg(Args, OPT_gsimple_template_names_EQ, "simple", SA); + else if (TNK == codegenoptions::DebugTemplateNamesKind::Mangled) + GenerateArg(Args, OPT_gsimple_template_names_EQ, "mangled", SA); + } // ProfileInstrumentUsePath is marshalled automatically, no need to generate // it or PGOUseInstrumentor. @@ -1417,7 +1430,7 @@ void CompilerInvocation::GenerateCodeGenArgs( } if (Opts.PrepareForLTO && !Opts.PrepareForThinLTO) - GenerateArg(Args, OPT_flto, SA); + GenerateArg(Args, OPT_flto_EQ, "full", SA); if (Opts.PrepareForThinLTO) GenerateArg(Args, OPT_flto_EQ, "thin", SA); @@ -1680,6 +1693,16 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, : Args.hasArg(OPT_gpubnames) ? llvm::DICompileUnit::DebugNameTableKind::Default : llvm::DICompileUnit::DebugNameTableKind::None); + if (const Arg *A = Args.getLastArg(OPT_gsimple_template_names_EQ)) { + StringRef Value = A->getValue(); + if (Value != "simple" && Value != "mangled") + Diags.Report(diag::err_drv_unsupported_option_argument) + << A->getOption().getName() << A->getValue(); + Opts.setDebugSimpleTemplateNames( + StringRef(A->getValue()) == "simple" + ? codegenoptions::DebugTemplateNamesKind::Simple + : codegenoptions::DebugTemplateNamesKind::Mangled); + } if (!Opts.ProfileInstrumentUsePath.empty()) setPGOUseInstrumentor(Opts, Opts.ProfileInstrumentUsePath); @@ -1704,9 +1727,10 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, } } - Opts.PrepareForLTO = Args.hasArg(OPT_flto, OPT_flto_EQ); + Opts.PrepareForLTO = false; Opts.PrepareForThinLTO = false; if (Arg *A = Args.getLastArg(OPT_flto_EQ)) { + Opts.PrepareForLTO = true; StringRef S = A->getValue(); if (S == "thin") Opts.PrepareForThinLTO = true; @@ -2035,13 +2059,13 @@ static bool ParseDependencyOutputArgs(DependencyOutputOptions &Opts, if (!Args.hasArg(OPT_fno_sanitize_ignorelist)) { for (const auto *A : Args.filtered(OPT_fsanitize_ignorelist_EQ)) { StringRef Val = A->getValue(); - if (Val.find('=') == StringRef::npos) + if (!Val.contains('=')) Opts.ExtraDeps.emplace_back(std::string(Val), EDK_SanitizeIgnorelist); } if (Opts.IncludeSystemHeaders) { for (const auto *A : Args.filtered(OPT_fsanitize_system_ignorelist_EQ)) { StringRef Val = A->getValue(); - if (Val.find('=') == StringRef::npos) + if (!Val.contains('=')) Opts.ExtraDeps.emplace_back(std::string(Val), EDK_SanitizeIgnorelist); } } @@ -2058,7 +2082,7 @@ static bool ParseDependencyOutputArgs(DependencyOutputOptions &Opts, // Only the -fmodule-file=<file> form. for (const auto *A : Args.filtered(OPT_fmodule_file)) { StringRef Val = A->getValue(); - if (Val.find('=') == StringRef::npos) + if (!Val.contains('=')) Opts.ExtraDeps.emplace_back(std::string(Val), EDK_ModuleFile); } @@ -2255,6 +2279,19 @@ void CompilerInvocation::GenerateDiagnosticArgs( } } +std::unique_ptr<DiagnosticOptions> +clang::CreateAndPopulateDiagOpts(ArrayRef<const char *> Argv) { + auto DiagOpts = std::make_unique<DiagnosticOptions>(); + unsigned MissingArgIndex, MissingArgCount; + InputArgList Args = getDriverOptTable().ParseArgs( + Argv.slice(1), MissingArgIndex, MissingArgCount); + // We ignore MissingArgCount and the return value of ParseDiagnosticArgs. + // Any errors that would be diagnosed here will also be diagnosed later, + // when the DiagnosticsEngine actually exists. + (void)ParseDiagnosticArgs(*DiagOpts, Args); + return DiagOpts; +} + bool clang::ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args, DiagnosticsEngine *Diags, bool DefaultDiagColor) { @@ -2689,7 +2726,7 @@ static bool ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args, // Only the -fmodule-file=<file> form. for (const auto *A : Args.filtered(OPT_fmodule_file)) { StringRef Val = A->getValue(); - if (Val.find('=') == StringRef::npos) + if (!Val.contains('=')) Opts.ModuleFiles.push_back(std::string(Val)); } @@ -2837,7 +2874,7 @@ static void GenerateHeaderSearchArgs(HeaderSearchOptions &Opts, llvm::ArrayRef<frontend::IncludeDirGroup> Groups, llvm::Optional<bool> IsFramework, llvm::Optional<bool> IgnoreSysRoot) { - return llvm::find(Groups, Entry.Group) != Groups.end() && + return llvm::is_contained(Groups, Entry.Group) && (!IsFramework || (Entry.IsFramework == *IsFramework)) && (!IgnoreSysRoot || (Entry.IgnoreSysRoot == *IgnoreSysRoot)); }; @@ -2964,7 +3001,7 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args, // Only the -fmodule-file=<name>=<file> form. for (const auto *A : Args.filtered(OPT_fmodule_file)) { StringRef Val = A->getValue(); - if (Val.find('=') != StringRef::npos){ + if (Val.contains('=')) { auto Split = Val.split('='); Opts.PrebuiltModuleFiles.insert( {std::string(Split.first), std::string(Split.second)}); @@ -3091,7 +3128,7 @@ void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK, LangStd = LangStandard::lang_opencl12; break; case Language::OpenCLCXX: - LangStd = LangStandard::lang_openclcpp; + LangStd = LangStandard::lang_openclcpp10; break; case Language::CUDA: LangStd = LangStandard::lang_cuda; @@ -3150,8 +3187,6 @@ void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK, Opts.HexFloats = Std.hasHexFloats(); Opts.ImplicitInt = Std.hasImplicitInt(); - Opts.CPlusPlusModules = Opts.CPlusPlus20; - // Set OpenCL Version. Opts.OpenCL = Std.isOpenCL(); if (LangStd == LangStandard::lang_opencl10) @@ -3164,8 +3199,10 @@ void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK, Opts.OpenCLVersion = 200; else if (LangStd == LangStandard::lang_opencl30) Opts.OpenCLVersion = 300; - else if (LangStd == LangStandard::lang_openclcpp) + else if (LangStd == LangStandard::lang_openclcpp10) Opts.OpenCLCPlusPlusVersion = 100; + else if (LangStd == LangStandard::lang_openclcpp2021) + Opts.OpenCLCPlusPlusVersion = 202100; // OpenCL has some additional defaults. if (Opts.OpenCL) { @@ -3173,9 +3210,8 @@ void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK, Opts.ZVector = 0; Opts.setDefaultFPContractMode(LangOptions::FPM_On); Opts.OpenCLCPlusPlus = Opts.CPlusPlus; - Opts.OpenCLPipes = Opts.OpenCLCPlusPlus || Opts.OpenCLVersion == 200; - Opts.OpenCLGenericAddressSpace = - Opts.OpenCLCPlusPlus || Opts.OpenCLVersion == 200; + Opts.OpenCLPipes = Opts.getOpenCLCompatibleVersion() == 200; + Opts.OpenCLGenericAddressSpace = Opts.getOpenCLCompatibleVersion() == 200; // Include default header file for OpenCL. if (Opts.IncludeDefaultHeader) { @@ -3314,7 +3350,8 @@ void CompilerInvocation::GenerateLangArgs(const LangOptions &Opts, case LangStandard::lang_opencl12: case LangStandard::lang_opencl20: case LangStandard::lang_opencl30: - case LangStandard::lang_openclcpp: + case LangStandard::lang_openclcpp10: + case LangStandard::lang_openclcpp2021: StdOpt = OPT_cl_std_EQ; break; default: @@ -3445,6 +3482,19 @@ void CompilerInvocation::GenerateLangArgs(const LangOptions &Opts, GenerateArg(Args, OPT_fopenmp_version_EQ, Twine(Opts.OpenMP), SA); } + if (Opts.OpenMPTargetNewRuntime) + GenerateArg(Args, OPT_fopenmp_target_new_runtime, SA); + + if (Opts.OpenMPThreadSubscription) + GenerateArg(Args, OPT_fopenmp_assume_threads_oversubscription, SA); + + if (Opts.OpenMPTeamSubscription) + GenerateArg(Args, OPT_fopenmp_assume_teams_oversubscription, SA); + + if (Opts.OpenMPTargetDebug != 0) + GenerateArg(Args, OPT_fopenmp_target_debug_EQ, + Twine(Opts.OpenMPTargetDebug), SA); + if (Opts.OpenMPCUDANumSMs != 0) GenerateArg(Args, OPT_fopenmp_cuda_number_of_sm_EQ, Twine(Opts.OpenMPCUDANumSMs), SA); @@ -3611,7 +3661,9 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args, .Cases("cl1.2", "CL1.2", LangStandard::lang_opencl12) .Cases("cl2.0", "CL2.0", LangStandard::lang_opencl20) .Cases("cl3.0", "CL3.0", LangStandard::lang_opencl30) - .Cases("clc++", "CLC++", LangStandard::lang_openclcpp) + .Cases("clc++", "CLC++", LangStandard::lang_openclcpp10) + .Cases("clc++1.0", "CLC++1.0", LangStandard::lang_openclcpp10) + .Cases("clc++2021", "CLC++2021", LangStandard::lang_openclcpp2021) .Default(LangStandard::lang_unspecified); if (OpenCLLangStd == LangStandard::lang_unspecified) { @@ -3740,8 +3792,8 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args, // '-mignore-xcoff-visibility' is implied. The generated command line will // contain both '-fvisibility default' and '-mignore-xcoff-visibility' and // subsequent calls to `CreateFromArgs`/`generateCC1CommandLine` will always - // produce the same arguments. - + // produce the same arguments. + if (T.isOSAIX() && (Args.hasArg(OPT_mignore_xcoff_visibility) || !Args.hasArg(OPT_fvisibility))) Opts.IgnoreXCOFFVisibility = 1; @@ -3821,6 +3873,9 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args, Opts.OpenMP && Args.hasArg(options::OPT_fopenmp_enable_irbuilder); bool IsTargetSpecified = Opts.OpenMPIsDevice || Args.hasArg(options::OPT_fopenmp_targets_EQ); + Opts.OpenMPTargetNewRuntime = + Opts.OpenMPIsDevice && + Args.hasArg(options::OPT_fopenmp_target_new_runtime); Opts.ConvergentFunctions = Opts.ConvergentFunctions || Opts.OpenMPIsDevice; @@ -3848,6 +3903,7 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args, // handling code for those requiring so. if ((Opts.OpenMPIsDevice && (T.isNVPTX() || T.isAMDGCN())) || Opts.OpenCLCPlusPlus) { + Opts.Exceptions = 0; Opts.CXXExceptions = 0; } @@ -3863,6 +3919,27 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args, Opts.OpenMPCUDAReductionBufNum, Diags); } + // Set the value of the debugging flag used in the new offloading device RTL. + // Set either by a specific value or to a default if not specified. + if (Opts.OpenMPIsDevice && (Args.hasArg(OPT_fopenmp_target_debug) || + Args.hasArg(OPT_fopenmp_target_debug_EQ))) { + if (Opts.OpenMPTargetNewRuntime) { + Opts.OpenMPTargetDebug = getLastArgIntValue( + Args, OPT_fopenmp_target_debug_EQ, Opts.OpenMPTargetDebug, Diags); + if (!Opts.OpenMPTargetDebug && Args.hasArg(OPT_fopenmp_target_debug)) + Opts.OpenMPTargetDebug = 1; + } else { + Diags.Report(diag::err_drv_debug_no_new_runtime); + } + } + + if (Opts.OpenMPIsDevice && Opts.OpenMPTargetNewRuntime) { + if (Args.hasArg(OPT_fopenmp_assume_teams_oversubscription)) + Opts.OpenMPTeamSubscription = true; + if (Args.hasArg(OPT_fopenmp_assume_threads_oversubscription)) + Opts.OpenMPThreadSubscription = true; + } + // Get the OpenMP target triples if any. if (Arg *A = Args.getLastArg(options::OPT_fopenmp_targets_EQ)) { enum ArchPtrSize { Arch16Bit, Arch32Bit, Arch64Bit }; @@ -4460,116 +4537,99 @@ bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Invocation, } std::string CompilerInvocation::getModuleHash() const { + // FIXME: Consider using SHA1 instead of MD5. + llvm::HashBuilder<llvm::MD5, llvm::support::endianness::native> HBuilder; + // Note: For QoI reasons, the things we use as a hash here should all be // dumped via the -module-info flag. - using llvm::hash_code; - using llvm::hash_value; - using llvm::hash_combine; - using llvm::hash_combine_range; // Start the signature with the compiler version. - // FIXME: We'd rather use something more cryptographically sound than - // CityHash, but this will do for now. - hash_code code = hash_value(getClangFullRepositoryVersion()); + HBuilder.add(getClangFullRepositoryVersion()); // Also include the serialization version, in case LLVM_APPEND_VC_REV is off // and getClangFullRepositoryVersion() doesn't include git revision. - code = hash_combine(code, serialization::VERSION_MAJOR, - serialization::VERSION_MINOR); + HBuilder.add(serialization::VERSION_MAJOR, serialization::VERSION_MINOR); // Extend the signature with the language options -#define LANGOPT(Name, Bits, Default, Description) \ - code = hash_combine(code, LangOpts->Name); -#define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ - code = hash_combine(code, static_cast<unsigned>(LangOpts->get##Name())); +#define LANGOPT(Name, Bits, Default, Description) HBuilder.add(LangOpts->Name); +#define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ + HBuilder.add(static_cast<unsigned>(LangOpts->get##Name())); #define BENIGN_LANGOPT(Name, Bits, Default, Description) #define BENIGN_ENUM_LANGOPT(Name, Type, Bits, Default, Description) #include "clang/Basic/LangOptions.def" - for (StringRef Feature : LangOpts->ModuleFeatures) - code = hash_combine(code, Feature); + HBuilder.addRange(LangOpts->ModuleFeatures); - code = hash_combine(code, LangOpts->ObjCRuntime); - const auto &BCN = LangOpts->CommentOpts.BlockCommandNames; - code = hash_combine(code, hash_combine_range(BCN.begin(), BCN.end())); + HBuilder.add(LangOpts->ObjCRuntime); + HBuilder.addRange(LangOpts->CommentOpts.BlockCommandNames); // Extend the signature with the target options. - code = hash_combine(code, TargetOpts->Triple, TargetOpts->CPU, - TargetOpts->TuneCPU, TargetOpts->ABI); - for (const auto &FeatureAsWritten : TargetOpts->FeaturesAsWritten) - code = hash_combine(code, FeatureAsWritten); + HBuilder.add(TargetOpts->Triple, TargetOpts->CPU, TargetOpts->TuneCPU, + TargetOpts->ABI); + HBuilder.addRange(TargetOpts->FeaturesAsWritten); // Extend the signature with preprocessor options. const PreprocessorOptions &ppOpts = getPreprocessorOpts(); - const HeaderSearchOptions &hsOpts = getHeaderSearchOpts(); - code = hash_combine(code, ppOpts.UsePredefines, ppOpts.DetailedRecord); + HBuilder.add(ppOpts.UsePredefines, ppOpts.DetailedRecord); - for (const auto &I : getPreprocessorOpts().Macros) { + const HeaderSearchOptions &hsOpts = getHeaderSearchOpts(); + for (const auto &Macro : getPreprocessorOpts().Macros) { // If we're supposed to ignore this macro for the purposes of modules, // don't put it into the hash. if (!hsOpts.ModulesIgnoreMacros.empty()) { // Check whether we're ignoring this macro. - StringRef MacroDef = I.first; + StringRef MacroDef = Macro.first; if (hsOpts.ModulesIgnoreMacros.count( llvm::CachedHashString(MacroDef.split('=').first))) continue; } - code = hash_combine(code, I.first, I.second); + HBuilder.add(Macro); } // Extend the signature with the sysroot and other header search options. - code = hash_combine(code, hsOpts.Sysroot, - hsOpts.ModuleFormat, - hsOpts.UseDebugInfo, - hsOpts.UseBuiltinIncludes, - hsOpts.UseStandardSystemIncludes, - hsOpts.UseStandardCXXIncludes, - hsOpts.UseLibcxx, - hsOpts.ModulesValidateDiagnosticOptions); - code = hash_combine(code, hsOpts.ResourceDir); + HBuilder.add(hsOpts.Sysroot, hsOpts.ModuleFormat, hsOpts.UseDebugInfo, + hsOpts.UseBuiltinIncludes, hsOpts.UseStandardSystemIncludes, + hsOpts.UseStandardCXXIncludes, hsOpts.UseLibcxx, + hsOpts.ModulesValidateDiagnosticOptions); + HBuilder.add(hsOpts.ResourceDir); if (hsOpts.ModulesStrictContextHash) { - hash_code SHPC = hash_combine_range(hsOpts.SystemHeaderPrefixes.begin(), - hsOpts.SystemHeaderPrefixes.end()); - hash_code UEC = hash_combine_range(hsOpts.UserEntries.begin(), - hsOpts.UserEntries.end()); - code = hash_combine(code, hsOpts.SystemHeaderPrefixes.size(), SHPC, - hsOpts.UserEntries.size(), UEC); + HBuilder.addRange(hsOpts.SystemHeaderPrefixes); + HBuilder.addRange(hsOpts.UserEntries); const DiagnosticOptions &diagOpts = getDiagnosticOpts(); - #define DIAGOPT(Name, Bits, Default) \ - code = hash_combine(code, diagOpts.Name); - #define ENUM_DIAGOPT(Name, Type, Bits, Default) \ - code = hash_combine(code, diagOpts.get##Name()); - #include "clang/Basic/DiagnosticOptions.def" - #undef DIAGOPT - #undef ENUM_DIAGOPT +#define DIAGOPT(Name, Bits, Default) HBuilder.add(diagOpts.Name); +#define ENUM_DIAGOPT(Name, Type, Bits, Default) \ + HBuilder.add(diagOpts.get##Name()); +#include "clang/Basic/DiagnosticOptions.def" +#undef DIAGOPT +#undef ENUM_DIAGOPT } // Extend the signature with the user build path. - code = hash_combine(code, hsOpts.ModuleUserBuildPath); + HBuilder.add(hsOpts.ModuleUserBuildPath); // Extend the signature with the module file extensions. - const FrontendOptions &frontendOpts = getFrontendOpts(); - for (const auto &ext : frontendOpts.ModuleFileExtensions) { - code = ext->hashExtension(code); - } + for (const auto &ext : getFrontendOpts().ModuleFileExtensions) + ext->hashExtension(HBuilder); // When compiling with -gmodules, also hash -fdebug-prefix-map as it // affects the debug info in the PCM. if (getCodeGenOpts().DebugTypeExtRefs) - for (const auto &KeyValue : getCodeGenOpts().DebugPrefixMap) - code = hash_combine(code, KeyValue.first, KeyValue.second); + HBuilder.addRange(getCodeGenOpts().DebugPrefixMap); // Extend the signature with the enabled sanitizers, if at least one is // enabled. Sanitizers which cannot affect AST generation aren't hashed. SanitizerSet SanHash = LangOpts->Sanitize; SanHash.clear(getPPTransparentSanitizers()); if (!SanHash.empty()) - code = hash_combine(code, SanHash.Mask); + HBuilder.add(SanHash.Mask); - return toString(llvm::APInt(64, code), 36, /*Signed=*/false); + llvm::MD5::MD5Result Result; + HBuilder.getHasher().final(Result); + uint64_t Hash = Result.high() ^ Result.low(); + return toString(llvm::APInt(64, Hash), 36, /*Signed=*/false); } void CompilerInvocation::generateCC1CommandLine( |