Skip to content

Commit aed6192

Browse files
committed
merge main into amd-staging
2 parents 77843a0 + 47793f9 commit aed6192

File tree

96 files changed

+28607
-4855
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+28607
-4855
lines changed

bolt/runtime/instr.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,9 +714,11 @@ static char *getBinaryPath() {
714714
uint32_t Ret = __readlink(FindBuf, TargetPath, sizeof(TargetPath));
715715
assert(Ret != -1 && Ret != BufSize, "readlink error");
716716
TargetPath[Ret] = '\0';
717+
__close(FDdir);
717718
return TargetPath;
718719
}
719720
}
721+
__close(FDdir);
720722
return nullptr;
721723
}
722724

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,6 +1773,7 @@ def note_unsatisfied_trait
17731773
"%TriviallyCopyable{trivially copyable}|"
17741774
"%Empty{empty}|"
17751775
"%StandardLayout{standard-layout}|"
1776+
"%Aggregate{aggregate}|"
17761777
"%Final{final}"
17771778
"}1">;
17781779

@@ -1794,6 +1795,7 @@ def note_unsatisfied_trait_reason
17941795
"%NTCBase{has a non-trivially-copyable base %1}|"
17951796
"%NTCField{has a non-trivially-copyable member %1 of type %2}|"
17961797
"%NonEmptyMember{has a non-static data member %1 of type %2}|"
1798+
"%PolymorphicType{is a polymorphic type}|"
17971799
"%VirtualFunction{has a virtual function %1}|"
17981800
"%NonEmptyBase{has a base class %1 that is not empty}|"
17991801
"%NonZeroLengthField{field %1 is a non-zero-length bit-field}|"
@@ -1806,6 +1808,8 @@ def note_unsatisfied_trait_reason
18061808
"%DeletedDtr{has a %select{deleted|user-provided}1 destructor}|"
18071809
"%UserProvidedCtr{has a user provided %select{copy|move}1 "
18081810
"constructor}|"
1811+
"%UserDeclaredCtr{has a user-declared constructor}|"
1812+
"%InheritedCtr{has an inherited constructor}|"
18091813
"%DeletedCtr{has a deleted %select{copy|move}1 "
18101814
"constructor}|"
18111815
"%UserProvidedAssign{has a user provided %select{copy|move}1 "
@@ -1817,6 +1821,8 @@ def note_unsatisfied_trait_reason
18171821
"%FunctionType{is a function type}|"
18181822
"%CVVoidType{is a cv void type}|"
18191823
"%IncompleteArrayType{is an incomplete array type}|"
1824+
"%PrivateProtectedDirectDataMember{has a %select{private|protected}1 direct data member}|"
1825+
"%PrivateProtectedDirectBase{has a %select{private|protected}1 direct base}|"
18201826
"%NotClassOrUnion{is not a class or union type}|"
18211827
"%NotMarkedFinal{is not marked 'final'}"
18221828
"}0">;

clang/lib/Sema/SemaOpenACC.cpp

Lines changed: 107 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2589,26 +2589,67 @@ SemaOpenACC::ActOnOpenACCAsteriskSizeExpr(SourceLocation AsteriskLoc) {
25892589
return BuildOpenACCAsteriskSizeExpr(AsteriskLoc);
25902590
}
25912591

2592-
/// Loops through a type and generates an appropriate InitListExpr to generate
2593-
/// type initialization.
2594-
static Expr *GenerateReductionInitRecipeExpr(ASTContext &Context,
2595-
SourceRange ExprRange,
2596-
QualType Ty) {
2592+
namespace {
2593+
enum class InitKind { Zero, One, AllOnes, Least, Largest };
2594+
llvm::APFloat getInitFloatValue(ASTContext &Context, InitKind IK, QualType Ty) {
2595+
switch (IK) {
2596+
case InitKind::Zero:
2597+
return llvm::APFloat::getZero(Context.getFloatTypeSemantics(Ty));
2598+
case InitKind::One:
2599+
return llvm::APFloat::getOne(Context.getFloatTypeSemantics(Ty));
2600+
case InitKind::AllOnes:
2601+
return llvm::APFloat::getAllOnesValue(Context.getFloatTypeSemantics(Ty));
2602+
case InitKind::Least:
2603+
return llvm::APFloat::getLargest(Context.getFloatTypeSemantics(Ty),
2604+
/*Negative=*/true);
2605+
case InitKind::Largest:
2606+
return llvm::APFloat::getLargest(Context.getFloatTypeSemantics(Ty));
2607+
break;
2608+
}
2609+
llvm_unreachable("unknown init kind");
2610+
}
2611+
2612+
llvm::APInt getInitIntValue(ASTContext &Context, InitKind IK, QualType Ty) {
2613+
switch (IK) {
2614+
case InitKind::Zero:
2615+
return llvm::APInt(Context.getIntWidth(Ty), 0);
2616+
case InitKind::One:
2617+
return llvm::APInt(Context.getIntWidth(Ty), 1);
2618+
case InitKind::AllOnes:
2619+
return llvm::APInt::getAllOnes(Context.getIntWidth(Ty));
2620+
case InitKind::Least:
2621+
if (Ty->isSignedIntegerOrEnumerationType())
2622+
return llvm::APInt::getSignedMinValue(Context.getIntWidth(Ty));
2623+
return llvm::APInt::getMinValue(Context.getIntWidth(Ty));
2624+
case InitKind::Largest:
2625+
if (Ty->isSignedIntegerOrEnumerationType())
2626+
return llvm::APInt::getSignedMaxValue(Context.getIntWidth(Ty));
2627+
return llvm::APInt::getMaxValue(Context.getIntWidth(Ty));
2628+
break;
2629+
}
2630+
llvm_unreachable("unknown init kind");
2631+
}
2632+
2633+
/// Loops through a type and generates an appropriate InitListExpr to
2634+
/// generate type initialization.
2635+
Expr *GenerateReductionInitRecipeExpr(ASTContext &Context,
2636+
SourceRange ExprRange, QualType Ty,
2637+
InitKind IK) {
25972638
Ty = Ty.getCanonicalType();
25982639
llvm::SmallVector<Expr *> Exprs;
25992640

26002641
if (const RecordDecl *RD = Ty->getAsRecordDecl()) {
26012642
for (auto *F : RD->fields()) {
2602-
if (Expr *NewExpr =
2603-
GenerateReductionInitRecipeExpr(Context, ExprRange, F->getType()))
2643+
if (Expr *NewExpr = GenerateReductionInitRecipeExpr(Context, ExprRange,
2644+
F->getType(), IK))
26042645
Exprs.push_back(NewExpr);
26052646
else
26062647
return nullptr;
26072648
}
26082649
} else if (const ConstantArrayType *AT = Context.getAsConstantArrayType(Ty)) {
26092650
for (uint64_t Idx = 0; Idx < AT->getZExtSize(); ++Idx) {
2610-
if (Expr *NewExpr = GenerateReductionInitRecipeExpr(Context, ExprRange,
2611-
AT->getElementType()))
2651+
if (Expr *NewExpr = GenerateReductionInitRecipeExpr(
2652+
Context, ExprRange, AT->getElementType(), IK))
26122653
Exprs.push_back(NewExpr);
26132654
else
26142655
return nullptr;
@@ -2627,16 +2668,41 @@ static Expr *GenerateReductionInitRecipeExpr(ASTContext &Context,
26272668
} else {
26282669
assert(Ty->isScalarType());
26292670

2630-
// TODO: OpenACC: This currently only works for '1', but we need to figure
2631-
// out a way to do least/largest/all-1s.
2632-
if (Ty->isFloatingType()) {
2633-
Exprs.push_back(FloatingLiteral::Create(
2634-
Context, llvm::APFloat::getOne(Context.getFloatTypeSemantics(Ty)),
2635-
/*isExact=*/true, Ty, ExprRange.getBegin()));
2671+
if (const auto *Cplx = Ty->getAs<ComplexType>()) {
2672+
// we can get here in error cases, so make sure we generate something that
2673+
// will work if we find ourselves wanting to enable this, so emit '0,0'
2674+
// for both ints and floats.
2675+
2676+
QualType EltTy = Cplx->getElementType();
2677+
if (EltTy->isFloatingType()) {
2678+
Exprs.push_back(FloatingLiteral::Create(
2679+
Context, getInitFloatValue(Context, InitKind::Zero, EltTy),
2680+
/*isExact=*/true, EltTy, ExprRange.getBegin()));
2681+
Exprs.push_back(FloatingLiteral::Create(
2682+
Context, getInitFloatValue(Context, InitKind::Zero, EltTy),
2683+
/*isExact=*/true, EltTy, ExprRange.getBegin()));
2684+
} else {
2685+
Exprs.push_back(IntegerLiteral::Create(
2686+
Context, getInitIntValue(Context, InitKind::Zero, EltTy), EltTy,
2687+
ExprRange.getBegin()));
2688+
Exprs.push_back(IntegerLiteral::Create(
2689+
Context, getInitIntValue(Context, InitKind::Zero, EltTy), EltTy,
2690+
ExprRange.getBegin()));
2691+
}
2692+
2693+
} else if (Ty->isFloatingType()) {
2694+
Exprs.push_back(
2695+
FloatingLiteral::Create(Context, getInitFloatValue(Context, IK, Ty),
2696+
/*isExact=*/true, Ty, ExprRange.getBegin()));
2697+
} else if (Ty->isBooleanType()) {
2698+
Exprs.push_back(CXXBoolLiteralExpr::Create(Context,
2699+
(IK == InitKind::One ||
2700+
IK == InitKind::AllOnes ||
2701+
IK == InitKind::Largest),
2702+
Ty, ExprRange.getBegin()));
26362703
} else {
26372704
Exprs.push_back(IntegerLiteral::Create(
2638-
Context, llvm::APInt(Context.getTypeSize(Ty), 1), Ty,
2639-
ExprRange.getBegin()));
2705+
Context, getInitIntValue(Context, IK, Ty), Ty, ExprRange.getBegin()));
26402706
}
26412707
}
26422708

@@ -2646,6 +2712,8 @@ static Expr *GenerateReductionInitRecipeExpr(ASTContext &Context,
26462712
return InitExpr;
26472713
}
26482714

2715+
} // namespace
2716+
26492717
std::pair<VarDecl *, VarDecl *>
26502718
SemaOpenACC::CreateInitRecipe(OpenACCClauseKind CK,
26512719
OpenACCReductionOperator ReductionOperator,
@@ -2796,20 +2864,37 @@ SemaOpenACC::CreateInitRecipe(OpenACCClauseKind CK,
27962864
// are used for code generation, we can just ignore/not bother doing any
27972865
// initialization here.
27982866
break;
2799-
case OpenACCReductionOperator::Max:
2800-
case OpenACCReductionOperator::Min:
2801-
case OpenACCReductionOperator::BitwiseAnd:
2802-
// TODO: OpenACC: figure out init for these.
2867+
case OpenACCReductionOperator::Max: {
2868+
Expr *InitExpr = GenerateReductionInitRecipeExpr(
2869+
getASTContext(), VarExpr->getSourceRange(), VarTy, InitKind::Least);
2870+
2871+
Init = FinishValueInit(InitExpr);
2872+
break;
2873+
}
2874+
case OpenACCReductionOperator::Min: {
2875+
Expr *InitExpr = GenerateReductionInitRecipeExpr(
2876+
getASTContext(), VarExpr->getSourceRange(), VarTy,
2877+
InitKind::Largest);
2878+
2879+
Init = FinishValueInit(InitExpr);
28032880
break;
2881+
}
2882+
case OpenACCReductionOperator::BitwiseAnd: {
2883+
Expr *InitExpr = GenerateReductionInitRecipeExpr(
2884+
getASTContext(), VarExpr->getSourceRange(), VarTy,
2885+
InitKind::AllOnes);
28042886

2887+
Init = FinishValueInit(InitExpr);
2888+
break;
2889+
}
28052890
case OpenACCReductionOperator::Multiplication:
28062891
case OpenACCReductionOperator::And: {
28072892
// '&&' initializes every field to 1. However, we need to loop through
28082893
// every field/element and generate an initializer for each of the
28092894
// elements.
28102895

28112896
Expr *InitExpr = GenerateReductionInitRecipeExpr(
2812-
getASTContext(), VarExpr->getSourceRange(), VarTy);
2897+
getASTContext(), VarExpr->getSourceRange(), VarTy, InitKind::One);
28132898

28142899
Init = FinishValueInit(InitExpr);
28152900
break;

clang/lib/Sema/SemaTypeTraits.cpp

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@
1616
#include "clang/Basic/DiagnosticIDs.h"
1717
#include "clang/Basic/DiagnosticParse.h"
1818
#include "clang/Basic/DiagnosticSema.h"
19+
#include "clang/Basic/Specifiers.h"
1920
#include "clang/Basic/TypeTraits.h"
2021
#include "clang/Sema/EnterExpressionEvaluationContext.h"
2122
#include "clang/Sema/Initialization.h"
2223
#include "clang/Sema/Lookup.h"
2324
#include "clang/Sema/Overload.h"
2425
#include "clang/Sema/Sema.h"
2526
#include "clang/Sema/SemaHLSL.h"
27+
#include "llvm/ADT/STLExtras.h"
2628

2729
using namespace clang;
2830

@@ -2009,6 +2011,7 @@ static std::optional<TypeTrait> StdNameToTypeTrait(StringRef Name) {
20092011
.Case("is_assignable", TypeTrait::BTT_IsAssignable)
20102012
.Case("is_empty", TypeTrait::UTT_IsEmpty)
20112013
.Case("is_standard_layout", TypeTrait::UTT_IsStandardLayout)
2014+
.Case("is_aggregate", TypeTrait::UTT_IsAggregate)
20122015
.Case("is_constructible", TypeTrait::TT_IsConstructible)
20132016
.Case("is_final", TypeTrait::UTT_IsFinal)
20142017
.Default(std::nullopt);
@@ -2685,6 +2688,92 @@ static void DiagnoseNonStandardLayoutReason(Sema &SemaRef, SourceLocation Loc,
26852688
SemaRef.Diag(D->getLocation(), diag::note_defined_here) << D;
26862689
}
26872690

2691+
static void DiagnoseNonAggregateReason(Sema &SemaRef, SourceLocation Loc,
2692+
const CXXRecordDecl *D) {
2693+
for (const CXXConstructorDecl *Ctor : D->ctors()) {
2694+
if (Ctor->isUserProvided())
2695+
SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
2696+
<< diag::TraitNotSatisfiedReason::UserDeclaredCtr;
2697+
if (Ctor->isInheritingConstructor())
2698+
SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
2699+
<< diag::TraitNotSatisfiedReason::InheritedCtr;
2700+
}
2701+
2702+
if (llvm::any_of(D->decls(), [](auto const *Sub) {
2703+
return isa<ConstructorUsingShadowDecl>(Sub);
2704+
})) {
2705+
SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
2706+
<< diag::TraitNotSatisfiedReason::InheritedCtr;
2707+
}
2708+
2709+
if (D->isPolymorphic())
2710+
SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
2711+
<< diag::TraitNotSatisfiedReason::PolymorphicType
2712+
<< D->getSourceRange();
2713+
2714+
for (const CXXBaseSpecifier &B : D->bases()) {
2715+
if (B.isVirtual()) {
2716+
SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
2717+
<< diag::TraitNotSatisfiedReason::VBase << B.getType()
2718+
<< B.getSourceRange();
2719+
continue;
2720+
}
2721+
auto AccessSpecifier = B.getAccessSpecifier();
2722+
switch (AccessSpecifier) {
2723+
case AS_private:
2724+
case AS_protected:
2725+
SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
2726+
<< diag::TraitNotSatisfiedReason::PrivateProtectedDirectBase
2727+
<< (AccessSpecifier == AS_protected);
2728+
break;
2729+
default:
2730+
break;
2731+
}
2732+
}
2733+
2734+
for (const CXXMethodDecl *Method : D->methods()) {
2735+
if (Method->isVirtual()) {
2736+
SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
2737+
<< diag::TraitNotSatisfiedReason::VirtualFunction << Method
2738+
<< Method->getSourceRange();
2739+
}
2740+
}
2741+
2742+
for (const FieldDecl *Field : D->fields()) {
2743+
auto AccessSpecifier = Field->getAccess();
2744+
switch (AccessSpecifier) {
2745+
case AS_private:
2746+
case AS_protected:
2747+
SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
2748+
<< diag::TraitNotSatisfiedReason::PrivateProtectedDirectDataMember
2749+
<< (AccessSpecifier == AS_protected);
2750+
break;
2751+
default:
2752+
break;
2753+
}
2754+
}
2755+
2756+
SemaRef.Diag(D->getLocation(), diag::note_defined_here) << D;
2757+
}
2758+
2759+
static void DiagnoseNonAggregateReason(Sema &SemaRef, SourceLocation Loc,
2760+
QualType T) {
2761+
SemaRef.Diag(Loc, diag::note_unsatisfied_trait)
2762+
<< T << diag::TraitName::Aggregate;
2763+
2764+
if (T->isVoidType())
2765+
SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
2766+
<< diag::TraitNotSatisfiedReason::CVVoidType;
2767+
2768+
T = T.getNonReferenceType();
2769+
const CXXRecordDecl *D = T->getAsCXXRecordDecl();
2770+
if (!D || D->isInvalidDecl())
2771+
return;
2772+
2773+
if (D->hasDefinition())
2774+
DiagnoseNonAggregateReason(SemaRef, Loc, D);
2775+
}
2776+
26882777
void Sema::DiagnoseTypeTraitDetails(const Expr *E) {
26892778
E = E->IgnoreParenImpCasts();
26902779
if (E->containsErrors())
@@ -2717,6 +2806,9 @@ void Sema::DiagnoseTypeTraitDetails(const Expr *E) {
27172806
case TT_IsConstructible:
27182807
DiagnoseNonConstructibleReason(*this, E->getBeginLoc(), Args);
27192808
break;
2809+
case UTT_IsAggregate:
2810+
DiagnoseNonAggregateReason(*this, E->getBeginLoc(), Args[0]);
2811+
break;
27202812
case UTT_IsFinal: {
27212813
QualType QT = Args[0];
27222814
if (QT->isDependentType())

0 commit comments

Comments
 (0)