Skip to content

Commit

Permalink
merge main into amd-staging
Browse files Browse the repository at this point in the history
Change-Id: I3c00ba688bfc2b837908732bf322d7849cddbebc
  • Loading branch information
ronlieb committed Nov 25, 2024
2 parents 4a96fd8 + ceaf6e9 commit 76c5481
Show file tree
Hide file tree
Showing 112 changed files with 3,308 additions and 1,532 deletions.
2 changes: 1 addition & 1 deletion clang/docs/ClangFormat.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ to format C/C++/Java/JavaScript/JSON/Objective-C/Protobuf/C# code.
Clang-format options:
--Werror - If set, changes formatting warnings to errors
--Wno-error=<value> - If set don't error out on the specified warning type.
--Wno-error=<value> - If set, don't error out on the specified warning type.
=unknown - If set, unknown format options are only warned about.
This can be used to enable formatting, even if the
configuration contains unknown (newer) options.
Expand Down
2 changes: 1 addition & 1 deletion clang/docs/OpenMPSupport.rst
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ implementation.
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
| memory management | changes to omp_alloctrait_key enum | :none:`unclaimed` | |
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
| memory model | seq_cst clause on flush construct | :none:`unclaimed` | |
| memory model | seq_cst clause on flush construct | :good:`done` | https://github.com/llvm/llvm-project/pull/114072 |
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
| misc | 'omp_all_memory' keyword and use in 'depend' clause | :good:`done` | D125828, D126321 |
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
Expand Down
3 changes: 3 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,8 @@ Attribute Changes in Clang
- Clang now supports ``[[clang::lifetime_capture_by(X)]]``. Similar to lifetimebound, this can be
used to specify when a reference to a function parameter is captured by another capturing entity ``X``.

- The ``target_version`` attribute is now only supported for AArch64 and RISC-V architectures.

Improvements to Clang's diagnostics
-----------------------------------

Expand Down Expand Up @@ -746,6 +748,7 @@ Bug Fixes to C++ Support
assumption if they also occur inside of a dependent lambda. (#GH114787)
- Clang now uses valid deduced type locations when diagnosing functions with trailing return type
missing placeholder return type. (#GH78694)
- Fixed a bug where bounds of partially expanded pack indexing expressions were checked too early. (#GH116105)

Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
14 changes: 9 additions & 5 deletions clang/include/clang/AST/ExprCXX.h
Original file line number Diff line number Diff line change
Expand Up @@ -4390,17 +4390,17 @@ class PackIndexingExpr final
unsigned TransformedExpressions : 31;

LLVM_PREFERRED_TYPE(bool)
unsigned ExpandedToEmptyPack : 1;
unsigned FullySubstituted : 1;

PackIndexingExpr(QualType Type, SourceLocation EllipsisLoc,
SourceLocation RSquareLoc, Expr *PackIdExpr, Expr *IndexExpr,
ArrayRef<Expr *> SubstitutedExprs = {},
bool ExpandedToEmptyPack = false)
bool FullySubstituted = false)
: Expr(PackIndexingExprClass, Type, VK_LValue, OK_Ordinary),
EllipsisLoc(EllipsisLoc), RSquareLoc(RSquareLoc),
SubExprs{PackIdExpr, IndexExpr},
TransformedExpressions(SubstitutedExprs.size()),
ExpandedToEmptyPack(ExpandedToEmptyPack) {
FullySubstituted(FullySubstituted) {

auto *Exprs = getTrailingObjects<Expr *>();
std::uninitialized_copy(SubstitutedExprs.begin(), SubstitutedExprs.end(),
Expand All @@ -4424,12 +4424,16 @@ class PackIndexingExpr final
SourceLocation RSquareLoc, Expr *PackIdExpr,
Expr *IndexExpr, std::optional<int64_t> Index,
ArrayRef<Expr *> SubstitutedExprs = {},
bool ExpandedToEmptyPack = false);
bool FullySubstituted = false);
static PackIndexingExpr *CreateDeserialized(ASTContext &Context,
unsigned NumTransformedExprs);

bool isFullySubstituted() const { return FullySubstituted; }

/// Determine if the expression was expanded to empty.
bool expandsToEmptyPack() const { return ExpandedToEmptyPack; }
bool expandsToEmptyPack() const {
return isFullySubstituted() && TransformedExpressions == 0;
}

/// Determine the location of the 'sizeof' keyword.
SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
Expand Down
4 changes: 2 additions & 2 deletions clang/include/clang/AST/OpenMPClause.h
Original file line number Diff line number Diff line change
Expand Up @@ -2670,8 +2670,8 @@ class OMPCompareClause final : public OMPClause {
}
};

/// This represents 'seq_cst' clause in the '#pragma omp atomic'
/// directive.
/// This represents 'seq_cst' clause in the '#pragma omp atomic|flush'
/// directives.
///
/// \code
/// #pragma omp atomic seq_cst
Expand Down
12 changes: 7 additions & 5 deletions clang/include/clang/AST/Type.h
Original file line number Diff line number Diff line change
Expand Up @@ -5922,12 +5922,12 @@ class PackIndexingType final
unsigned Size : 31;

LLVM_PREFERRED_TYPE(bool)
unsigned ExpandsToEmptyPack : 1;
unsigned FullySubstituted : 1;

protected:
friend class ASTContext; // ASTContext creates these.
PackIndexingType(const ASTContext &Context, QualType Canonical,
QualType Pattern, Expr *IndexExpr, bool ExpandsToEmptyPack,
QualType Pattern, Expr *IndexExpr, bool FullySubstituted,
ArrayRef<QualType> Expansions = {});

public:
Expand All @@ -5951,7 +5951,9 @@ class PackIndexingType final

bool hasSelectedType() const { return getSelectedIndex() != std::nullopt; }

bool expandsToEmptyPack() const { return ExpandsToEmptyPack; }
bool isFullySubstituted() const { return FullySubstituted; }

bool expandsToEmptyPack() const { return isFullySubstituted() && Size == 0; }

ArrayRef<QualType> getExpansions() const {
return {getExpansionsPtr(), Size};
Expand All @@ -5965,10 +5967,10 @@ class PackIndexingType final
if (hasSelectedType())
getSelectedType().Profile(ID);
else
Profile(ID, Context, getPattern(), getIndexExpr(), expandsToEmptyPack());
Profile(ID, Context, getPattern(), getIndexExpr(), isFullySubstituted());
}
static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
QualType Pattern, Expr *E, bool ExpandsToEmptyPack);
QualType Pattern, Expr *E, bool FullySubstituted);

private:
const QualType *getExpansionsPtr() const {
Expand Down
6 changes: 3 additions & 3 deletions clang/include/clang/AST/TypeProperties.td
Original file line number Diff line number Diff line change
Expand Up @@ -473,12 +473,12 @@ let Class = PackIndexingType in {
def : Property<"indexExpression", ExprRef> {
let Read = [{ node->getIndexExpr() }];
}
def : Property<"expandsToEmptyPack", Bool> {
let Read = [{ node->expandsToEmptyPack() }];
def : Property<"isFullySubstituted", Bool> {
let Read = [{ node->isFullySubstituted() }];
}

def : Creator<[{
return ctx.getPackIndexingType(pattern, indexExpression, expandsToEmptyPack);
return ctx.getPackIndexingType(pattern, indexExpression, isFullySubstituted);
}]>;
}

Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/Attr.td
Original file line number Diff line number Diff line change
Expand Up @@ -3297,7 +3297,7 @@ def Target : InheritableAttr {
}];
}

def TargetVersion : InheritableAttr {
def TargetVersion : InheritableAttr, TargetSpecificAttr<TargetArch<!listconcat(TargetAArch64.Arches, TargetRISCV.Arches)>> {
let Spellings = [GCC<"target_version">];
let Args = [StringArgument<"NamesStr">];
let Subjects = SubjectList<[Function], ErrorDiag>;
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -11399,7 +11399,7 @@ def err_omp_atomic_weak_no_equality : Error<"expected '==' operator for 'weak' c
def err_omp_atomic_several_clauses : Error<
"directive '#pragma omp atomic' cannot contain more than one 'read', 'write', 'update', 'capture', or 'compare' clause">;
def err_omp_several_mem_order_clauses : Error<
"directive '#pragma omp %0' cannot contain more than one %select{'seq_cst', 'relaxed', |}1'acq_rel', 'acquire' or 'release' clause">;
"directive '#pragma omp %0' cannot contain more than one 'seq_cst',%select{ 'relaxed',|}1 'acq_rel', 'acquire' or 'release' clause">;
def err_omp_atomic_incompatible_mem_order_clause : Error<
"directive '#pragma omp atomic%select{ %0|}1' cannot be used with '%2' clause">;
def note_omp_previous_mem_order_clause : Note<
Expand Down
9 changes: 4 additions & 5 deletions clang/include/clang/Format/Format.h
Original file line number Diff line number Diff line change
Expand Up @@ -4970,12 +4970,11 @@ struct FormatStyle {
/// \version 12
std::vector<std::string> StatementAttributeLikeMacros;

/// A vector of macros that should be interpreted as complete
/// statements.
/// A vector of macros that should be interpreted as complete statements.
///
/// Typical macros are expressions, and require a semi-colon to be
/// added; sometimes this is not the case, and this allows to make
/// clang-format aware of such cases.
/// Typical macros are expressions and require a semicolon to be added.
/// Sometimes this is not the case, and this allows to make clang-format aware
/// of such cases.
///
/// For example: Q_UNUSED
/// \version 8
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -14257,7 +14257,7 @@ class Sema final : public SemaBase {
SourceLocation EllipsisLoc, Expr *IndexExpr,
SourceLocation RSquareLoc,
ArrayRef<Expr *> ExpandedExprs = {},
bool EmptyPack = false);
bool FullySubstituted = false);

/// Handle a C++1z fold-expression: ( expr op ... op expr ).
ExprResult ActOnCXXFoldExpr(Scope *S, SourceLocation LParenLoc, Expr *LHS,
Expand Down
8 changes: 3 additions & 5 deletions clang/lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6223,13 +6223,11 @@ QualType ASTContext::getPackIndexingType(QualType Pattern, Expr *IndexExpr,
ArrayRef<QualType> Expansions,
int Index) const {
QualType Canonical;
bool ExpandsToEmptyPack = FullySubstituted && Expansions.empty();
if (FullySubstituted && Index != -1) {
Canonical = getCanonicalType(Expansions[Index]);
} else {
llvm::FoldingSetNodeID ID;
PackIndexingType::Profile(ID, *this, Pattern, IndexExpr,
ExpandsToEmptyPack);
PackIndexingType::Profile(ID, *this, Pattern, IndexExpr, FullySubstituted);
void *InsertPos = nullptr;
PackIndexingType *Canon =
DependentPackIndexingTypes.FindNodeOrInsertPos(ID, InsertPos);
Expand All @@ -6238,7 +6236,7 @@ QualType ASTContext::getPackIndexingType(QualType Pattern, Expr *IndexExpr,
PackIndexingType::totalSizeToAlloc<QualType>(Expansions.size()),
TypeAlignment);
Canon = new (Mem) PackIndexingType(*this, QualType(), Pattern, IndexExpr,
ExpandsToEmptyPack, Expansions);
FullySubstituted, Expansions);
DependentPackIndexingTypes.InsertNode(Canon, InsertPos);
}
Canonical = QualType(Canon, 0);
Expand All @@ -6248,7 +6246,7 @@ QualType ASTContext::getPackIndexingType(QualType Pattern, Expr *IndexExpr,
Allocate(PackIndexingType::totalSizeToAlloc<QualType>(Expansions.size()),
TypeAlignment);
auto *T = new (Mem) PackIndexingType(*this, Canonical, Pattern, IndexExpr,
ExpandsToEmptyPack, Expansions);
FullySubstituted, Expansions);
Types.push_back(T);
return QualType(T, 0);
}
Expand Down
79 changes: 51 additions & 28 deletions clang/lib/AST/ByteCode/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1642,22 +1642,8 @@ bool Compiler<Emitter>::VisitImplicitValueInitExpr(
if (QT->isIncompleteArrayType())
return true;

if (QT->isArrayType()) {
const ArrayType *AT = QT->getAsArrayTypeUnsafe();
assert(AT);
const auto *CAT = cast<ConstantArrayType>(AT);
size_t NumElems = CAT->getZExtSize();
PrimType ElemT = classifyPrim(CAT->getElementType());

for (size_t I = 0; I != NumElems; ++I) {
if (!this->visitZeroInitializer(ElemT, CAT->getElementType(), E))
return false;
if (!this->emitInitElem(ElemT, I, E))
return false;
}

return true;
}
if (QT->isArrayType())
return this->visitZeroArrayInitializer(QT, E);

if (const auto *ComplexTy = E->getType()->getAs<ComplexType>()) {
assert(Initializing);
Expand Down Expand Up @@ -3916,18 +3902,9 @@ bool Compiler<Emitter>::visitZeroRecordInitializer(const Record *R,
return false;
}
} else if (D->isCompositeArray()) {
const Record *ElemRecord = D->ElemDesc->ElemRecord;
assert(D->ElemDesc->ElemRecord);
for (uint32_t I = 0, N = D->getNumElems(); I != N; ++I) {
if (!this->emitConstUint32(I, E))
return false;
if (!this->emitArrayElemPtr(PT_Uint32, E))
return false;
if (!this->visitZeroRecordInitializer(ElemRecord, E))
return false;
if (!this->emitPopPtr(E))
return false;
}
// Can't be a vector or complex field.
if (!this->visitZeroArrayInitializer(D->getType(), E))
return false;
} else if (D->isRecord()) {
if (!this->visitZeroRecordInitializer(D->ElemRecord, E))
return false;
Expand Down Expand Up @@ -3958,6 +3935,52 @@ bool Compiler<Emitter>::visitZeroRecordInitializer(const Record *R,
return true;
}

template <class Emitter>
bool Compiler<Emitter>::visitZeroArrayInitializer(QualType T, const Expr *E) {
assert(T->isArrayType() || T->isAnyComplexType() || T->isVectorType());
const ArrayType *AT = T->getAsArrayTypeUnsafe();
QualType ElemType = AT->getElementType();
size_t NumElems = cast<ConstantArrayType>(AT)->getZExtSize();

if (std::optional<PrimType> ElemT = classify(ElemType)) {
for (size_t I = 0; I != NumElems; ++I) {
if (!this->visitZeroInitializer(*ElemT, ElemType, E))
return false;
if (!this->emitInitElem(*ElemT, I, E))
return false;
}
return true;
} else if (ElemType->isRecordType()) {
const Record *R = getRecord(ElemType);

for (size_t I = 0; I != NumElems; ++I) {
if (!this->emitConstUint32(I, E))
return false;
if (!this->emitArrayElemPtr(PT_Uint32, E))
return false;
if (!this->visitZeroRecordInitializer(R, E))
return false;
if (!this->emitPopPtr(E))
return false;
}
return true;
} else if (ElemType->isArrayType()) {
for (size_t I = 0; I != NumElems; ++I) {
if (!this->emitConstUint32(I, E))
return false;
if (!this->emitArrayElemPtr(PT_Uint32, E))
return false;
if (!this->visitZeroArrayInitializer(ElemType, E))
return false;
if (!this->emitPopPtr(E))
return false;
}
return true;
}

return false;
}

template <class Emitter>
template <typename T>
bool Compiler<Emitter>::emitConst(T Value, PrimType Ty, const Expr *E) {
Expand Down
1 change: 1 addition & 0 deletions clang/lib/AST/ByteCode/Compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ class Compiler : public ConstStmtVisitor<Compiler<Emitter>, bool>,
/// Emits a zero initializer.
bool visitZeroInitializer(PrimType T, QualType QT, const Expr *E);
bool visitZeroRecordInitializer(const Record *R, const Expr *E);
bool visitZeroArrayInitializer(QualType T, const Expr *E);

/// Emits an APSInt constant.
bool emitConst(const llvm::APSInt &Value, PrimType Ty, const Expr *E);
Expand Down
7 changes: 6 additions & 1 deletion clang/lib/AST/ByteCode/InterpFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,12 @@ SourceInfo InterpFrame::getSource(CodePtr PC) const {
if (Func && !funcHasUsableBody(Func) && Caller)
return Caller->getSource(RetPC);

return S.getSource(Func, PC);
// Similarly, if the resulting source location is invalid anyway,
// point to the caller instead.
SourceInfo Result = S.getSource(Func, PC);
if (Result.getLoc().isInvalid() && Caller)
return Caller->getSource(RetPC);
return Result;
}

const Expr *InterpFrame::getExpr(CodePtr PC) const {
Expand Down
3 changes: 1 addition & 2 deletions clang/lib/AST/ComputeDependence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,8 @@ ExprDependence clang::computeDependence(PackIndexingExpr *E) {
ExprDependence::Instantiation;

ArrayRef<Expr *> Exprs = E->getExpressions();
if (Exprs.empty())
if (Exprs.empty() || !E->isFullySubstituted())
D |= PatternDep | ExprDependence::Instantiation;

else if (!E->getIndexExpr()->isInstantiationDependent()) {
std::optional<unsigned> Index = E->getSelectedIndex();
assert(Index && *Index < Exprs.size() && "pack index out of bound");
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/AST/ExprCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1717,9 +1717,9 @@ NonTypeTemplateParmDecl *SubstNonTypeTemplateParmExpr::getParameter() const {
PackIndexingExpr *PackIndexingExpr::Create(
ASTContext &Context, SourceLocation EllipsisLoc, SourceLocation RSquareLoc,
Expr *PackIdExpr, Expr *IndexExpr, std::optional<int64_t> Index,
ArrayRef<Expr *> SubstitutedExprs, bool ExpandedToEmptyPack) {
ArrayRef<Expr *> SubstitutedExprs, bool FullySubstituted) {
QualType Type;
if (Index && !SubstitutedExprs.empty())
if (Index && FullySubstituted && !SubstitutedExprs.empty())
Type = SubstitutedExprs[*Index]->getType();
else
Type = Context.DependentTy;
Expand All @@ -1728,7 +1728,7 @@ PackIndexingExpr *PackIndexingExpr::Create(
Context.Allocate(totalSizeToAlloc<Expr *>(SubstitutedExprs.size()));
return new (Storage)
PackIndexingExpr(Type, EllipsisLoc, RSquareLoc, PackIdExpr, IndexExpr,
SubstitutedExprs, ExpandedToEmptyPack);
SubstitutedExprs, FullySubstituted);
}

NamedDecl *PackIndexingExpr::getPackDecl() const {
Expand Down
8 changes: 4 additions & 4 deletions clang/lib/AST/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4031,12 +4031,12 @@ void DependentDecltypeType::Profile(llvm::FoldingSetNodeID &ID,

PackIndexingType::PackIndexingType(const ASTContext &Context,
QualType Canonical, QualType Pattern,
Expr *IndexExpr, bool ExpandsToEmptyPack,
Expr *IndexExpr, bool FullySubstituted,
ArrayRef<QualType> Expansions)
: Type(PackIndexing, Canonical,
computeDependence(Pattern, IndexExpr, Expansions)),
Context(Context), Pattern(Pattern), IndexExpr(IndexExpr),
Size(Expansions.size()), ExpandsToEmptyPack(ExpandsToEmptyPack) {
Size(Expansions.size()), FullySubstituted(FullySubstituted) {

std::uninitialized_copy(Expansions.begin(), Expansions.end(),
getTrailingObjects<QualType>());
Expand Down Expand Up @@ -4081,10 +4081,10 @@ PackIndexingType::computeDependence(QualType Pattern, Expr *IndexExpr,

void PackIndexingType::Profile(llvm::FoldingSetNodeID &ID,
const ASTContext &Context, QualType Pattern,
Expr *E, bool ExpandsToEmptyPack) {
Expr *E, bool FullySubstituted) {
Pattern.Profile(ID);
E->Profile(ID, Context, true);
ID.AddBoolean(ExpandsToEmptyPack);
ID.AddBoolean(FullySubstituted);
}

UnaryTransformType::UnaryTransformType(QualType BaseType,
Expand Down
Loading

0 comments on commit 76c5481

Please sign in to comment.