Skip to content

Commit 5551074

Browse files
authored
Merge branch 'llvm:main' into gh-101657
2 parents 2a2d668 + f87a9db commit 5551074

File tree

25 files changed

+471
-211
lines changed

25 files changed

+471
-211
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,7 @@ Bug Fixes to C++ Support
886886
out of a module (which is the case e.g. in MSVC's implementation of ``std`` module). (#GH118218)
887887
- Fixed a pack expansion issue in checking unexpanded parameter sizes. (#GH17042)
888888
- Fixed a bug where captured structured bindings were modifiable inside non-mutable lambda (#GH95081)
889+
- Clang now identifies unexpanded parameter packs within the type constraint on a non-type template parameter. (#GH88866)
889890
- Fixed an issue while resolving type of expression indexing into a pack of values of non-dependent type (#GH121242)
890891

891892
Bug Fixes to AST Handling

clang/lib/AST/ASTContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6376,7 +6376,7 @@ ASTContext::getAutoType(QualType DeducedType, AutoTypeKeyword Keyword,
63766376
}
63776377

63786378
QualType ASTContext::getUnconstrainedType(QualType T) const {
6379-
QualType CanonT = T.getCanonicalType();
6379+
QualType CanonT = T.getNonPackExpansionType().getCanonicalType();
63806380

63816381
// Remove a type-constraint from a top-level auto or decltype(auto).
63826382
if (auto *AT = CanonT->getAs<AutoType>()) {

clang/lib/Sema/SemaInit.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2030,13 +2030,8 @@ canInitializeArrayWithEmbedDataString(ArrayRef<Expr *> ExprList,
20302030

20312031
if (InitType->isArrayType()) {
20322032
const ArrayType *InitArrayType = InitType->getAsArrayTypeUnsafe();
2033-
QualType InitElementTy = InitArrayType->getElementType();
2034-
QualType EmbedExprElementTy = EE->getDataStringLiteral()->getType();
2035-
const bool TypesMatch =
2036-
Context.typesAreCompatible(InitElementTy, EmbedExprElementTy) ||
2037-
(InitElementTy->isCharType() && EmbedExprElementTy->isCharType());
2038-
if (TypesMatch)
2039-
return true;
2033+
StringLiteral *SL = EE->getDataStringLiteral();
2034+
return IsStringInit(SL, InitArrayType, Context) == SIF_None;
20402035
}
20412036
return false;
20422037
}

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,7 +1228,7 @@ bool Sema::AttachTypeConstraint(AutoTypeLoc TL,
12281228
NonTypeTemplateParmDecl *NewConstrainedParm,
12291229
NonTypeTemplateParmDecl *OrigConstrainedParm,
12301230
SourceLocation EllipsisLoc) {
1231-
if (NewConstrainedParm->getType() != TL.getType() ||
1231+
if (NewConstrainedParm->getType().getNonPackExpansionType() != TL.getType() ||
12321232
TL.getAutoKeyword() != AutoTypeKeyword::Auto) {
12331233
Diag(NewConstrainedParm->getTypeSourceInfo()->getTypeLoc().getBeginLoc(),
12341234
diag::err_unsupported_placeholder_constraint)
@@ -1530,9 +1530,19 @@ NamedDecl *Sema::ActOnNonTypeTemplateParameter(Scope *S, Declarator &D,
15301530
Param->setAccess(AS_public);
15311531

15321532
if (AutoTypeLoc TL = TInfo->getTypeLoc().getContainedAutoTypeLoc())
1533-
if (TL.isConstrained())
1534-
if (AttachTypeConstraint(TL, Param, Param, D.getEllipsisLoc()))
1533+
if (TL.isConstrained()) {
1534+
if (D.getEllipsisLoc().isInvalid() &&
1535+
T->containsUnexpandedParameterPack()) {
1536+
assert(TL.getConceptReference()->getTemplateArgsAsWritten());
1537+
for (auto &Loc :
1538+
TL.getConceptReference()->getTemplateArgsAsWritten()->arguments())
1539+
Invalid |= DiagnoseUnexpandedParameterPack(
1540+
Loc, UnexpandedParameterPackContext::UPPC_TypeConstraint);
1541+
}
1542+
if (!Invalid &&
1543+
AttachTypeConstraint(TL, Param, Param, D.getEllipsisLoc()))
15351544
Invalid = true;
1545+
}
15361546

15371547
if (Invalid)
15381548
Param->setInvalidDecl();

clang/lib/Sema/SemaTemplateDeduction.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,10 @@ class PackDeductionScope {
857857
if (auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(
858858
TemplateParams->getParam(Index))) {
859859
if (!NTTP->isExpandedParameterPack())
860-
if (auto *Expansion = dyn_cast<PackExpansionType>(NTTP->getType()))
860+
// FIXME: CWG2982 suggests a type-constraint forms a non-deduced
861+
// context, however it is not yet resolved.
862+
if (auto *Expansion = dyn_cast<PackExpansionType>(
863+
S.Context.getUnconstrainedType(NTTP->getType())))
861864
ExtraDeductions.push_back(Expansion->getPattern());
862865
}
863866
// FIXME: Also collect the unexpanded packs in any type and template

clang/test/Analysis/embed.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ int main() {
88
#embed "embed.c"
99
};
1010
clang_analyzer_dump_ptr(SelfBytes); // expected-warning {{&Element{SelfBytes,0 S64b,unsigned char}}}
11-
clang_analyzer_dump(SelfBytes[0]); // expected-warning {{Unknown}} FIXME: This should be the `/` character.
11+
clang_analyzer_dump(SelfBytes[0]); // expected-warning {{47 U8b}}
1212
}

clang/test/OpenMP/irbuilder_simd_aligned.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,11 @@ void simple(float *a, float *b, int *c) {
7070
// CHECK-NEXT: br label [[FOR_COND]], !llvm.loop [[LOOP3:![0-9]+]]
7171
// CHECK: for.end:
7272
// CHECK-NEXT: [[TMP4:%.*]] = load ptr, ptr [[A_ADDR]], align 8
73+
// CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(ptr [[TMP4]], i64 128) ]
7374
// CHECK-NEXT: [[TMP5:%.*]] = load ptr, ptr [[P]], align 8
75+
// CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(ptr [[TMP5]], i64 64) ]
7476
// CHECK-NEXT: [[ARRAYDECAY:%.*]] = getelementptr inbounds [32 x i32], ptr [[D]], i64 0, i64 0
77+
// CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(ptr [[ARRAYDECAY]], i64 16) ]
7578
// CHECK-NEXT: store i32 3, ptr [[I1]], align 4
7679
// CHECK-NEXT: [[TMP6:%.*]] = getelementptr inbounds nuw [[STRUCT_ANON]], ptr [[AGG_CAPTURED]], i32 0, i32 0
7780
// CHECK-NEXT: store ptr [[I1]], ptr [[TMP6]], align 8
@@ -82,9 +85,6 @@ void simple(float *a, float *b, int *c) {
8285
// CHECK-NEXT: [[DOTCOUNT:%.*]] = load i32, ptr [[DOTCOUNT_ADDR]], align 4
8386
// CHECK-NEXT: br label [[OMP_LOOP_PREHEADER:%.*]]
8487
// CHECK: omp_loop.preheader:
85-
// CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(ptr [[TMP4]], i64 128) ]
86-
// CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(ptr [[TMP5]], i64 64) ]
87-
// CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(ptr [[ARRAYDECAY]], i64 16) ]
8888
// CHECK-NEXT: br label [[OMP_LOOP_HEADER:%.*]]
8989
// CHECK: omp_loop.header:
9090
// CHECK-NEXT: [[OMP_LOOP_IV:%.*]] = phi i32 [ 0, [[OMP_LOOP_PREHEADER]] ], [ [[OMP_LOOP_NEXT:%.*]], [[OMP_LOOP_INC:%.*]] ]

clang/test/SemaCXX/cxx2c-fold-exprs.cpp

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,3 +305,82 @@ static_assert(__is_same_as(_Three_way_comparison_result_with_tuple_like<tuple<in
305305
static_assert(__is_same_as(_Three_way_comparison_result_with_tuple_like<tuple<int>, 0>::type, long));
306306

307307
}
308+
309+
namespace GH88866 {
310+
311+
template <typename...Ts> struct index_by;
312+
313+
template <typename T, typename Indices>
314+
concept InitFunc = true;
315+
316+
namespace ExpandsBoth {
317+
318+
template <typename Indices, InitFunc<Indices> auto... init>
319+
struct LazyLitMatrix; // expected-note {{here}}
320+
321+
template <
322+
typename...Indices,
323+
InitFunc<index_by<Indices>> auto... init
324+
>
325+
struct LazyLitMatrix<index_by<Indices...>, init...> {
326+
};
327+
328+
// FIXME: Explain why we didn't pick up the partial specialization - pack sizes don't match.
329+
template struct LazyLitMatrix<index_by<int, char>, 42>;
330+
// expected-error@-1 {{instantiation of undefined template}}
331+
template struct LazyLitMatrix<index_by<int, char>, 42, 43>;
332+
333+
}
334+
335+
namespace ExpandsRespectively {
336+
337+
template <typename Indices, InitFunc<Indices> auto... init>
338+
struct LazyLitMatrix;
339+
340+
template <
341+
typename...Indices,
342+
InitFunc<index_by<Indices...>> auto... init
343+
>
344+
struct LazyLitMatrix<index_by<Indices...>, init...> {
345+
};
346+
347+
template struct LazyLitMatrix<index_by<int, char>, 42>;
348+
template struct LazyLitMatrix<index_by<int, char>, 42, 43>;
349+
350+
}
351+
352+
namespace TypeParameter {
353+
354+
template <typename Indices, InitFunc<Indices>... init>
355+
struct LazyLitMatrix; // expected-note {{here}}
356+
357+
template <
358+
typename...Indices,
359+
InitFunc<index_by<Indices>>... init
360+
>
361+
struct LazyLitMatrix<index_by<Indices...>, init...> {
362+
};
363+
364+
// FIXME: Explain why we didn't pick up the partial specialization - pack sizes don't match.
365+
template struct LazyLitMatrix<index_by<int, char>, float>;
366+
// expected-error@-1 {{instantiation of undefined template}}
367+
template struct LazyLitMatrix<index_by<int, char>, unsigned, float>;
368+
369+
}
370+
371+
namespace Invalid {
372+
373+
template <typename Indices, InitFunc<Indices>... init>
374+
struct LazyLitMatrix;
375+
376+
template <
377+
typename...Indices,
378+
InitFunc<index_by<Indices>> init
379+
// expected-error@-1 {{unexpanded parameter pack 'Indices'}}
380+
>
381+
struct LazyLitMatrix<index_by<Indices...>, init> {
382+
};
383+
384+
}
385+
386+
}

compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,17 @@ INTERCEPTOR(FILE *, fdopen, int fd, const char *mode) {
297297
return REAL(fdopen)(fd, mode);
298298
}
299299

300+
#if SANITIZER_INTERCEPT_FOPENCOOKIE
301+
INTERCEPTOR(FILE *, fopencookie, void *cookie, const char *mode,
302+
cookie_io_functions_t funcs) {
303+
__rtsan_notify_intercepted_call("fopencookie");
304+
return REAL(fopencookie)(cookie, mode, funcs);
305+
}
306+
#define RTSAN_MAYBE_INTERCEPT_FOPENCOOKIE INTERCEPT_FUNCTION(fopencookie)
307+
#else
308+
#define RTSAN_MAYBE_INTERCEPT_FOPENCOOKIE
309+
#endif
310+
300311
#if SANITIZER_INTERCEPT_OPEN_MEMSTREAM
301312
INTERCEPTOR(FILE *, open_memstream, char **buf, size_t *size) {
302313
__rtsan_notify_intercepted_call("open_memstream");
@@ -972,6 +983,7 @@ void __rtsan::InitializeInterceptors() {
972983
INTERCEPT_FUNCTION(fputs);
973984
INTERCEPT_FUNCTION(fdopen);
974985
INTERCEPT_FUNCTION(freopen);
986+
RTSAN_MAYBE_INTERCEPT_FOPENCOOKIE;
975987
RTSAN_MAYBE_INTERCEPT_OPEN_MEMSTREAM;
976988
RTSAN_MAYBE_INTERCEPT_FMEMOPEN;
977989
INTERCEPT_FUNCTION(lseek);

compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,31 @@ TEST_F(RtsanFileTest, FopenDiesWhenRealtime) {
353353
ExpectNonRealtimeSurvival(Func);
354354
}
355355

356+
#if SANITIZER_INTERCEPT_FOPENCOOKIE
357+
TEST_F(RtsanFileTest, FopenCookieDieWhenRealtime) {
358+
FILE *f = fopen(GetTemporaryFilePath(), "w");
359+
EXPECT_THAT(f, Ne(nullptr));
360+
struct fholder {
361+
FILE *fp;
362+
size_t read;
363+
} fh = {f, 0};
364+
auto CookieRead = [this](void *cookie, char *buf, size_t size) {
365+
fholder *p = reinterpret_cast<fholder *>(cookie);
366+
p->read = fread(static_cast<void *>(buf), 1, size, p->fp);
367+
EXPECT_NE(0, p->read);
368+
};
369+
cookie_io_functions_t funcs = {(cookie_read_function_t *)&CookieRead, nullptr,
370+
nullptr, nullptr};
371+
auto Func = [&fh, &funcs]() {
372+
FILE *f = fopencookie(&fh, "w", funcs);
373+
EXPECT_THAT(f, Ne(nullptr));
374+
};
375+
376+
ExpectRealtimeDeath(Func, "fopencookie");
377+
ExpectNonRealtimeSurvival(Func);
378+
}
379+
#endif
380+
356381
#if SANITIZER_INTERCEPT_OPEN_MEMSTREAM
357382
TEST_F(RtsanFileTest, OpenMemstreamDiesWhenRealtime) {
358383
char *buffer;

0 commit comments

Comments
 (0)