Skip to content

Commit

Permalink
Merge from 'master' to 'sycl-web' (intel#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexeySachkov committed Apr 21, 2020
2 parents 5797b8c + aad3d57 commit dd3a824
Show file tree
Hide file tree
Showing 257 changed files with 4,920 additions and 2,097 deletions.
3 changes: 3 additions & 0 deletions clang/cmake/caches/CrossWinToARMLinux.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ set(LIBCXXABI_LINK_TESTS_WITH_SHARED_LIBCXX OFF CACHE BOOL "")
set(LIBCXX_LINK_TESTS_WITH_SHARED_LIBCXXABI OFF CACHE BOOL "")
set(LIBCXX_LINK_TESTS_WITH_SHARED_LIBCXX OFF CACHE BOOL "")

# FIXME: Remove this when https://reviews.llvm.org/D78200 is merged.
set(LIBCXX_ENABLE_FILESYSTEM OFF CACHE BOOL "")

set(LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
set(LIBCXX_TARGET_TRIPLE "${CMAKE_C_COMPILER_TARGET}" CACHE STRING "")
set(LIBCXX_SYSROOT "${DEFAULT_SYSROOT}" CACHE STRING "")
Expand Down
5 changes: 5 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ Modified Compiler Flags
- Duplicate qualifiers on asm statements (ex. `asm volatile volatile ("")`) no
longer produces a warning via -Wduplicate-decl-specifier, but now an error
(this matches GCC's behavior).
- The deprecated argument ``-f[no-]sanitize-recover`` has changed to mean
``-f[no-]sanitize-recover=all`` instead of
``-f[no-]sanitize-recover=undefined,integer`` and is no longer deprecated.
- The argument to ``-f[no-]sanitize-trap=...`` is now optional and defaults to
``all``.

New Pragmas in Clang
--------------------
Expand Down
4 changes: 4 additions & 0 deletions clang/docs/UndefinedBehaviorSanitizer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ and define the desired behavior for each kind of check:
* ``-fno-sanitize-recover=...``: print a verbose error report and exit the program;
* ``-fsanitize-trap=...``: execute a trap instruction (doesn't require UBSan run-time support).

Note that the ``trap`` / ``recover`` options do not enable the corresponding
sanitizer, and in general need to be accompanied by a suitable ``-fsanitize=``
flag.

For example if you compile/link your program as:

.. code-block:: console
Expand Down
8 changes: 4 additions & 4 deletions clang/docs/UsersManual.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1466,7 +1466,7 @@ are listed below.

**-f[no-]sanitize-recover=check1,check2,...**

**-f[no-]sanitize-recover=all**
**-f[no-]sanitize-recover[=all]**

Controls which checks enabled by ``-fsanitize=`` flag are non-fatal.
If the check is fatal, program will halt after the first error
Expand All @@ -1492,16 +1492,16 @@ are listed below.

**-f[no-]sanitize-trap=check1,check2,...**

**-f[no-]sanitize-trap[=all]**

Controls which checks enabled by the ``-fsanitize=`` flag trap. This
option is intended for use in cases where the sanitizer runtime cannot
be used (for instance, when building libc or a kernel module), or where
the binary size increase caused by the sanitizer runtime is a concern.

This flag is only compatible with :doc:`control flow integrity
<ControlFlowIntegrity>` schemes and :doc:`UndefinedBehaviorSanitizer`
checks other than ``vptr``. If this flag
is supplied together with ``-fsanitize=undefined``, the ``vptr`` sanitizer
will be implicitly disabled.
checks other than ``vptr``.

This flag is enabled by default for sanitizers in the ``cfi`` group.

Expand Down
27 changes: 24 additions & 3 deletions clang/include/clang/Basic/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,10 @@ class Module {
/// A module with the same name that shadows this module.
Module *ShadowingModule = nullptr;

/// Whether this module is missing a feature from \c Requirements.
unsigned IsMissingRequirement : 1;
/// Whether this module has declared itself unimportable, either because
/// it's missing a requirement from \p Requirements or because it's been
/// shadowed by another module.
unsigned IsUnimportable : 1;

/// Whether we tried and failed to load a module file for this module.
unsigned HasIncompatibleModuleFile : 1;
Expand Down Expand Up @@ -384,6 +386,25 @@ class Module {

~Module();

/// Determine whether this module has been declared unimportable.
bool isUnimportable() const { return IsUnimportable; }

/// Determine whether this module has been declared unimportable.
///
/// \param LangOpts The language options used for the current
/// translation unit.
///
/// \param Target The target options used for the current translation unit.
///
/// \param Req If this module is unimportable because of a missing
/// requirement, this parameter will be set to one of the requirements that
/// is not met for use of this module.
///
/// \param ShadowingModule If this module is unimportable because it is
/// shadowed, this parameter will be set to the shadowing module.
bool isUnimportable(const LangOptions &LangOpts, const TargetInfo &Target,
Requirement &Req, Module *&ShadowingModule) const;

/// Determine whether this module is available for use within the
/// current translation unit.
bool isAvailable() const { return IsAvailable; }
Expand Down Expand Up @@ -535,7 +556,7 @@ class Module {
const TargetInfo &Target);

/// Mark this module and all of its submodules as unavailable.
void markUnavailable(bool MissingRequirement = false);
void markUnavailable(bool Unimportable);

/// Find the submodule with the given name.
///
Expand Down
34 changes: 21 additions & 13 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -1102,27 +1102,35 @@ def fsanitize_hwaddress_abi_EQ
: Joined<["-"], "fsanitize-hwaddress-abi=">,
Group<f_clang_Group>,
HelpText<"Select the HWAddressSanitizer ABI to target (interceptor or platform, default interceptor). This option is currently unused.">;
def fsanitize_recover : Flag<["-"], "fsanitize-recover">, Group<f_clang_Group>;
def fno_sanitize_recover : Flag<["-"], "fno-sanitize-recover">,
Flags<[CoreOption, DriverOption]>,
Group<f_clang_Group>;
def fsanitize_recover_EQ : CommaJoined<["-"], "fsanitize-recover=">,
Group<f_clang_Group>,
HelpText<"Enable recovery for specified sanitizers">;
def fno_sanitize_recover_EQ
: CommaJoined<["-"], "fno-sanitize-recover=">,
Group<f_clang_Group>,
Flags<[CoreOption, DriverOption]>,
HelpText<"Disable recovery for specified sanitizers">;
def fno_sanitize_recover_EQ : CommaJoined<["-"], "fno-sanitize-recover=">,
Group<f_clang_Group>, Flags<[CoreOption, DriverOption]>,
HelpText<"Disable recovery for specified sanitizers">;
def fsanitize_recover : Flag<["-"], "fsanitize-recover">, Group<f_clang_Group>,
Alias<fsanitize_recover_EQ>, AliasArgs<["all"]>;
def fno_sanitize_recover : Flag<["-"], "fno-sanitize-recover">,
Flags<[CoreOption, DriverOption]>, Group<f_clang_Group>,
Alias<fno_sanitize_recover_EQ>, AliasArgs<["all"]>;
def fsanitize_trap_EQ : CommaJoined<["-"], "fsanitize-trap=">, Group<f_clang_Group>,
HelpText<"Enable trapping for specified sanitizers">;
def fno_sanitize_trap_EQ : CommaJoined<["-"], "fno-sanitize-trap=">, Group<f_clang_Group>,
Flags<[CoreOption, DriverOption]>,
HelpText<"Disable trapping for specified sanitizers">;
def fsanitize_undefined_trap_on_error : Flag<["-"], "fsanitize-undefined-trap-on-error">,
Group<f_clang_Group>;
def fno_sanitize_undefined_trap_on_error : Flag<["-"], "fno-sanitize-undefined-trap-on-error">,
Group<f_clang_Group>;
def fsanitize_trap : Flag<["-"], "fsanitize-trap">, Group<f_clang_Group>,
Alias<fsanitize_trap_EQ>, AliasArgs<["all"]>,
HelpText<"Enable trapping for all sanitizers">;
def fno_sanitize_trap : Flag<["-"], "fno-sanitize-trap">, Group<f_clang_Group>,
Alias<fno_sanitize_trap_EQ>, AliasArgs<["all"]>,
Flags<[CoreOption, DriverOption]>,
HelpText<"Disable trapping for all sanitizers">;
def fsanitize_undefined_trap_on_error
: Flag<["-"], "fsanitize-undefined-trap-on-error">, Group<f_clang_Group>,
Alias<fsanitize_trap_EQ>, AliasArgs<["undefined"]>;
def fno_sanitize_undefined_trap_on_error
: Flag<["-"], "fno-sanitize-undefined-trap-on-error">, Group<f_clang_Group>,
Alias<fno_sanitize_trap_EQ>, AliasArgs<["undefined"]>;
def fsanitize_minimal_runtime : Flag<["-"], "fsanitize-minimal-runtime">,
Group<f_clang_Group>;
def fno_sanitize_minimal_runtime : Flag<["-"], "fno-sanitize-minimal-runtime">,
Expand Down
66 changes: 39 additions & 27 deletions clang/lib/Basic/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ using namespace clang;
Module::Module(StringRef Name, SourceLocation DefinitionLoc, Module *Parent,
bool IsFramework, bool IsExplicit, unsigned VisibilityID)
: Name(Name), DefinitionLoc(DefinitionLoc), Parent(Parent),
VisibilityID(VisibilityID), IsMissingRequirement(false),
VisibilityID(VisibilityID), IsUnimportable(false),
HasIncompatibleModuleFile(false), IsAvailable(true),
IsFromModuleFile(false), IsFramework(IsFramework), IsExplicit(IsExplicit),
IsSystem(false), IsExternC(false), IsInferred(false),
Expand All @@ -46,17 +46,12 @@ Module::Module(StringRef Name, SourceLocation DefinitionLoc, Module *Parent,
NoUndeclaredIncludes(false), ModuleMapIsPrivate(false),
HasUmbrellaDir(false), NameVisibility(Hidden) {
if (Parent) {
if (!Parent->isAvailable())
IsAvailable = false;
if (Parent->IsSystem)
IsSystem = true;
if (Parent->IsExternC)
IsExternC = true;
if (Parent->NoUndeclaredIncludes)
NoUndeclaredIncludes = true;
if (Parent->ModuleMapIsPrivate)
ModuleMapIsPrivate = true;
IsMissingRequirement = Parent->IsMissingRequirement;
IsAvailable = Parent->isAvailable();
IsUnimportable = Parent->isUnimportable();
IsSystem = Parent->IsSystem;
IsExternC = Parent->IsExternC;
NoUndeclaredIncludes = Parent->NoUndeclaredIncludes;
ModuleMapIsPrivate = Parent->ModuleMapIsPrivate;

Parent->SubModuleIndex[Name] = Parent->SubModules.size();
Parent->SubModules.push_back(this);
Expand Down Expand Up @@ -132,25 +127,42 @@ static bool hasFeature(StringRef Feature, const LangOptions &LangOpts,
return HasFeature;
}

bool Module::isAvailable(const LangOptions &LangOpts, const TargetInfo &Target,
Requirement &Req,
UnresolvedHeaderDirective &MissingHeader,
Module *&ShadowingModule) const {
if (IsAvailable)
return true;
bool Module::isUnimportable(const LangOptions &LangOpts,
const TargetInfo &Target, Requirement &Req,
Module *&ShadowingModule) const {
if (!IsUnimportable)
return false;

for (const Module *Current = this; Current; Current = Current->Parent) {
if (Current->ShadowingModule) {
ShadowingModule = Current->ShadowingModule;
return false;
return true;
}
for (unsigned I = 0, N = Current->Requirements.size(); I != N; ++I) {
if (hasFeature(Current->Requirements[I].first, LangOpts, Target) !=
Current->Requirements[I].second) {
Req = Current->Requirements[I];
return false;
return true;
}
}
}

llvm_unreachable("could not find a reason why module is unimportable");
}

bool Module::isAvailable(const LangOptions &LangOpts, const TargetInfo &Target,
Requirement &Req,
UnresolvedHeaderDirective &MissingHeader,
Module *&ShadowingModule) const {
if (IsAvailable)
return true;

if (isUnimportable(LangOpts, Target, Req, ShadowingModule))
return false;

// FIXME: All missing headers are listed on the top-level module. Should we
// just look there?
for (const Module *Current = this; Current; Current = Current->Parent) {
if (!Current->MissingHeaders.empty()) {
MissingHeader = Current->MissingHeaders.front();
return false;
Expand Down Expand Up @@ -287,12 +299,12 @@ void Module::addRequirement(StringRef Feature, bool RequiredState,
if (hasFeature(Feature, LangOpts, Target) == RequiredState)
return;

markUnavailable(/*MissingRequirement*/true);
markUnavailable(/*Unimportable*/true);
}

void Module::markUnavailable(bool MissingRequirement) {
auto needUpdate = [MissingRequirement](Module *M) {
return M->IsAvailable || (!M->IsMissingRequirement && MissingRequirement);
void Module::markUnavailable(bool Unimportable) {
auto needUpdate = [Unimportable](Module *M) {
return M->IsAvailable || (!M->IsUnimportable && Unimportable);
};

if (!needUpdate(this))
Expand All @@ -308,7 +320,7 @@ void Module::markUnavailable(bool MissingRequirement) {
continue;

Current->IsAvailable = false;
Current->IsMissingRequirement |= MissingRequirement;
Current->IsUnimportable |= Unimportable;
for (submodule_iterator Sub = Current->submodule_begin(),
SubEnd = Current->submodule_end();
Sub != SubEnd; ++Sub) {
Expand Down Expand Up @@ -642,8 +654,8 @@ void VisibleModuleSet::setVisible(Module *M, SourceLocation Loc,
SmallVector<Module *, 16> Exports;
V.M->getExportedModules(Exports);
for (Module *E : Exports) {
// Don't recurse to unavailable submodules.
if (E->isAvailable())
// Don't import non-importable modules.
if (!E->isUnimportable())
VisitModule({E, &V});
}

Expand Down
29 changes: 1 addition & 28 deletions clang/lib/Driver/SanitizerArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ static const SanitizerMask Unrecoverable =
SanitizerKind::Unreachable | SanitizerKind::Return;
static const SanitizerMask AlwaysRecoverable =
SanitizerKind::KernelAddress | SanitizerKind::KernelHWAddress;
static const SanitizerMask LegacyFsanitizeRecoverMask =
SanitizerKind::Undefined | SanitizerKind::Integer;
static const SanitizerMask NeedsLTO = SanitizerKind::CFI;
static const SanitizerMask TrappingSupported =
(SanitizerKind::Undefined & ~SanitizerKind::Vptr) |
Expand Down Expand Up @@ -221,16 +219,6 @@ static SanitizerMask parseSanitizeTrapArgs(const Driver &D,
} else if (Arg->getOption().matches(options::OPT_fno_sanitize_trap_EQ)) {
Arg->claim();
TrapRemove |= expandSanitizerGroups(parseArgValues(D, Arg, true));
} else if (Arg->getOption().matches(
options::OPT_fsanitize_undefined_trap_on_error)) {
Arg->claim();
TrappingKinds |=
expandSanitizerGroups(SanitizerKind::UndefinedGroup & ~TrapRemove) &
~TrapRemove;
} else if (Arg->getOption().matches(
options::OPT_fno_sanitize_undefined_trap_on_error)) {
Arg->claim();
TrapRemove |= expandSanitizerGroups(SanitizerKind::UndefinedGroup);
}
}

Expand Down Expand Up @@ -541,18 +529,7 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
SanitizerMask DiagnosedUnrecoverableKinds;
SanitizerMask DiagnosedAlwaysRecoverableKinds;
for (const auto *Arg : Args) {
const char *DeprecatedReplacement = nullptr;
if (Arg->getOption().matches(options::OPT_fsanitize_recover)) {
DeprecatedReplacement =
"-fsanitize-recover=undefined,integer' or '-fsanitize-recover=all";
RecoverableKinds |= expandSanitizerGroups(LegacyFsanitizeRecoverMask);
Arg->claim();
} else if (Arg->getOption().matches(options::OPT_fno_sanitize_recover)) {
DeprecatedReplacement = "-fno-sanitize-recover=undefined,integer' or "
"'-fno-sanitize-recover=all";
RecoverableKinds &= ~expandSanitizerGroups(LegacyFsanitizeRecoverMask);
Arg->claim();
} else if (Arg->getOption().matches(options::OPT_fsanitize_recover_EQ)) {
if (Arg->getOption().matches(options::OPT_fsanitize_recover_EQ)) {
SanitizerMask Add = parseArgValues(D, Arg, true);
// Report error if user explicitly tries to recover from unrecoverable
// sanitizer.
Expand Down Expand Up @@ -581,10 +558,6 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
RecoverableKinds &= ~expandSanitizerGroups(Remove);
Arg->claim();
}
if (DeprecatedReplacement) {
D.Diag(diag::warn_drv_deprecated_arg) << Arg->getAsString(Args)
<< DeprecatedReplacement;
}
}
RecoverableKinds &= Kinds;
RecoverableKinds &= ~Unrecoverable;
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Frontend/CompilerInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1576,7 +1576,7 @@ bool CompilerInstance::loadModuleFile(StringRef FileName) {
Stack.push_back(M);
while (!Stack.empty()) {
Module *Current = Stack.pop_back_val();
if (Current->IsMissingRequirement) continue;
if (Current->IsUnimportable) continue;
Current->IsAvailable = true;
Stack.insert(Stack.end(),
Current->submodule_begin(), Current->submodule_end());
Expand Down
11 changes: 7 additions & 4 deletions clang/lib/Lex/ModuleMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ void ModuleMap::resolveHeader(Module *Mod,
// resolved. (Such a module still can't be built though, except from
// preprocessed source.)
if (!Header.Size && !Header.ModTime)
Mod->markUnavailable();
Mod->markUnavailable(/*Unimportable=*/false);
}
}

Expand Down Expand Up @@ -544,6 +544,9 @@ void ModuleMap::diagnoseHeaderInclusion(Module *RequestingModule,
static bool isBetterKnownHeader(const ModuleMap::KnownHeader &New,
const ModuleMap::KnownHeader &Old) {
// Prefer available modules.
// FIXME: Considering whether the module is available rather than merely
// importable is non-hermetic and can result in surprising behavior for
// prebuilt modules. Consider only checking for importability here.
if (New.getModule()->isAvailable() && !Old.getModule()->isAvailable())
return true;

Expand Down Expand Up @@ -1094,7 +1097,7 @@ Module *ModuleMap::createShadowedModule(StringRef Name, bool IsFramework,
new Module(Name, SourceLocation(), /*Parent=*/nullptr, IsFramework,
/*IsExplicit=*/false, NumCreatedModules++);
Result->ShadowingModule = ShadowingModule;
Result->IsAvailable = false;
Result->markUnavailable(/*Unimportable*/true);
ModuleScopeIDs[Result] = CurrentModuleScopeID;
ShadowModules.push_back(Result);

Expand Down Expand Up @@ -2096,9 +2099,9 @@ void ModuleMapParser::parseModuleDecl() {

// If the module meets all requirements but is still unavailable, mark the
// whole tree as unavailable to prevent it from building.
if (!ActiveModule->IsAvailable && !ActiveModule->IsMissingRequirement &&
if (!ActiveModule->IsAvailable && !ActiveModule->IsUnimportable &&
ActiveModule->Parent) {
ActiveModule->getTopLevelModule()->markUnavailable();
ActiveModule->getTopLevelModule()->markUnavailable(/*Unimportable=*/false);
ActiveModule->getTopLevelModule()->MissingHeaders.append(
ActiveModule->MissingHeaders.begin(), ActiveModule->MissingHeaders.end());
}
Expand Down
Loading

0 comments on commit dd3a824

Please sign in to comment.