Skip to content

Commit

Permalink
Merged main:ddf1de20a3f7 into amd-gfx:756ea0fac61f
Browse files Browse the repository at this point in the history
Local branch amd-gfx 756ea0f Merged main:b0b8e83e668a into amd-gfx:b9f9dea74514
Remote branch main ddf1de2 [hwasan] Fix rare false negative (zero tag) in stack-uar.c (llvm#69374)
  • Loading branch information
SC llvm team authored and SC llvm team committed Oct 18, 2023
2 parents 756ea0f + ddf1de2 commit b4f6afc
Show file tree
Hide file tree
Showing 100 changed files with 1,743 additions and 464 deletions.
2 changes: 1 addition & 1 deletion clang-tools-extra/docs/clang-tidy/checks/list.rst
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ Clang-Tidy Checks
:doc:`llvmlibc-restrict-system-libc-headers <llvmlibc/restrict-system-libc-headers>`, "Yes"
:doc:`misc-confusable-identifiers <misc/confusable-identifiers>`,
:doc:`misc-const-correctness <misc/const-correctness>`, "Yes"
:doc:`misc-coroutine-hostile-raii <misc/coroutine-hostile-raii.html>`_,
:doc:`misc-coroutine-hostile-raii <misc/coroutine-hostile-raii>`,
:doc:`misc-definitions-in-headers <misc/definitions-in-headers>`, "Yes"
:doc:`misc-header-include-cycle <misc/header-include-cycle>`,
:doc:`misc-include-cleaner <misc/include-cleaner>`, "Yes"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
.. title:: clang-tidy - misc-coroutine-hostile-raii

misc-coroutine-hostile-raii
====================
===========================

Detects when objects of certain hostile RAII types persists across suspension
points in a coroutine. Such hostile types include scoped-lockable types and
types belonging to a configurable denylist.

Some objects require that they be destroyed on the same thread that created them.
Some objects require that they be destroyed on the same thread that created them.
Traditionally this requirement was often phrased as "must be a local variable",
under the assumption that local variables always work this way. However this is
incorrect with C++20 coroutines, since an intervening ``co_await`` may cause the
coroutine to suspend and later be resumed on another thread.

The lifetime of an object that requires being destroyed on the same thread must
The lifetime of an object that requires being destroyed on the same thread must
not encompass a ``co_await`` or ``co_yield`` point. If you create/destroy an object,
you must do so without allowing the coroutine to suspend in the meantime.

Following types are considered as hostile:

- Scoped-lockable types: A scoped-lockable object persisting across a suspension
point is problematic as the lock held by this object could be unlocked by a
different thread. This would be undefined behaviour.
This includes all types annotated with the ``scoped_lockable`` attribute.
point is problematic as the lock held by this object could be unlocked by a
different thread. This would be undefined behaviour.
This includes all types annotated with the ``scoped_lockable`` attribute.

- Types belonging to a configurable denylist.

Expand All @@ -44,7 +44,7 @@ Options

.. option:: RAIITypesList

A semicolon-separated list of qualified types which should not be allowed to
A semicolon-separated list of qualified types which should not be allowed to
persist across suspension points.
Eg: ``my::lockable; a::b;::my::other::lockable;``
The default value of this option is `"std::lock_guard;std::scoped_lock"`.
The default value of this option is `"std::lock_guard;std::scoped_lock"`.
9 changes: 7 additions & 2 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ C++ Language Changes

C++20 Feature Support
^^^^^^^^^^^^^^^^^^^^^
- Fix a bug in conversion sequence of arguments to a function with reversed parameter order.
Fixes `GH <https://github.com/llvm/llvm-project/issues/53954>`_.

C++23 Feature Support
^^^^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -199,6 +197,9 @@ New Compiler Flags
the preprocessed text to the output. This can greatly reduce the size of the
preprocessed output, which can be helpful when trying to reduce a test case.

* ``-Wbitfield-conversion`` was added to detect assignments of integral
types to a bitfield that may change the value.

Deprecated Compiler Flags
-------------------------

Expand Down Expand Up @@ -522,6 +523,10 @@ Bug Fixes to C++ Support
with non-type template parameters of reference type. Fixes:
(`#65153 <https://github.com/llvm/llvm-project/issues/65153>`_)

- Clang now properly compares constraints on an out of line class template
declaration definition. Fixes:
(`#61763 <https://github.com/llvm/llvm-project/issues/61763>`_)

Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
- Fixed an import failure of recursive friend class template.
Expand Down
7 changes: 7 additions & 0 deletions clang/include/clang/AST/Expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,13 @@ class Expr : public ValueStmt {
/// foldable. If the expression is foldable, but not a constant expression,
/// the notes will describes why it isn't a constant expression. If the
/// expression *is* a constant expression, no notes will be produced.
///
/// FIXME: this causes significant performance concerns and should be
/// refactored at some point. Not all evaluations of the constant
/// expression interpreter will display the given diagnostics, this means
/// those kinds of uses are paying the expense of generating a diagnostic
/// (which may include expensive operations like converting APValue objects
/// to a string representation).
SmallVectorImpl<PartialDiagnosticAt> *Diag = nullptr;

EvalStatus() = default;
Expand Down
2 changes: 2 additions & 0 deletions clang/include/clang/Basic/DiagnosticGroups.td
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def SingleBitBitFieldConstantConversion :
def BitFieldConstantConversion : DiagGroup<"bitfield-constant-conversion",
[SingleBitBitFieldConstantConversion]>;
def BitFieldEnumConversion : DiagGroup<"bitfield-enum-conversion">;
def BitFieldConversion : DiagGroup<"bitfield-conversion">;
def BitFieldWidth : DiagGroup<"bitfield-width">;
def CompoundTokenSplitByMacro : DiagGroup<"compound-token-split-by-macro">;
def CompoundTokenSplitBySpace : DiagGroup<"compound-token-split-by-space">;
Expand Down Expand Up @@ -933,6 +934,7 @@ def Conversion : DiagGroup<"conversion",
ConstantConversion,
EnumConversion,
BitFieldEnumConversion,
BitFieldConversion,
FloatConversion,
Shorten64To32,
IntConversion,
Expand Down
3 changes: 3 additions & 0 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -6171,6 +6171,9 @@ def warn_signed_bitfield_enum_conversion : Warning<
"signed bit-field %0 needs an extra bit to represent the largest positive "
"enumerators of %1">,
InGroup<BitFieldEnumConversion>, DefaultIgnore;
def warn_bitfield_too_small_for_integral_type : Warning<
"conversion from %2 (%3 bits) to bit-field %0 (%1 bits) may change value">,
InGroup<BitFieldConversion>, DefaultIgnore;
def note_change_bitfield_sign : Note<
"consider making the bitfield type %select{unsigned|signed}0">;

Expand Down
11 changes: 11 additions & 0 deletions clang/include/clang/Basic/arm_sve.td
Original file line number Diff line number Diff line change
Expand Up @@ -1865,10 +1865,21 @@ def SVPTRUE_COUNT : SInst<"svptrue_{d}", "}v", "QcQsQiQl", MergeNone, "aarch64_

def SVPEXT_SINGLE : SInst<"svpext_lane_{d}", "P}i", "QcQsQiQl", MergeNone, "aarch64_sve_pext", [], [ImmCheck<1, ImmCheck0_3>]>;
def SVPEXT_X2 : SInst<"svpext_lane_{d}_x2", "2.P}i", "QcQsQiQl", MergeNone, "aarch64_sve_pext_x2", [], [ImmCheck<1, ImmCheck0_1>]>;

def SVPSEL_COUNT_ALIAS_B : SInst<"svpsel_lane_c8", "}}Pm", "Pc", MergeNone, "", [], []>;
def SVPSEL_COUNT_ALIAS_H : SInst<"svpsel_lane_c16", "}}Pm", "Ps", MergeNone, "", [], []>;
def SVPSEL_COUNT_ALIAS_S : SInst<"svpsel_lane_c32", "}}Pm", "Pi", MergeNone, "", [], []>;
def SVPSEL_COUNT_ALIAS_D : SInst<"svpsel_lane_c64", "}}Pm", "Pl", MergeNone, "", [], []>;
}

let TargetGuard = "sve2p1" in {
def SVSCLAMP : SInst<"svclamp[_{d}]", "dddd", "csil", MergeNone, "aarch64_sve_sclamp", [], []>;
def SVUCLAMP : SInst<"svclamp[_{d}]", "dddd", "UcUsUiUl", MergeNone, "aarch64_sve_uclamp", [], []>;

def SVPSEL_B : SInst<"svpsel_lane_b8", "PPPm", "Pc", MergeNone, "", [], []>;
def SVPSEL_H : SInst<"svpsel_lane_b16", "PPPm", "Ps", MergeNone, "", [], []>;
def SVPSEL_S : SInst<"svpsel_lane_b32", "PPPm", "Pi", MergeNone, "", [], []>;
def SVPSEL_D : SInst<"svpsel_lane_b64", "PPPm", "Pl", MergeNone, "", [], []>;

def SVCNTP_COUNT : SInst<"svcntp_{d}", "n}i", "QcQsQiQl", MergeNone, "aarch64_sve_cntp_{d}", [IsOverloadNone], [ImmCheck<1, ImmCheck2_4_Mul2>]>;
}
77 changes: 58 additions & 19 deletions clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -3809,17 +3809,6 @@ class Sema final {
// the purposes of [temp.friend] p9.
bool FriendConstraintsDependOnEnclosingTemplate(const FunctionDecl *FD);

// Calculates whether two constraint expressions are equal irrespective of a
// difference in 'depth'. This takes a pair of optional 'NamedDecl's 'Old' and
// 'New', which are the "source" of the constraint, since this is necessary
// for figuring out the relative 'depth' of the constraint. The depth of the
// 'primary template' and the 'instantiated from' templates aren't necessarily
// the same, such as a case when one is a 'friend' defined in a class.
bool AreConstraintExpressionsEqual(const NamedDecl *Old,
const Expr *OldConstr,
const NamedDecl *New,
const Expr *NewConstr);

enum class AllowedExplicit {
/// Allow no explicit functions to be used.
None,
Expand Down Expand Up @@ -8615,8 +8604,48 @@ class Sema final {
TPL_TemplateParamsEquivalent,
};

// A struct to represent the 'new' declaration, which is either itself just
// the named decl, or the important information we need about it in order to
// do constraint comparisons.
class TemplateCompareNewDeclInfo {
const NamedDecl *ND = nullptr;
const DeclContext *DC = nullptr;
const DeclContext *LexicalDC = nullptr;
SourceLocation Loc;

public:
TemplateCompareNewDeclInfo(const NamedDecl *ND) : ND(ND) {}
TemplateCompareNewDeclInfo(const DeclContext *DeclCtx,
const DeclContext *LexicalDeclCtx,
SourceLocation Loc)

: DC(DeclCtx), LexicalDC(LexicalDeclCtx), Loc(Loc) {
assert(DC && LexicalDC &&
"Constructor only for cases where we have the information to put "
"in here");
}

// If this was constructed with no information, we cannot do substitution
// for constraint comparison, so make sure we can check that.
bool isInvalid() const { return !ND && !DC; }

const NamedDecl *getDecl() const { return ND; }

bool ContainsDecl(const NamedDecl *ND) const { return this->ND == ND; }

const DeclContext *getLexicalDeclContext() const {
return ND ? ND->getLexicalDeclContext() : LexicalDC;
}

const DeclContext *getDeclContext() const {
return ND ? ND->getDeclContext() : DC;
}

SourceLocation getLocation() const { return ND ? ND->getLocation() : Loc; }
};

bool TemplateParameterListsAreEqual(
const NamedDecl *NewInstFrom, TemplateParameterList *New,
const TemplateCompareNewDeclInfo &NewInstFrom, TemplateParameterList *New,
const NamedDecl *OldInstFrom, TemplateParameterList *Old, bool Complain,
TemplateParameterListEqualKind Kind,
SourceLocation TemplateArgLoc = SourceLocation());
Expand All @@ -8629,6 +8658,17 @@ class Sema final {
Kind, TemplateArgLoc);
}

// Calculates whether two constraint expressions are equal irrespective of a
// difference in 'depth'. This takes a pair of optional 'NamedDecl's 'Old' and
// 'New', which are the "source" of the constraint, since this is necessary
// for figuring out the relative 'depth' of the constraint. The depth of the
// 'primary template' and the 'instantiated from' templates aren't necessarily
// the same, such as a case when one is a 'friend' defined in a class.
bool AreConstraintExpressionsEqual(const NamedDecl *Old,
const Expr *OldConstr,
const TemplateCompareNewDeclInfo &New,
const Expr *NewConstr);

bool CheckTemplateDeclScope(Scope *S, TemplateParameterList *TemplateParams);

/// Called when the parser has parsed a C++ typename
Expand Down Expand Up @@ -9368,13 +9408,12 @@ class Sema final {
// C++ Template Instantiation
//

MultiLevelTemplateArgumentList
getTemplateInstantiationArgs(const NamedDecl *D, bool Final = false,
const TemplateArgumentList *Innermost = nullptr,
bool RelativeToPrimary = false,
const FunctionDecl *Pattern = nullptr,
bool ForConstraintInstantiation = false,
bool SkipForSpecialization = false);
MultiLevelTemplateArgumentList getTemplateInstantiationArgs(
const NamedDecl *D, const DeclContext *DC = nullptr, bool Final = false,
const TemplateArgumentList *Innermost = nullptr,
bool RelativeToPrimary = false, const FunctionDecl *Pattern = nullptr,
bool ForConstraintInstantiation = false,
bool SkipForSpecialization = false);

/// A context in which code is being synthesized (where a source location
/// alone is not sufficient to identify the context). This covers template
Expand Down
4 changes: 3 additions & 1 deletion clang/include/clang/Sema/Template.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,9 @@ enum class TemplateSubstitutionKind : char {
"substituted args outside retained args?");
assert(getKind() == TemplateSubstitutionKind::Specialization);
TemplateArgumentLists.push_back(
{{AssociatedDecl->getCanonicalDecl(), Final}, Args});
{{AssociatedDecl ? AssociatedDecl->getCanonicalDecl() : nullptr,
Final},
Args});
}

void addOuterTemplateArguments(ArgList Args) {
Expand Down
28 changes: 27 additions & 1 deletion clang/lib/CodeGen/CGBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10007,7 +10007,33 @@ Value *CodeGenFunction::EmitAArch64SVEBuiltinExpr(unsigned BuiltinID,
switch (BuiltinID) {
default:
return nullptr;

case SVE::BI__builtin_sve_svpsel_lane_b8:
case SVE::BI__builtin_sve_svpsel_lane_b16:
case SVE::BI__builtin_sve_svpsel_lane_b32:
case SVE::BI__builtin_sve_svpsel_lane_b64:
case SVE::BI__builtin_sve_svpsel_lane_c8:
case SVE::BI__builtin_sve_svpsel_lane_c16:
case SVE::BI__builtin_sve_svpsel_lane_c32:
case SVE::BI__builtin_sve_svpsel_lane_c64: {
bool IsSVCount = isa<TargetExtType>(Ops[0]->getType());
assert(((!IsSVCount || cast<TargetExtType>(Ops[0]->getType())->getName() ==
"aarch64.svcount")) &&
"Unexpected TargetExtType");
auto SVCountTy =
llvm::TargetExtType::get(getLLVMContext(), "aarch64.svcount");
Function *CastFromSVCountF =
CGM.getIntrinsic(Intrinsic::aarch64_sve_convert_to_svbool, SVCountTy);
Function *CastToSVCountF =
CGM.getIntrinsic(Intrinsic::aarch64_sve_convert_from_svbool, SVCountTy);

auto OverloadedTy = getSVEType(SVETypeFlags(Builtin->TypeModifier));
Function *F = CGM.getIntrinsic(Intrinsic::aarch64_sve_psel, OverloadedTy);
llvm::Value *Ops0 =
IsSVCount ? Builder.CreateCall(CastFromSVCountF, Ops[0]) : Ops[0];
llvm::Value *Ops1 = EmitSVEPredicateCast(Ops[1], OverloadedTy);
llvm::Value *PSel = Builder.CreateCall(F, {Ops0, Ops1, Ops[2]});
return IsSVCount ? Builder.CreateCall(CastToSVCountF, PSel) : PSel;
}
case SVE::BI__builtin_sve_svmov_b_z: {
// svmov_b_z(pg, op) <=> svand_b_z(pg, op, op)
SVETypeFlags TypeFlags(Builtin->TypeModifier);
Expand Down
8 changes: 8 additions & 0 deletions clang/lib/Driver/ToolChains/Solaris.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,14 @@ void solaris::Linker::ConstructJob(Compilation &C, const JobAction &JA,
getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
CmdArgs.push_back("-lm");
}
// Additional linker set-up and flags for Fortran. This is required in order
// to generate executables. As Fortran runtime depends on the C runtime,
// these dependencies need to be listed before the C runtime below.
if (D.IsFlangMode()) {
addFortranRuntimeLibraryPath(getToolChain(), Args, CmdArgs);
addFortranRuntimeLibs(getToolChain(), CmdArgs);
CmdArgs.push_back("-lm");
}
if (Args.hasArg(options::OPT_fstack_protector) ||
Args.hasArg(options::OPT_fstack_protector_strong) ||
Args.hasArg(options::OPT_fstack_protector_all)) {
Expand Down
13 changes: 12 additions & 1 deletion clang/lib/Sema/SemaChecking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14331,6 +14331,18 @@ static bool AnalyzeBitFieldAssignment(Sema &S, FieldDecl *Bitfield, Expr *Init,
S.Diag(WidthExpr->getExprLoc(), diag::note_widen_bitfield)
<< BitsNeeded << ED << WidthExpr->getSourceRange();
}
} else if (OriginalInit->getType()->isIntegralType(S.Context)) {
IntRange LikelySourceRange =
GetExprRange(S.Context, Init, S.isConstantEvaluatedContext(),
/*Approximate=*/true);

if (LikelySourceRange.Width > FieldWidth) {
Expr *WidthExpr = Bitfield->getBitWidth();
S.Diag(InitLoc, diag::warn_bitfield_too_small_for_integral_type)
<< Bitfield << FieldWidth << OriginalInit->getType()
<< LikelySourceRange.Width;
S.Diag(WidthExpr->getExprLoc(), diag::note_declared_at);
}
}

return false;
Expand Down Expand Up @@ -15228,7 +15240,6 @@ static void CheckImplicitConversion(Sema &S, Expr *E, QualType T,

if (LikelySourceRange.Width > TargetRange.Width) {
// If the source is a constant, use a default-on diagnostic.
// TODO: this should happen for bitfield stores, too.
Expr::EvalResult Result;
if (E->EvaluateAsInt(Result, S.Context, Expr::SE_AllowSideEffects,
S.isConstantEvaluatedContext())) {
Expand Down
Loading

0 comments on commit b4f6afc

Please sign in to comment.