Skip to content

Commit 54e6914

Browse files
committed
Merge from 'main' to 'sycl-web' (57 commits)
CONFLICT (content): Merge conflict in llvm/include/llvm/CodeGen/CodeGenPassBuilder.h
2 parents a24b8e6 + 06aa8b1 commit 54e6914

File tree

357 files changed

+8410
-4103
lines changed

Some content is hidden

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

357 files changed

+8410
-4103
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: rm -rf %t.dir && mkdir -p %t.dir
2+
// RUN: echo '[{"directory": "%/t.dir", "command": "clang --target=x86_64-pc-windows-msvc -x c GH75115.test", "file": "GH75115.test"}]' > %t.dir/compile_commands.json
3+
// RUN: not --crash clangd -enable-config=0 --compile-commands-dir=%t.dir -check=%s 2>&1 | FileCheck -strict-whitespace %s
4+
5+
// FIXME: Crashes
6+
7+
// CHECK: Building preamble...
8+
// CHECK-NEXT: Built preamble
9+
// CHECK-NEXT: Indexing headers...
10+
// CHECK-NEXT: !KeyInfoT::isEqual(Val, EmptyKey) && !KeyInfoT::isEqual(Val, TombstoneKey) && "Empty/Tombstone value shouldn't be inserted into map!"
11+
12+
#define assert

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,9 @@ Bug Fixes in This Version
685685
(`#62157 <https://github.com/llvm/llvm-project/issues/62157>`_) and
686686
(`#64885 <https://github.com/llvm/llvm-project/issues/64885>`_) and
687687
(`#65568 <https://github.com/llvm/llvm-project/issues/65568>`_)
688+
- Fixed false positive error emitted when templated alias inside a class
689+
used private members of the same class.
690+
Fixes (`#41693 <https://github.com/llvm/llvm-project/issues/41693>`_)
688691

689692
Bug Fixes to Compiler Builtins
690693
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/Sema/Sema.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9016,7 +9016,7 @@ class Sema final {
90169016
SourceLocation IILoc,
90179017
bool DeducedTSTContext = true);
90189018

9019-
9019+
bool RebuildingTypesInCurrentInstantiation = false;
90209020
TypeSourceInfo *RebuildTypeInCurrentInstantiation(TypeSourceInfo *T,
90219021
SourceLocation Loc,
90229022
DeclarationName Name);

clang/lib/Sema/SemaCXXScopeSpec.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,33 @@ static CXXRecordDecl *getCurrentInstantiationOf(QualType T,
3030
return nullptr;
3131

3232
const Type *Ty = T->getCanonicalTypeInternal().getTypePtr();
33+
if (isa<TemplateSpecializationType>(Ty)) {
34+
if (auto *Record = dyn_cast<CXXRecordDecl>(CurContext)) {
35+
if (isa<ClassTemplatePartialSpecializationDecl>(Record) ||
36+
Record->getDescribedClassTemplate()) {
37+
const Type *ICNT = Record->getTypeForDecl();
38+
QualType Injected =
39+
cast<InjectedClassNameType>(ICNT)->getInjectedSpecializationType();
40+
41+
if (Ty == Injected->getCanonicalTypeInternal().getTypePtr())
42+
return Record;
43+
}
44+
}
45+
}
46+
3347
if (const RecordType *RecordTy = dyn_cast<RecordType>(Ty)) {
3448
CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordTy->getDecl());
3549
if (!Record->isDependentContext() ||
3650
Record->isCurrentInstantiation(CurContext))
3751
return Record;
3852

3953
return nullptr;
40-
} else if (isa<InjectedClassNameType>(Ty))
41-
return cast<InjectedClassNameType>(Ty)->getDecl();
42-
else
43-
return nullptr;
54+
}
55+
56+
if (auto *ICNT = dyn_cast<InjectedClassNameType>(Ty))
57+
return ICNT->getDecl();
58+
59+
return nullptr;
4460
}
4561

4662
/// Compute the DeclContext that is associated with the given type.

clang/lib/Sema/SemaInit.cpp

Lines changed: 80 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,8 @@ class InitListChecker {
465465
void FillInEmptyInitForField(unsigned Init, FieldDecl *Field,
466466
const InitializedEntity &ParentEntity,
467467
InitListExpr *ILE, bool &RequiresSecondPass,
468-
bool FillWithNoInit = false);
468+
bool FillWithNoInit = false,
469+
bool WarnIfMissing = false);
469470
void FillInEmptyInitializations(const InitializedEntity &Entity,
470471
InitListExpr *ILE, bool &RequiresSecondPass,
471472
InitListExpr *OuterILE, unsigned OuterIndex,
@@ -654,11 +655,16 @@ void InitListChecker::FillInEmptyInitForBase(
654655
}
655656
}
656657

657-
void InitListChecker::FillInEmptyInitForField(unsigned Init, FieldDecl *Field,
658-
const InitializedEntity &ParentEntity,
659-
InitListExpr *ILE,
660-
bool &RequiresSecondPass,
661-
bool FillWithNoInit) {
658+
static bool hasAnyDesignatedInits(const InitListExpr *IL) {
659+
return llvm::any_of(*IL, [=](const Stmt *Init) {
660+
return isa_and_nonnull<DesignatedInitExpr>(Init);
661+
});
662+
}
663+
664+
void InitListChecker::FillInEmptyInitForField(
665+
unsigned Init, FieldDecl *Field, const InitializedEntity &ParentEntity,
666+
InitListExpr *ILE, bool &RequiresSecondPass, bool FillWithNoInit,
667+
bool WarnIfMissing) {
662668
SourceLocation Loc = ILE->getEndLoc();
663669
unsigned NumInits = ILE->getNumInits();
664670
InitializedEntity MemberEntity
@@ -726,15 +732,52 @@ void InitListChecker::FillInEmptyInitForField(unsigned Init, FieldDecl *Field,
726732

727733
if (hadError || VerifyOnly) {
728734
// Do nothing
729-
} else if (Init < NumInits) {
730-
ILE->setInit(Init, MemberInit.getAs<Expr>());
731-
} else if (!isa<ImplicitValueInitExpr>(MemberInit.get())) {
732-
// Empty initialization requires a constructor call, so
733-
// extend the initializer list to include the constructor
734-
// call and make a note that we'll need to take another pass
735-
// through the initializer list.
736-
ILE->updateInit(SemaRef.Context, Init, MemberInit.getAs<Expr>());
737-
RequiresSecondPass = true;
735+
} else {
736+
if (WarnIfMissing) {
737+
auto CheckAnonMember = [&](const FieldDecl *FD,
738+
auto &&CheckAnonMember) -> FieldDecl * {
739+
FieldDecl *Uninitialized = nullptr;
740+
RecordDecl *RD = FD->getType()->getAsRecordDecl();
741+
assert(RD && "Not anonymous member checked?");
742+
for (auto *F : RD->fields()) {
743+
FieldDecl *UninitializedFieldInF = nullptr;
744+
if (F->isAnonymousStructOrUnion())
745+
UninitializedFieldInF = CheckAnonMember(F, CheckAnonMember);
746+
else if (!F->isUnnamedBitfield() &&
747+
!F->getType()->isIncompleteArrayType() &&
748+
!F->hasInClassInitializer())
749+
UninitializedFieldInF = F;
750+
751+
if (RD->isUnion() && !UninitializedFieldInF)
752+
return nullptr;
753+
if (!Uninitialized)
754+
Uninitialized = UninitializedFieldInF;
755+
}
756+
return Uninitialized;
757+
};
758+
759+
FieldDecl *FieldToDiagnose = nullptr;
760+
if (Field->isAnonymousStructOrUnion())
761+
FieldToDiagnose = CheckAnonMember(Field, CheckAnonMember);
762+
else if (!Field->isUnnamedBitfield() &&
763+
!Field->getType()->isIncompleteArrayType())
764+
FieldToDiagnose = Field;
765+
766+
if (FieldToDiagnose)
767+
SemaRef.Diag(Loc, diag::warn_missing_field_initializers)
768+
<< FieldToDiagnose;
769+
}
770+
771+
if (Init < NumInits) {
772+
ILE->setInit(Init, MemberInit.getAs<Expr>());
773+
} else if (!isa<ImplicitValueInitExpr>(MemberInit.get())) {
774+
// Empty initialization requires a constructor call, so
775+
// extend the initializer list to include the constructor
776+
// call and make a note that we'll need to take another pass
777+
// through the initializer list.
778+
ILE->updateInit(SemaRef.Context, Init, MemberInit.getAs<Expr>());
779+
RequiresSecondPass = true;
780+
}
738781
}
739782
} else if (InitListExpr *InnerILE
740783
= dyn_cast<InitListExpr>(ILE->getInit(Init))) {
@@ -802,9 +845,25 @@ InitListChecker::FillInEmptyInitializations(const InitializedEntity &Entity,
802845
}
803846
}
804847
} else {
848+
InitListExpr *SForm =
849+
ILE->isSyntacticForm() ? ILE : ILE->getSyntacticForm();
805850
// The fields beyond ILE->getNumInits() are default initialized, so in
806851
// order to leave them uninitialized, the ILE is expanded and the extra
807852
// fields are then filled with NoInitExpr.
853+
854+
// Some checks that are required for missing fields warning are bound to
855+
// how many elements the initializer list originally was provided; perform
856+
// them before the list is expanded.
857+
bool WarnIfMissingField =
858+
!SForm->isIdiomaticZeroInitializer(SemaRef.getLangOpts()) &&
859+
ILE->getNumInits();
860+
861+
// Disable check for missing fields when designators are used in C to
862+
// match gcc behaviour.
863+
// FIXME: Should we emulate possible gcc warning bug?
864+
WarnIfMissingField &=
865+
SemaRef.getLangOpts().CPlusPlus || !hasAnyDesignatedInits(SForm);
866+
808867
unsigned NumElems = numStructUnionElements(ILE->getType());
809868
if (!RDecl->isUnion() && RDecl->hasFlexibleArrayMember())
810869
++NumElems;
@@ -832,7 +891,7 @@ InitListChecker::FillInEmptyInitializations(const InitializedEntity &Entity,
832891
return;
833892

834893
FillInEmptyInitForField(Init, Field, Entity, ILE, RequiresSecondPass,
835-
FillWithNoInit);
894+
FillWithNoInit, WarnIfMissingField);
836895
if (hadError)
837896
return;
838897

@@ -947,13 +1006,6 @@ InitListChecker::FillInEmptyInitializations(const InitializedEntity &Entity,
9471006
}
9481007
}
9491008

950-
static bool hasAnyDesignatedInits(const InitListExpr *IL) {
951-
for (const Stmt *Init : *IL)
952-
if (isa_and_nonnull<DesignatedInitExpr>(Init))
953-
return true;
954-
return false;
955-
}
956-
9571009
InitListChecker::InitListChecker(
9581010
Sema &S, const InitializedEntity &Entity, InitListExpr *IL, QualType &T,
9591011
bool VerifyOnly, bool TreatUnavailableAsInvalid, bool InOverloadResolution,
@@ -2225,12 +2277,8 @@ void InitListChecker::CheckStructUnionTypes(
22252277
size_t NumRecordDecls = llvm::count_if(RD->decls(), [&](const Decl *D) {
22262278
return isa<FieldDecl>(D) || isa<RecordDecl>(D);
22272279
});
2228-
bool CheckForMissingFields =
2229-
!IList->isIdiomaticZeroInitializer(SemaRef.getLangOpts());
22302280
bool HasDesignatedInit = false;
22312281

2232-
llvm::SmallPtrSet<FieldDecl *, 4> InitializedFields;
2233-
22342282
while (Index < IList->getNumInits()) {
22352283
Expr *Init = IList->getInit(Index);
22362284
SourceLocation InitLoc = Init->getBeginLoc();
@@ -2254,24 +2302,17 @@ void InitListChecker::CheckStructUnionTypes(
22542302

22552303
// Find the field named by the designated initializer.
22562304
DesignatedInitExpr::Designator *D = DIE->getDesignator(0);
2257-
if (!VerifyOnly && D->isFieldDesignator()) {
2305+
if (!VerifyOnly && D->isFieldDesignator() && !DesignatedInitFailed) {
22582306
FieldDecl *F = D->getFieldDecl();
2259-
InitializedFields.insert(F);
2260-
if (!DesignatedInitFailed) {
2261-
QualType ET = SemaRef.Context.getBaseElementType(F->getType());
2262-
if (checkDestructorReference(ET, InitLoc, SemaRef)) {
2263-
hadError = true;
2264-
return;
2265-
}
2307+
QualType ET = SemaRef.Context.getBaseElementType(F->getType());
2308+
if (checkDestructorReference(ET, InitLoc, SemaRef)) {
2309+
hadError = true;
2310+
return;
22662311
}
22672312
}
22682313

22692314
InitializedSomething = true;
22702315

2271-
// Disable check for missing fields when designators are used.
2272-
// This matches gcc behaviour.
2273-
if (!SemaRef.getLangOpts().CPlusPlus)
2274-
CheckForMissingFields = false;
22752316
continue;
22762317
}
22772318

@@ -2350,7 +2391,6 @@ void InitListChecker::CheckStructUnionTypes(
23502391
CheckSubElementType(MemberEntity, IList, Field->getType(), Index,
23512392
StructuredList, StructuredIndex);
23522393
InitializedSomething = true;
2353-
InitializedFields.insert(*Field);
23542394

23552395
if (RD->isUnion() && StructuredList) {
23562396
// Initialize the first field within the union.
@@ -2360,28 +2400,6 @@ void InitListChecker::CheckStructUnionTypes(
23602400
++Field;
23612401
}
23622402

2363-
// Emit warnings for missing struct field initializers.
2364-
if (!VerifyOnly && InitializedSomething && CheckForMissingFields &&
2365-
!RD->isUnion()) {
2366-
// It is possible we have one or more unnamed bitfields remaining.
2367-
// Find first (if any) named field and emit warning.
2368-
for (RecordDecl::field_iterator it = HasDesignatedInit ? RD->field_begin()
2369-
: Field,
2370-
end = RD->field_end();
2371-
it != end; ++it) {
2372-
if (HasDesignatedInit && InitializedFields.count(*it))
2373-
continue;
2374-
2375-
if (!it->isUnnamedBitfield() && !it->hasInClassInitializer() &&
2376-
!it->getType()->isIncompleteArrayType()) {
2377-
SemaRef.Diag(IList->getSourceRange().getEnd(),
2378-
diag::warn_missing_field_initializers)
2379-
<< *it;
2380-
break;
2381-
}
2382-
}
2383-
}
2384-
23852403
// Check that any remaining fields can be value-initialized if we're not
23862404
// building a structured list. (If we are, we'll check this later.)
23872405
if (!StructuredList && Field != FieldEnd && !RD->isUnion() &&

clang/lib/Sema/SemaRISCVVectorLookup.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ struct RVVIntrinsicDef {
4343

4444
struct RVVOverloadIntrinsicDef {
4545
// Indexes of RISCVIntrinsicManagerImpl::IntrinsicList.
46-
SmallVector<size_t, 8> Indexes;
46+
SmallVector<uint32_t, 8> Indexes;
4747
};
4848

4949
} // namespace
@@ -162,7 +162,7 @@ class RISCVIntrinsicManagerImpl : public sema::RISCVIntrinsicManager {
162162
// List of all RVV intrinsic.
163163
std::vector<RVVIntrinsicDef> IntrinsicList;
164164
// Mapping function name to index of IntrinsicList.
165-
StringMap<size_t> Intrinsics;
165+
StringMap<uint32_t> Intrinsics;
166166
// Mapping function name to RVVOverloadIntrinsicDef.
167167
StringMap<RVVOverloadIntrinsicDef> OverloadIntrinsics;
168168

@@ -174,7 +174,7 @@ class RISCVIntrinsicManagerImpl : public sema::RISCVIntrinsicManager {
174174

175175
// Create FunctionDecl for a vector intrinsic.
176176
void CreateRVVIntrinsicDecl(LookupResult &LR, IdentifierInfo *II,
177-
Preprocessor &PP, unsigned Index,
177+
Preprocessor &PP, uint32_t Index,
178178
bool IsOverload);
179179

180180
void ConstructRVVIntrinsics(ArrayRef<RVVIntrinsicRecord> Recs,
@@ -386,7 +386,7 @@ void RISCVIntrinsicManagerImpl::InitRVVIntrinsic(
386386
Record.HasFRMRoundModeOp);
387387

388388
// Put into IntrinsicList.
389-
size_t Index = IntrinsicList.size();
389+
uint32_t Index = IntrinsicList.size();
390390
IntrinsicList.push_back({BuiltinName, Signature});
391391

392392
// Creating mapping to Intrinsics.
@@ -403,7 +403,7 @@ void RISCVIntrinsicManagerImpl::InitRVVIntrinsic(
403403
void RISCVIntrinsicManagerImpl::CreateRVVIntrinsicDecl(LookupResult &LR,
404404
IdentifierInfo *II,
405405
Preprocessor &PP,
406-
unsigned Index,
406+
uint32_t Index,
407407
bool IsOverload) {
408408
ASTContext &Context = S.Context;
409409
RVVIntrinsicDef &IDef = IntrinsicList[Index];

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "llvm/ADT/SmallBitVector.h"
4040
#include "llvm/ADT/SmallString.h"
4141
#include "llvm/ADT/StringExtras.h"
42+
#include "llvm/Support/SaveAndRestore.h"
4243

4344
#include <iterator>
4445
#include <optional>
@@ -3990,9 +3991,14 @@ QualType Sema::CheckTemplateIdType(TemplateName Name,
39903991
if (Inst.isInvalid())
39913992
return QualType();
39923993

3993-
CanonType = SubstType(Pattern->getUnderlyingType(),
3994-
TemplateArgLists, AliasTemplate->getLocation(),
3995-
AliasTemplate->getDeclName());
3994+
{
3995+
Sema::ContextRAII SavedContext(*this, Pattern->getDeclContext());
3996+
if (RebuildingTypesInCurrentInstantiation)
3997+
SavedContext.pop();
3998+
CanonType =
3999+
SubstType(Pattern->getUnderlyingType(), TemplateArgLists,
4000+
AliasTemplate->getLocation(), AliasTemplate->getDeclName());
4001+
}
39964002
if (CanonType.isNull()) {
39974003
// If this was enable_if and we failed to find the nested type
39984004
// within enable_if in a SFINAE context, dig out the specific
@@ -11392,6 +11398,8 @@ TypeSourceInfo *Sema::RebuildTypeInCurrentInstantiation(TypeSourceInfo *T,
1139211398
if (!T || !T->getType()->isInstantiationDependentType())
1139311399
return T;
1139411400

11401+
llvm::SaveAndRestore DisableContextSwitchForTypeAliases(
11402+
RebuildingTypesInCurrentInstantiation, true);
1139511403
CurrentInstantiationRebuilder Rebuilder(*this, Loc, Name);
1139611404
return Rebuilder.TransformType(T);
1139711405
}

clang/test/CXX/temp/temp.decls/temp.alias/p3.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
// The example given in the standard (this is rejected for other reasons anyway).
44
template<class T> struct A;
5-
template<class T> using B = typename A<T>::U; // expected-error {{no type named 'U' in 'A<T>'}}
5+
template<class T> using B = typename A<T>::U; // expected-error {{no type named 'U' in 'A<short>'}}
6+
// expected-note@-1 {{in instantiation of template class 'A<short>' requested here}}
67
template<class T> struct A {
78
typedef B<T> U; // expected-note {{in instantiation of template type alias 'B' requested here}}
89
};
9-
B<short> b;
10+
B<short> b; // expected-note {{in instantiation of template type alias 'B' requested here}}
1011

1112
template<typename T> using U = int;
1213

0 commit comments

Comments
 (0)