Skip to content

Commit c1fed68

Browse files
committed
Merge commit '43e13fdc9e8edd425f640c424071377879c07822' into llvmspirv_pulldown
2 parents 021b0fe + 43e13fd commit c1fed68

File tree

484 files changed

+16947
-14700
lines changed

Some content is hidden

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

484 files changed

+16947
-14700
lines changed

clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -118,45 +118,50 @@ static void updateAssignmentLevel(
118118
}
119119
}
120120

121-
static std::pair<const FieldDecl *, const Expr *>
121+
struct AssignmentPair {
122+
const FieldDecl *Field;
123+
const Expr *Init;
124+
};
125+
126+
static std::optional<AssignmentPair>
122127
isAssignmentToMemberOf(const CXXRecordDecl *Rec, const Stmt *S,
123128
const CXXConstructorDecl *Ctor) {
124129
if (const auto *BO = dyn_cast<BinaryOperator>(S)) {
125130
if (BO->getOpcode() != BO_Assign)
126-
return std::make_pair(nullptr, nullptr);
131+
return {};
127132

128133
const auto *ME = dyn_cast<MemberExpr>(BO->getLHS()->IgnoreParenImpCasts());
129134
if (!ME)
130-
return std::make_pair(nullptr, nullptr);
135+
return {};
131136

132137
const auto *Field = dyn_cast<FieldDecl>(ME->getMemberDecl());
133138
if (!Field)
134-
return std::make_pair(nullptr, nullptr);
139+
return {};
135140

136141
if (!isa<CXXThisExpr>(ME->getBase()))
137-
return std::make_pair(nullptr, nullptr);
142+
return {};
138143
const Expr *Init = BO->getRHS()->IgnoreParenImpCasts();
139-
return std::make_pair(Field, Init);
144+
return AssignmentPair{Field, Init};
140145
}
141146
if (const auto *COCE = dyn_cast<CXXOperatorCallExpr>(S)) {
142147
if (COCE->getOperator() != OO_Equal)
143-
return std::make_pair(nullptr, nullptr);
148+
return {};
144149

145150
const auto *ME =
146151
dyn_cast<MemberExpr>(COCE->getArg(0)->IgnoreParenImpCasts());
147152
if (!ME)
148-
return std::make_pair(nullptr, nullptr);
153+
return {};
149154

150155
const auto *Field = dyn_cast<FieldDecl>(ME->getMemberDecl());
151156
if (!Field)
152-
return std::make_pair(nullptr, nullptr);
157+
return {};
153158

154159
if (!isa<CXXThisExpr>(ME->getBase()))
155-
return std::make_pair(nullptr, nullptr);
160+
return {};
156161
const Expr *Init = COCE->getArg(1)->IgnoreParenImpCasts();
157-
return std::make_pair(Field, Init);
162+
return AssignmentPair{Field, Init};
158163
}
159-
return std::make_pair(nullptr, nullptr);
164+
return {};
160165
}
161166

162167
PreferMemberInitializerCheck::PreferMemberInitializerCheck(
@@ -216,11 +221,12 @@ void PreferMemberInitializerCheck::check(
216221
return;
217222
}
218223

219-
const FieldDecl *Field = nullptr;
220-
const Expr *InitValue = nullptr;
221-
std::tie(Field, InitValue) = isAssignmentToMemberOf(Class, S, Ctor);
222-
if (!Field)
224+
std::optional<AssignmentPair> AssignmentToMember =
225+
isAssignmentToMemberOf(Class, S, Ctor);
226+
if (!AssignmentToMember)
223227
continue;
228+
const FieldDecl *Field = AssignmentToMember->Field;
229+
const Expr *InitValue = AssignmentToMember->Init;
224230
updateAssignmentLevel(Field, InitValue, Ctor, AssignedFields);
225231
if (!canAdvanceAssignment(AssignedFields[Field]))
226232
continue;

clang/docs/ReleaseNotes.rst

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -665,11 +665,6 @@ Bug Fixes to C++ Support
665665
declaration definition. Fixes:
666666
(`#61763 <https://github.com/llvm/llvm-project/issues/61763>`_)
667667

668-
- Fix a bug where implicit deduction guides are not correctly generated for nested template
669-
classes. Fixes:
670-
(`#46200 <https://github.com/llvm/llvm-project/issues/46200>`_)
671-
(`#57812 <https://github.com/llvm/llvm-project/issues/57812>`_)
672-
673668
- Diagnose use of a variable-length array in a coroutine. The design of
674669
coroutines is such that it is not possible to support VLA use. Fixes:
675670
(`#65858 <https://github.com/llvm/llvm-project/issues/65858>`_)

clang/include/clang/Basic/DiagnosticLexKinds.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,11 @@ def err_header_import_semi_in_macro : Error<
922922
def err_header_import_not_header_unit : Error<
923923
"header file %0 (aka '%1') cannot be imported because "
924924
"it is not known to be a header unit">;
925+
def warn_pp_include_angled_in_module_purview : Warning<
926+
"'#include <filename>' attaches the declarations to the named module '%0'"
927+
", which is not usually intended; consider moving that directive before "
928+
"the module declaration">,
929+
InGroup<DiagGroup<"include-angled-in-module-purview">>;
925930

926931
def warn_header_guard : Warning<
927932
"%0 is used as a header guard here, followed by #define of a different macro">,

clang/lib/Lex/PPDirectives.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2537,6 +2537,10 @@ Preprocessor::ImportAction Preprocessor::HandleHeaderIncludeOrImport(
25372537
return {ImportAction::None};
25382538
}
25392539

2540+
if (isAngled && isInNamedModule())
2541+
Diag(FilenameTok, diag::warn_pp_include_angled_in_module_purview)
2542+
<< getNamedModuleName();
2543+
25402544
// Look up the file, create a File ID for it.
25412545
SourceLocation IncludePos = FilenameTok.getLocation();
25422546
// If the filename string was the result of macro expansions, set the include

clang/lib/Sema/SemaCoroutine.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1965,9 +1965,15 @@ bool Sema::buildCoroutineParameterMoves(SourceLocation Loc) {
19651965
if (PD->getType()->isDependentType())
19661966
continue;
19671967

1968+
// Preserve the referenced state for unused parameter diagnostics.
1969+
bool DeclReferenced = PD->isReferenced();
1970+
19681971
ExprResult PDRefExpr =
19691972
BuildDeclRefExpr(PD, PD->getType().getNonReferenceType(),
19701973
ExprValueKind::VK_LValue, Loc); // FIXME: scope?
1974+
1975+
PD->setReferenced(DeclReferenced);
1976+
19711977
if (PDRefExpr.isInvalid())
19721978
return false;
19731979

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2253,7 +2253,6 @@ struct ConvertConstructorToDeductionGuideTransform {
22532253

22542254
Sema &SemaRef;
22552255
ClassTemplateDecl *Template;
2256-
ClassTemplateDecl *NestedPattern = nullptr;
22572256

22582257
DeclContext *DC = Template->getDeclContext();
22592258
CXXRecordDecl *Primary = Template->getTemplatedDecl();
@@ -2333,9 +2332,6 @@ struct ConvertConstructorToDeductionGuideTransform {
23332332
Args.addOuterRetainedLevel();
23342333
}
23352334

2336-
if (NestedPattern)
2337-
Args.addOuterRetainedLevels(NestedPattern->getTemplateDepth());
2338-
23392335
FunctionProtoTypeLoc FPTL = CD->getTypeSourceInfo()->getTypeLoc()
23402336
.getAsAdjusted<FunctionProtoTypeLoc>();
23412337
assert(FPTL && "no prototype for constructor declaration");
@@ -2445,17 +2441,10 @@ struct ConvertConstructorToDeductionGuideTransform {
24452441
SmallVector<QualType, 4> ParamTypes;
24462442
const FunctionProtoType *T = TL.getTypePtr();
24472443

2448-
MultiLevelTemplateArgumentList OuterInstantiationArgs;
2449-
if (NestedPattern)
2450-
OuterInstantiationArgs = SemaRef.getTemplateInstantiationArgs(Template);
2451-
24522444
// -- The types of the function parameters are those of the constructor.
24532445
for (auto *OldParam : TL.getParams()) {
24542446
ParmVarDecl *NewParam =
24552447
transformFunctionTypeParam(OldParam, Args, MaterializedTypedefs);
2456-
if (NestedPattern && NewParam)
2457-
NewParam = transformFunctionTypeParam(NewParam, OuterInstantiationArgs,
2458-
MaterializedTypedefs);
24592448
if (!NewParam)
24602449
return QualType();
24612450
ParamTypes.push_back(NewParam->getType());
@@ -2661,24 +2650,13 @@ void Sema::DeclareImplicitDeductionGuides(TemplateDecl *Template,
26612650
if (BuildingDeductionGuides.isInvalid())
26622651
return;
26632652

2664-
// If the template is nested, then we need to use the original
2665-
// pattern to iterate over the constructors.
2666-
ClassTemplateDecl *Pattern = Transform.Template;
2667-
while (Pattern->getInstantiatedFromMemberTemplate()) {
2668-
if (Pattern->isMemberSpecialization())
2669-
break;
2670-
Pattern = Pattern->getInstantiatedFromMemberTemplate();
2671-
Transform.NestedPattern = Pattern;
2672-
}
2673-
26742653
// Convert declared constructors into deduction guide templates.
26752654
// FIXME: Skip constructors for which deduction must necessarily fail (those
26762655
// for which some class template parameter without a default argument never
26772656
// appears in a deduced context).
2678-
ContextRAII SavedContext(*this, Pattern->getTemplatedDecl());
26792657
llvm::SmallPtrSet<NamedDecl *, 8> ProcessedCtors;
26802658
bool AddedAny = false;
2681-
for (NamedDecl *D : LookupConstructors(Pattern->getTemplatedDecl())) {
2659+
for (NamedDecl *D : LookupConstructors(Transform.Primary)) {
26822660
D = D->getUnderlyingDecl();
26832661
if (D->isInvalidDecl() || D->isImplicit())
26842662
continue;
@@ -2724,8 +2702,6 @@ void Sema::DeclareImplicitDeductionGuides(TemplateDecl *Template,
27242702
Transform.buildSimpleDeductionGuide(Transform.DeducedType))
27252703
->getTemplatedDecl())
27262704
->setDeductionCandidateKind(DeductionCandidate::Copy);
2727-
2728-
SavedContext.pop();
27292705
}
27302706

27312707
/// Diagnose the presence of a default template argument on a

clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,10 @@ class StreamChecker : public Checker<check::PreCall, eval::Call,
238238

239239
private:
240240
CallDescriptionMap<FnDescription> FnDescriptions = {
241-
{{{"fopen"}}, {nullptr, &StreamChecker::evalFopen, ArgNone}},
241+
{{{"fopen"}, 2}, {nullptr, &StreamChecker::evalFopen, ArgNone}},
242242
{{{"freopen"}, 3},
243243
{&StreamChecker::preFreopen, &StreamChecker::evalFreopen, 2}},
244-
{{{"tmpfile"}}, {nullptr, &StreamChecker::evalFopen, ArgNone}},
244+
{{{"tmpfile"}, 0}, {nullptr, &StreamChecker::evalFopen, ArgNone}},
245245
{{{"fclose"}, 1},
246246
{&StreamChecker::preDefault, &StreamChecker::evalFclose, 0}},
247247
{{{"fread"}, 4},
@@ -1037,7 +1037,7 @@ StreamChecker::ensureStreamNonNull(SVal StreamVal, const Expr *StreamE,
10371037
ConstraintManager &CM = C.getConstraintManager();
10381038

10391039
ProgramStateRef StateNotNull, StateNull;
1040-
std::tie(StateNotNull, StateNull) = CM.assumeDual(C.getState(), *Stream);
1040+
std::tie(StateNotNull, StateNull) = CM.assumeDual(State, *Stream);
10411041

10421042
if (!StateNotNull && StateNull) {
10431043
if (ExplodedNode *N = C.generateErrorNode(StateNull)) {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %clang_analyze_cc1 -fno-builtin -analyzer-checker=core,alpha.unix.Stream -verify %s
2+
// expected-no-diagnostics
3+
4+
typedef struct _FILE FILE;
5+
6+
// These functions are not standard C library functions.
7+
FILE *tmpfile(const char *restrict path); // Real 'tmpfile' should have exactly 0 formal parameters.
8+
FILE *fopen(const char *restrict path); // Real 'fopen' should have exactly 2 formal parameters.
9+
10+
void test_fopen_non_posix(void) {
11+
FILE *fp = fopen("file"); // no-leak: This isn't the standard POSIX `fopen`, we don't know the semantics of this call.
12+
}
13+
14+
void test_tmpfile_non_posix(void) {
15+
FILE *fp = tmpfile("file"); // // no-leak: This isn't the standard POSIX `tmpfile`, we don't know the semantics of this call.
16+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// RUN: %clang_cc1 -triple loongarch64 -target-feature +f -target-feature +d -target-abi lp64d -emit-llvm %s -o - | \
2+
// RUN: FileCheck --check-prefix=CHECK-C %s
3+
// RUN: %clang_cc1 -triple loongarch64 -target-feature +f -target-feature +d -target-abi lp64d -emit-llvm %s -o - -x c++ | \
4+
// RUN: FileCheck --check-prefix=CHECK-CXX %s
5+
6+
#include <stdint.h>
7+
8+
// CHECK-C: define{{.*}} void @test1()
9+
// CHECK-CXX: define{{.*}} i64 @_Z5test12u1(i64{{[^,]*}})
10+
union u1 { };
11+
union u1 test1(union u1 a) {
12+
return a;
13+
}
14+
15+
struct s1 {
16+
union u1 u;
17+
int i;
18+
float f;
19+
};
20+
21+
// CHECK-C: define{{.*}} { i32, float } @test2(i32{{[^,]*}}, float{{[^,]*}})
22+
/// FIXME: This doesn't match g++.
23+
// CHECK-CXX: define{{.*}} { i32, float } @_Z5test22s1(i32{{[^,]*}}, float{{[^,]*}})
24+
struct s1 test2(struct s1 a) {
25+
return a;
26+
}

clang/test/CodeGen/arm64_32-vaarg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ long long test_longlong(OneLongLong input, va_list *mylist) {
2929
// CHECK-LABEL: define{{.*}} i64 @test_longlong(i64 %input
3030
// CHECK: [[STARTPTR:%.*]] = load ptr, ptr %mylist
3131
// CHECK: [[ALIGN_TMP:%.+]] = getelementptr inbounds i8, ptr [[STARTPTR]], i32 7
32-
// CHECK: [[ALIGNED_ADDR:%.+]] = tail call ptr @llvm.ptrmask.p0.i32(ptr nonnull [[ALIGN_TMP]], i32 -8)
32+
// CHECK: [[ALIGNED_ADDR:%.+]] = tail call align 8 ptr @llvm.ptrmask.p0.i32(ptr nonnull [[ALIGN_TMP]], i32 -8)
3333
// CHECK: [[NEXT:%.*]] = getelementptr inbounds i8, ptr [[ALIGNED_ADDR]], i32 8
3434
// CHECK: store ptr [[NEXT]], ptr %mylist
3535

0 commit comments

Comments
 (0)