Skip to content

Commit

Permalink
Merge from 'master' to 'sycl-web' (intel#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
sndmitriev committed Oct 22, 2019
2 parents d8e2786 + 734c74b commit 2a576c8
Show file tree
Hide file tree
Showing 138 changed files with 3,853 additions and 1,683 deletions.
10 changes: 10 additions & 0 deletions clang/docs/Modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,16 @@ Command-line parameters
``-fprebuilt-module-path=<directory>``
Specify the path to the prebuilt modules. If specified, we will look for modules in this directory for a given top-level module name. We don't need a module map for loading prebuilt modules in this directory and the compiler will not try to rebuild these modules. This can be specified multiple times.

-cc1 Options
~~~~~~~~~~~~

``-fmodules-strict-context-hash``
Enables hashing of all compiler options that could impact the semantics of a
module in an implicit build. This includes things such as header search paths
and diagnostics. Using this option may lead to an excessive number of modules
being built if the command line arguments are not homogeneous across your
build.

Module Semantics
================

Expand Down
8 changes: 4 additions & 4 deletions clang/include/clang/Basic/TargetInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
#include "clang/Basic/Specifiers.h"
#include "clang/Basic/TargetCXXABI.h"
#include "clang/Basic/TargetOptions.h"
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/IntrusiveRefCntPtr.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Triple.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/Support/DataTypes.h"
#include "llvm/Support/VersionTuple.h"
#include <cassert>
Expand All @@ -35,6 +36,7 @@

namespace llvm {
struct fltSemantics;
class DataLayout;
}

namespace clang {
Expand Down Expand Up @@ -198,9 +200,7 @@ class TargetInfo : public virtual TransferrableTargetInfo,
// TargetInfo Constructor. Default initializes all fields.
TargetInfo(const llvm::Triple &T);

void resetDataLayout(StringRef DL) {
DataLayout.reset(new llvm::DataLayout(DL));
}
void resetDataLayout(StringRef DL);

public:
/// Construct a target for the given options.
Expand Down
3 changes: 3 additions & 0 deletions clang/include/clang/Driver/CC1Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,9 @@ def fdisable_module_hash : Flag<["-"], "fdisable-module-hash">,
HelpText<"Disable the module hash">;
def fmodules_hash_content : Flag<["-"], "fmodules-hash-content">,
HelpText<"Enable hashing the content of a module file">;
def fmodules_strict_context_hash : Flag<["-"], "fmodules-strict-context-hash">,
HelpText<"Enable hashing of all compiler options that could impact the "
"semantics of a module in an implicit build">;
def c_isystem : JoinedOrSeparate<["-"], "c-isystem">, MetaVarName<"<directory>">,
HelpText<"Add directory to the C SYSTEM include search path">;
def objc_isystem : JoinedOrSeparate<["-"], "objc-isystem">,
Expand Down
24 changes: 21 additions & 3 deletions clang/include/clang/Frontend/CompilerInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ class CompilerInstance : public ModuleLoader {
/// One or more modules failed to build.
bool ModuleBuildFailed = false;

/// The stream for verbose output if owned, otherwise nullptr.
std::unique_ptr<raw_ostream> OwnedVerboseOutputStream;

/// The stream for verbose output.
raw_ostream *VerboseOutputStream = &llvm::errs();

/// Holds information about the output file.
///
/// If TempFilename is not empty we must rename it to Filename at the end.
Expand Down Expand Up @@ -217,9 +223,6 @@ class CompilerInstance : public ModuleLoader {
/// \param Act - The action to execute.
/// \return - True on success.
//
// FIXME: This function should take the stream to write any debugging /
// verbose output to as an argument.
//
// FIXME: Eliminate the llvm_shutdown requirement, that should either be part
// of the context or else not CompilerInstance specific.
bool ExecuteAction(FrontendAction &Act);
Expand Down Expand Up @@ -349,6 +352,21 @@ class CompilerInstance : public ModuleLoader {
return *Diagnostics->getClient();
}

/// }
/// @name VerboseOutputStream
/// }

/// Replace the current stream for verbose output.
void setVerboseOutputStream(raw_ostream &Value);

/// Replace the current stream for verbose output.
void setVerboseOutputStream(std::unique_ptr<raw_ostream> Value);

/// Get the current stream for verbose output.
raw_ostream &getVerboseOutputStream() {
return *VerboseOutputStream;
}

/// }
/// @name Target Info
/// {
Expand Down
20 changes: 19 additions & 1 deletion clang/include/clang/Lex/HeaderSearchOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "clang/Basic/LLVM.h"
#include "llvm/ADT/CachedHashString.h"
#include "llvm/ADT/Hashing.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/StringRef.h"
#include <cstdint>
Expand Down Expand Up @@ -206,6 +207,13 @@ class HeaderSearchOptions {

unsigned ModulesHashContent : 1;

/// Whether we should include all things that could impact the module in the
/// hash.
///
/// This includes things like the full header search path, and enabled
/// diagnostics.
unsigned ModulesStrictContextHash : 1;

HeaderSearchOptions(StringRef _Sysroot = "/")
: Sysroot(_Sysroot), ModuleFormat("raw"), DisableModuleHash(false),
ImplicitModuleMaps(false), ModuleMapFileHomeIsCwd(false),
Expand All @@ -214,7 +222,8 @@ class HeaderSearchOptions {
ModulesValidateOncePerBuildSession(false),
ModulesValidateSystemHeaders(false),
ValidateASTInputFilesContent(false), UseDebugInfo(false),
ModulesValidateDiagnosticOptions(true), ModulesHashContent(false) {}
ModulesValidateDiagnosticOptions(true), ModulesHashContent(false),
ModulesStrictContextHash(false) {}

/// AddPath - Add the \p Path path to the specified \p Group list.
void AddPath(StringRef Path, frontend::IncludeDirGroup Group,
Expand All @@ -238,6 +247,15 @@ class HeaderSearchOptions {
}
};

inline llvm::hash_code hash_value(const HeaderSearchOptions::Entry &E) {
return llvm::hash_combine(E.Path, E.Group, E.IsFramework, E.IgnoreSysRoot);
}

inline llvm::hash_code
hash_value(const HeaderSearchOptions::SystemHeaderPrefix &SHP) {
return llvm::hash_combine(SHP.Prefix, SHP.IsSystemHeader);
}

} // namespace clang

#endif // LLVM_CLANG_LEX_HEADERSEARCHOPTIONS_H
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//===- DependencyScanningTool.h - clang-scan-deps service ------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_CLANG_TOOLING_DEPENDENCY_SCANNING_TOOL_H
#define LLVM_CLANG_TOOLING_DEPENDENCY_SCANNING_TOOL_H

#include "clang/Tooling/DependencyScanning/DependencyScanningService.h"
#include "clang/Tooling/DependencyScanning/DependencyScanningWorker.h"
#include "clang/Tooling/JSONCompilationDatabase.h"
#include <string>

namespace clang{
namespace tooling{
namespace dependencies{

/// The high-level implementation of the dependency discovery tool that runs on
/// an individual worker thread.
class DependencyScanningTool {
public:
/// Construct a dependency scanning tool.
///
/// \param Compilations The reference to the compilation database that's
/// used by the clang tool.
DependencyScanningTool(DependencyScanningService &Service, const clang::tooling::CompilationDatabase &Compilations);

/// Print out the dependency information into a string using the dependency
/// file format that is specified in the options (-MD is the default) and
/// return it.
///
/// \returns A \c StringError with the diagnostic output if clang errors
/// occurred, dependency file contents otherwise.
llvm::Expected<std::string> getDependencyFile(const std::string &Input, StringRef CWD);

private:
DependencyScanningWorker Worker;
const tooling::CompilationDatabase &Compilations;
};

} // end namespace dependencies
} // end namespace tooling
} // end namespace clang

#endif // LLVM_CLANG_TOOLING_DEPENDENCY_SCANNING_TOOL_H
5 changes: 5 additions & 0 deletions clang/lib/Basic/TargetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "clang/Basic/LangOptions.h"
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/TargetParser.h"
#include <cstdlib>
Expand Down Expand Up @@ -136,6 +137,10 @@ TargetInfo::TargetInfo(const llvm::Triple &T) : TargetOpts(), Triple(T) {
// Out of line virtual dtor for TargetInfo.
TargetInfo::~TargetInfo() {}

void TargetInfo::resetDataLayout(StringRef DL) {
DataLayout.reset(new llvm::DataLayout(DL));
}

bool
TargetInfo::checkCFProtectionBranchSupported(DiagnosticsEngine &Diags) const {
Diags.Report(diag::err_opt_not_valid_on_target) << "cf-protection=branch";
Expand Down
1 change: 1 addition & 0 deletions clang/lib/Basic/Targets/AMDGPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "clang/Basic/MacroBuilder.h"
#include "clang/Basic/TargetBuiltins.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/IR/DataLayout.h"

using namespace clang;
using namespace clang::targets;
Expand Down
1 change: 1 addition & 0 deletions clang/lib/Basic/Targets/SPIR.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "clang/Basic/TargetInfo.h"
#include "clang/Basic/TargetOptions.h"
#include "llvm/ADT/Triple.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/Support/Compiler.h"
#include "OSTargets.h"

Expand Down
15 changes: 14 additions & 1 deletion clang/lib/Driver/ToolChains/NetBSD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,10 +489,23 @@ SanitizerMask NetBSD::getSupportedSanitizers() const {
return Res;
}

void NetBSD::addClangTargetOptions(const ArgList &,
void NetBSD::addClangTargetOptions(const ArgList &DriverArgs,
ArgStringList &CC1Args,
Action::OffloadKind) const {
const SanitizerArgs &SanArgs = getSanitizerArgs();
if (SanArgs.hasAnySanitizer())
CC1Args.push_back("-D_REENTRANT");

unsigned Major, Minor, Micro;
getTriple().getOSVersion(Major, Minor, Micro);
bool UseInitArrayDefault =
Major >= 9 || Major == 0 ||
getTriple().getArch() == llvm::Triple::aarch64 ||
getTriple().getArch() == llvm::Triple::aarch64_be ||
getTriple().getArch() == llvm::Triple::arm ||
getTriple().getArch() == llvm::Triple::armeb;

if (DriverArgs.hasFlag(options::OPT_fuse_init_array,
options::OPT_fno_use_init_array, UseInitArrayDefault))
CC1Args.push_back("-fuse-init-array");
}
14 changes: 11 additions & 3 deletions clang/lib/Frontend/CompilerInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ void CompilerInstance::setDiagnostics(DiagnosticsEngine *Value) {
Diagnostics = Value;
}

void CompilerInstance::setVerboseOutputStream(raw_ostream &Value) {
OwnedVerboseOutputStream.release();
VerboseOutputStream = &Value;
}

void CompilerInstance::setVerboseOutputStream(std::unique_ptr<raw_ostream> Value) {
OwnedVerboseOutputStream.swap(Value);
VerboseOutputStream = OwnedVerboseOutputStream.get();
}

void CompilerInstance::setTarget(TargetInfo *Value) { Target = Value; }
void CompilerInstance::setAuxTarget(TargetInfo *Value) { AuxTarget = Value; }

Expand Down Expand Up @@ -896,9 +906,7 @@ bool CompilerInstance::ExecuteAction(FrontendAction &Act) {
// DesiredStackSpace available.
noteBottomOfStack();

// FIXME: Take this as an argument, once all the APIs we used have moved to
// taking it as an input instead of hard-coding llvm::errs.
raw_ostream &OS = llvm::errs();
raw_ostream &OS = getVerboseOutputStream();

if (!Act.PrepareToExecute(*this))
return false;
Expand Down
20 changes: 20 additions & 0 deletions clang/lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2069,6 +2069,7 @@ static void ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args,
Opts.AddPrebuiltModulePath(A->getValue());
Opts.DisableModuleHash = Args.hasArg(OPT_fdisable_module_hash);
Opts.ModulesHashContent = Args.hasArg(OPT_fmodules_hash_content);
Opts.ModulesStrictContextHash = Args.hasArg(OPT_fmodules_strict_context_hash);
Opts.ModulesValidateDiagnosticOptions =
!Args.hasArg(OPT_fmodules_disable_diagnostic_validation);
Opts.ImplicitModuleMaps = Args.hasArg(OPT_fimplicit_module_maps);
Expand Down Expand Up @@ -3576,6 +3577,7 @@ std::string CompilerInvocation::getModuleHash() const {
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
Expand Down Expand Up @@ -3630,6 +3632,24 @@ std::string CompilerInvocation::getModuleHash() const {
hsOpts.ModulesValidateDiagnosticOptions);
code = hash_combine(code, 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);

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
}

// Extend the signature with the user build path.
code = hash_combine(code, hsOpts.ModuleUserBuildPath);

Expand Down
1 change: 1 addition & 0 deletions clang/lib/Frontend/InitPreprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "clang/Lex/PreprocessorOptions.h"
#include "clang/Serialization/ASTReader.h"
#include "llvm/ADT/APFloat.h"
#include "llvm/IR/DataLayout.h"
using namespace clang;

static bool MacroBodyEndsInBackslash(StringRef MacroBody) {
Expand Down
7 changes: 3 additions & 4 deletions clang/lib/Sema/SemaExceptionSpec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,7 @@ static bool hasImplicitExceptionSpec(FunctionDecl *Decl) {
if (!Decl->getTypeSourceInfo())
return isa<CXXDestructorDecl>(Decl);

const FunctionProtoType *Ty =
Decl->getTypeSourceInfo()->getType()->getAs<FunctionProtoType>();
auto *Ty = Decl->getTypeSourceInfo()->getType()->castAs<FunctionProtoType>();
return !Ty->hasExceptionSpec();
}

Expand Down Expand Up @@ -965,9 +964,9 @@ bool Sema::CheckOverridingFunctionExceptionSpec(const CXXMethodDecl *New,
PDiag(diag::err_deep_exception_specs_differ),
PDiag(diag::note_overridden_virtual_function),
PDiag(diag::ext_override_exception_spec),
Old->getType()->getAs<FunctionProtoType>(),
Old->getType()->castAs<FunctionProtoType>(),
Old->getLocation(),
New->getType()->getAs<FunctionProtoType>(),
New->getType()->castAs<FunctionProtoType>(),
New->getLocation());
}

Expand Down
3 changes: 2 additions & 1 deletion clang/lib/Sema/SemaLambda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,8 @@ void Sema::handleLambdaNumbering(
}

auto getMangleNumberingContext =
[this](CXXRecordDecl *Class, Decl *ManglingContextDecl) -> MangleNumberingContext * {
[this](CXXRecordDecl *Class,
Decl *ManglingContextDecl) -> MangleNumberingContext * {
// Get mangle numbering context if there's any extra decl context.
if (ManglingContextDecl)
return &Context.getManglingNumberContext(
Expand Down
10 changes: 3 additions & 7 deletions clang/lib/Sema/SemaTemplateDeduction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3826,8 +3826,7 @@ Sema::TemplateDeductionResult Sema::DeduceTemplateArguments(
if (Args.size() < Function->getMinRequiredArguments() && !PartialOverloading)
return TDK_TooFewArguments;
else if (TooManyArguments(NumParams, Args.size(), PartialOverloading)) {
const FunctionProtoType *Proto
= Function->getType()->getAs<FunctionProtoType>();
const auto *Proto = Function->getType()->castAs<FunctionProtoType>();
if (Proto->isTemplateVariadic())
/* Do nothing */;
else if (!Proto->isVariadic())
Expand Down Expand Up @@ -3965,11 +3964,8 @@ QualType Sema::adjustCCAndNoReturn(QualType ArgFunctionType,
if (ArgFunctionType.isNull())
return ArgFunctionType;

const FunctionProtoType *FunctionTypeP =
FunctionType->castAs<FunctionProtoType>();
const FunctionProtoType *ArgFunctionTypeP =
ArgFunctionType->getAs<FunctionProtoType>();

const auto *FunctionTypeP = FunctionType->castAs<FunctionProtoType>();
const auto *ArgFunctionTypeP = ArgFunctionType->castAs<FunctionProtoType>();
FunctionProtoType::ExtProtoInfo EPI = ArgFunctionTypeP->getExtProtoInfo();
bool Rebuild = false;

Expand Down
Loading

0 comments on commit 2a576c8

Please sign in to comment.