Skip to content

Commit 9deb7bf

Browse files
committed
Merge branch 'main' of https://github.com/llvm/llvm-project into weiweic/make-mmiwp-mmi-unique-ptr
2 parents 6186520 + 3b80a28 commit 9deb7bf

File tree

54 files changed

+1412
-713
lines changed

Some content is hidden

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

54 files changed

+1412
-713
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ C++ Specific Potentially Breaking Changes
7373
template <> // error: extraneous template head
7474
template <typename T>
7575
void f();
76-
76+
7777
ABI Changes in This Version
7878
---------------------------
7979

@@ -273,6 +273,7 @@ Bug Fixes to C++ Support
273273
- Properly reject defaulted copy/move assignment operators that have a non-reference explicit object parameter.
274274
- Clang now properly handles the order of attributes in `extern` blocks. (#GH101990).
275275
- Fixed an assertion failure by preventing null explicit object arguments from being deduced. (#GH102025).
276+
- Correctly check constraints of explicit instantiations of member functions. (#GH46029)
276277

277278
Bug Fixes to AST Handling
278279
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/Analysis/FlowSensitive/ASTOps.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ struct ReferencedDecls {
139139
/// All variables with static storage duration, notably including static
140140
/// member variables and static variables declared within a function.
141141
llvm::DenseSet<const VarDecl *> Globals;
142+
/// Local variables, not including parameters or static variables declared
143+
/// within a function.
144+
llvm::DenseSet<const VarDecl *> Locals;
142145
/// Free functions and member functions which are referenced (but not
143146
/// necessarily called).
144147
llvm::DenseSet<const FunctionDecl *> Functions;

clang/include/clang/Basic/BuiltinsNVPTX.def

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,21 @@ TARGET_BUILTIN(__nvvm_f2bf16_rz_relu, "yf", "", AND(SM_80,PTX70))
584584

585585
TARGET_BUILTIN(__nvvm_f2tf32_rna, "ZUif", "", AND(SM_80,PTX70))
586586

587+
TARGET_BUILTIN(__nvvm_ff_to_e4m3x2_rn, "sff", "", AND(SM_89,PTX81))
588+
TARGET_BUILTIN(__nvvm_ff_to_e4m3x2_rn_relu, "sff", "", AND(SM_89,PTX81))
589+
TARGET_BUILTIN(__nvvm_ff_to_e5m2x2_rn, "sff", "", AND(SM_89,PTX81))
590+
TARGET_BUILTIN(__nvvm_ff_to_e5m2x2_rn_relu, "sff", "", AND(SM_89,PTX81))
591+
592+
TARGET_BUILTIN(__nvvm_f16x2_to_e4m3x2_rn, "sV2h", "", AND(SM_89,PTX81))
593+
TARGET_BUILTIN(__nvvm_f16x2_to_e4m3x2_rn_relu, "sV2h", "", AND(SM_89,PTX81))
594+
TARGET_BUILTIN(__nvvm_f16x2_to_e5m2x2_rn, "sV2h", "", AND(SM_89,PTX81))
595+
TARGET_BUILTIN(__nvvm_f16x2_to_e5m2x2_rn_relu, "sV2h", "", AND(SM_89,PTX81))
596+
597+
TARGET_BUILTIN(__nvvm_e4m3x2_to_f16x2_rn, "V2hs", "", AND(SM_89,PTX81))
598+
TARGET_BUILTIN(__nvvm_e4m3x2_to_f16x2_rn_relu, "V2hs", "", AND(SM_89,PTX81))
599+
TARGET_BUILTIN(__nvvm_e5m2x2_to_f16x2_rn, "V2hs", "", AND(SM_89,PTX81))
600+
TARGET_BUILTIN(__nvvm_e5m2x2_to_f16x2_rn_relu, "V2hs", "", AND(SM_89,PTX81))
601+
587602
// Bitcast
588603

589604
BUILTIN(__nvvm_bitcast_f2i, "if", "")

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5667,6 +5667,8 @@ def err_explicit_instantiation_internal_linkage : Error<
56675667
def err_explicit_instantiation_not_known : Error<
56685668
"explicit instantiation of %0 does not refer to a function template, "
56695669
"variable template, member function, member class, or static data member">;
5670+
def err_explicit_instantiation_no_candidate : Error<
5671+
"no viable candidate for explicit instantiation of %0">;
56705672
def note_explicit_instantiation_here : Note<
56715673
"explicit instantiation refers here">;
56725674
def err_explicit_instantiation_data_member_not_instantiated : Error<

clang/lib/Analysis/FlowSensitive/ASTOps.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,13 @@ static void insertIfGlobal(const Decl &D,
170170
Globals.insert(V);
171171
}
172172

173+
static void insertIfLocal(const Decl &D,
174+
llvm::DenseSet<const VarDecl *> &Locals) {
175+
if (auto *V = dyn_cast<VarDecl>(&D))
176+
if (V->hasLocalStorage() && !isa<ParmVarDecl>(V))
177+
Locals.insert(V);
178+
}
179+
173180
static void insertIfFunction(const Decl &D,
174181
llvm::DenseSet<const FunctionDecl *> &Funcs) {
175182
if (auto *FD = dyn_cast<FunctionDecl>(&D))
@@ -220,12 +227,14 @@ class ReferencedDeclsVisitor
220227

221228
bool VisitDecl(Decl *D) {
222229
insertIfGlobal(*D, Referenced.Globals);
230+
insertIfLocal(*D, Referenced.Locals);
223231
insertIfFunction(*D, Referenced.Functions);
224232
return true;
225233
}
226234

227235
bool VisitDeclRefExpr(DeclRefExpr *E) {
228236
insertIfGlobal(*E->getDecl(), Referenced.Globals);
237+
insertIfLocal(*E->getDecl(), Referenced.Locals);
229238
insertIfFunction(*E->getDecl(), Referenced.Functions);
230239
return true;
231240
}

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10124,8 +10124,9 @@ DeclResult Sema::ActOnExplicitInstantiation(Scope *S,
1012410124
// instantiated from the member definition associated with its class
1012510125
// template.
1012610126
UnresolvedSet<8> TemplateMatches;
10127-
FunctionDecl *NonTemplateMatch = nullptr;
10128-
TemplateSpecCandidateSet FailedCandidates(D.getIdentifierLoc());
10127+
OverloadCandidateSet NonTemplateMatches(D.getBeginLoc(),
10128+
OverloadCandidateSet::CSK_Normal);
10129+
TemplateSpecCandidateSet FailedTemplateCandidates(D.getIdentifierLoc());
1012910130
for (LookupResult::iterator P = Previous.begin(), PEnd = Previous.end();
1013010131
P != PEnd; ++P) {
1013110132
NamedDecl *Prev = *P;
@@ -10137,9 +10138,18 @@ DeclResult Sema::ActOnExplicitInstantiation(Scope *S,
1013710138
if (Method->getPrimaryTemplate()) {
1013810139
TemplateMatches.addDecl(Method, P.getAccess());
1013910140
} else {
10140-
// FIXME: Can this assert ever happen? Needs a test.
10141-
assert(!NonTemplateMatch && "Multiple NonTemplateMatches");
10142-
NonTemplateMatch = Method;
10141+
OverloadCandidate &C = NonTemplateMatches.addCandidate();
10142+
C.FoundDecl = P.getPair();
10143+
C.Function = Method;
10144+
C.Viable = true;
10145+
ConstraintSatisfaction S;
10146+
if (Method->getTrailingRequiresClause() &&
10147+
(CheckFunctionConstraints(Method, S, D.getIdentifierLoc(),
10148+
/*ForOverloadResolution=*/true) ||
10149+
!S.IsSatisfied)) {
10150+
C.Viable = false;
10151+
C.FailureKind = ovl_fail_constraints_not_satisfied;
10152+
}
1014310153
}
1014410154
}
1014510155
}
@@ -10149,16 +10159,16 @@ DeclResult Sema::ActOnExplicitInstantiation(Scope *S,
1014910159
if (!FunTmpl)
1015010160
continue;
1015110161

10152-
TemplateDeductionInfo Info(FailedCandidates.getLocation());
10162+
TemplateDeductionInfo Info(FailedTemplateCandidates.getLocation());
1015310163
FunctionDecl *Specialization = nullptr;
1015410164
if (TemplateDeductionResult TDK = DeduceTemplateArguments(
1015510165
FunTmpl, (HasExplicitTemplateArgs ? &TemplateArgs : nullptr), R,
1015610166
Specialization, Info);
1015710167
TDK != TemplateDeductionResult::Success) {
1015810168
// Keep track of almost-matches.
10159-
FailedCandidates.addCandidate()
10160-
.set(P.getPair(), FunTmpl->getTemplatedDecl(),
10161-
MakeDeductionFailureInfo(Context, TDK, Info));
10169+
FailedTemplateCandidates.addCandidate().set(
10170+
P.getPair(), FunTmpl->getTemplatedDecl(),
10171+
MakeDeductionFailureInfo(Context, TDK, Info));
1016210172
(void)TDK;
1016310173
continue;
1016410174
}
@@ -10172,7 +10182,7 @@ DeclResult Sema::ActOnExplicitInstantiation(Scope *S,
1017210182
CUDA().IdentifyTarget(Specialization,
1017310183
/* IgnoreImplicitHDAttr = */ true) !=
1017410184
CUDA().IdentifyTarget(D.getDeclSpec().getAttributes())) {
10175-
FailedCandidates.addCandidate().set(
10185+
FailedTemplateCandidates.addCandidate().set(
1017610186
P.getPair(), FunTmpl->getTemplatedDecl(),
1017710187
MakeDeductionFailureInfo(
1017810188
Context, TemplateDeductionResult::CUDATargetMismatch, Info));
@@ -10182,12 +10192,40 @@ DeclResult Sema::ActOnExplicitInstantiation(Scope *S,
1018210192
TemplateMatches.addDecl(Specialization, P.getAccess());
1018310193
}
1018410194

10185-
FunctionDecl *Specialization = NonTemplateMatch;
10195+
FunctionDecl *Specialization = nullptr;
10196+
if (!NonTemplateMatches.empty()) {
10197+
unsigned Msg = 0;
10198+
OverloadCandidateDisplayKind DisplayKind;
10199+
OverloadCandidateSet::iterator Best;
10200+
switch (NonTemplateMatches.BestViableFunction(*this, D.getIdentifierLoc(),
10201+
Best)) {
10202+
case OR_Success:
10203+
case OR_Deleted:
10204+
Specialization = cast<FunctionDecl>(Best->Function);
10205+
break;
10206+
case OR_Ambiguous:
10207+
Msg = diag::err_explicit_instantiation_ambiguous;
10208+
DisplayKind = OCD_AmbiguousCandidates;
10209+
break;
10210+
case OR_No_Viable_Function:
10211+
Msg = diag::err_explicit_instantiation_no_candidate;
10212+
DisplayKind = OCD_AllCandidates;
10213+
break;
10214+
}
10215+
if (Msg) {
10216+
PartialDiagnostic Diag = PDiag(Msg) << Name;
10217+
NonTemplateMatches.NoteCandidates(
10218+
PartialDiagnosticAt(D.getIdentifierLoc(), Diag), *this, DisplayKind,
10219+
{});
10220+
return true;
10221+
}
10222+
}
10223+
1018610224
if (!Specialization) {
1018710225
// Find the most specialized function template specialization.
1018810226
UnresolvedSetIterator Result = getMostSpecialized(
10189-
TemplateMatches.begin(), TemplateMatches.end(), FailedCandidates,
10190-
D.getIdentifierLoc(),
10227+
TemplateMatches.begin(), TemplateMatches.end(),
10228+
FailedTemplateCandidates, D.getIdentifierLoc(),
1019110229
PDiag(diag::err_explicit_instantiation_not_known) << Name,
1019210230
PDiag(diag::err_explicit_instantiation_ambiguous) << Name,
1019310231
PDiag(diag::note_explicit_instantiation_candidate));

clang/test/CodeGen/builtins-nvptx.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
// RUN: %clang_cc1 -ffp-contract=off -triple nvptx64-unknown-unknown -target-cpu sm_86 -target-feature +ptx72 \
2323
// RUN: -fcuda-is-device -emit-llvm -o - -x cuda %s \
2424
// RUN: | FileCheck -check-prefix=CHECK -check-prefix=CHECK_PTX72_SM86 -check-prefix=LP64 %s
25+
// RUN: %clang_cc1 -ffp-contract=off -triple nvptx64-unknown-unknown -target-cpu sm_89 -target-feature +ptx81 \
26+
// RUN: -fcuda-is-device -emit-llvm -o - -x cuda %s \
27+
// RUN: | FileCheck -check-prefix=CHECK -check-prefix=CHECK_PTX81_SM89 %s
2528

2629
#define __device__ __attribute__((device))
2730
#define __global__ __attribute__((global))
@@ -968,6 +971,39 @@ __device__ void nvvm_cvt_sm80() {
968971
// CHECK: ret void
969972
}
970973

974+
// CHECK-LABEL: nvvm_cvt_sm89
975+
__device__ void nvvm_cvt_sm89() {
976+
#if __CUDA_ARCH__ >= 890
977+
// CHECK_PTX81_SM89: call i16 @llvm.nvvm.ff.to.e4m3x2.rn(float 1.000000e+00, float 1.000000e+00)
978+
__nvvm_ff_to_e4m3x2_rn(1.0f, 1.0f);
979+
// CHECK_PTX81_SM89: call i16 @llvm.nvvm.ff.to.e4m3x2.rn.relu(float 1.000000e+00, float 1.000000e+00)
980+
__nvvm_ff_to_e4m3x2_rn_relu(1.0f, 1.0f);
981+
// CHECK_PTX81_SM89: call i16 @llvm.nvvm.ff.to.e5m2x2.rn(float 1.000000e+00, float 1.000000e+00)
982+
__nvvm_ff_to_e5m2x2_rn(1.0f, 1.0f);
983+
// CHECK_PTX81_SM89: call i16 @llvm.nvvm.ff.to.e5m2x2.rn.relu(float 1.000000e+00, float 1.000000e+00)
984+
__nvvm_ff_to_e5m2x2_rn_relu(1.0f, 1.0f);
985+
986+
// CHECK_PTX81_SM89: call i16 @llvm.nvvm.f16x2.to.e4m3x2.rn(<2 x half> <half 0xH3C00, half 0xH3C00>)
987+
__nvvm_f16x2_to_e4m3x2_rn({1.0f16, 1.0f16});
988+
// CHECK_PTX81_SM89: call i16 @llvm.nvvm.f16x2.to.e4m3x2.rn.relu(<2 x half> <half 0xH3C00, half 0xH3C00>)
989+
__nvvm_f16x2_to_e4m3x2_rn_relu({1.0f16, 1.0f16});
990+
// CHECK_PTX81_SM89: call i16 @llvm.nvvm.f16x2.to.e5m2x2.rn(<2 x half> <half 0xH3C00, half 0xH3C00>)
991+
__nvvm_f16x2_to_e5m2x2_rn({1.0f16, 1.0f16});
992+
// CHECK_PTX81_SM89: call i16 @llvm.nvvm.f16x2.to.e5m2x2.rn.relu(<2 x half> <half 0xH3C00, half 0xH3C00>)
993+
__nvvm_f16x2_to_e5m2x2_rn_relu({1.0f16, 1.0f16});
994+
995+
// CHECK_PTX81_SM89: call <2 x half> @llvm.nvvm.e4m3x2.to.f16x2.rn(i16 18504)
996+
__nvvm_e4m3x2_to_f16x2_rn(0x4848);
997+
// CHECK_PTX81_SM89: call <2 x half> @llvm.nvvm.e4m3x2.to.f16x2.rn.relu(i16 18504)
998+
__nvvm_e4m3x2_to_f16x2_rn_relu(0x4848);
999+
// CHECK_PTX81_SM89: call <2 x half> @llvm.nvvm.e5m2x2.to.f16x2.rn(i16 19532)
1000+
__nvvm_e5m2x2_to_f16x2_rn(0x4c4c);
1001+
// CHECK_PTX81_SM89: call <2 x half> @llvm.nvvm.e5m2x2.to.f16x2.rn.relu(i16 19532)
1002+
__nvvm_e5m2x2_to_f16x2_rn_relu(0x4c4c);
1003+
#endif
1004+
// CHECK: ret void
1005+
}
1006+
9711007
#define NAN32 0x7FBFFFFF
9721008
#define NAN16 (__bf16)0x7FBF
9731009
#define BF16 (__bf16)0.1f
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
2+
3+
template<class T>
4+
concept C = true;
5+
6+
template<class T>
7+
concept D = C<T> && true;
8+
9+
template<typename T>
10+
struct a {
11+
void no_candidate() requires(false) {}
12+
// expected-note@-1 {{candidate function not viable: constraints not satisfied}} \
13+
// expected-note@-1 {{because 'false' evaluated to false}}
14+
void no_candidate() requires(false && false) {}
15+
// expected-note@-1 {{candidate function not viable: constraints not satisfied}} \
16+
// expected-note@-1 {{because 'false' evaluated to false}}
17+
18+
void subsumes();
19+
void subsumes() requires C<T>;
20+
void subsumes() requires D<T> {};
21+
22+
void ok() requires false;
23+
void ok() requires true {};
24+
25+
void ok2() requires false;
26+
void ok2(){};
27+
28+
void ambiguous() requires true;
29+
// expected-note@-1 {{candidate function}}
30+
void ambiguous() requires C<T>;
31+
// expected-note@-1 {{candidate function}}
32+
};
33+
template void a<int>::no_candidate();
34+
// expected-error@-1 {{no viable candidate for explicit instantiation of 'no_candidate'}}
35+
36+
template void a<int>::ambiguous();
37+
// expected-error@-1 {{partial ordering for explicit instantiation of 'ambiguous' is ambiguous}}
38+
39+
template void a<int>::ok();
40+
template void a<int>::ok2();

clang/unittests/Analysis/FlowSensitive/ASTOpsTest.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,26 @@ TEST(ASTOpsTest, ReferencedDeclsOnUnionInitList) {
8585
UnorderedElementsAre(IDecl));
8686
}
8787

88+
TEST(ASTOpsTest, ReferencedDeclsLocalsNotParamsOrStatics) {
89+
std::string Code = R"cc(
90+
void func(int Param) {
91+
static int Static = 0;
92+
int Local = Param;
93+
Local = Static;
94+
}
95+
)cc";
96+
std::unique_ptr<ASTUnit> Unit =
97+
tooling::buildASTFromCodeWithArgs(Code, {"-fsyntax-only", "-std=c++17"});
98+
auto &ASTCtx = Unit->getASTContext();
99+
100+
ASSERT_EQ(ASTCtx.getDiagnostics().getClient()->getNumErrors(), 0U);
101+
102+
auto *Func = cast<FunctionDecl>(findValueDecl(ASTCtx, "func"));
103+
ASSERT_NE(Func, nullptr);
104+
auto *LocalDecl = cast<VarDecl>(findValueDecl(ASTCtx, "Local"));
105+
106+
EXPECT_THAT(getReferencedDecls(*Func).Locals,
107+
UnorderedElementsAre(LocalDecl));
108+
}
109+
88110
} // namespace

compiler-rt/lib/asan/asan_allocator.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,13 @@ const uptr kAllocatorSize = 0x40000000000ULL; // 4T.
189189
typedef DefaultSizeClassMap SizeClassMap;
190190
# endif // SANITIZER_RISCV64
191191
# else // SANITIZER_FUCHSIA
192+
193+
# if SANITIZER_APPLE
194+
const uptr kAllocatorSpace = 0x600000000000ULL;
195+
# else // SANITIZER_APPLE
192196
const uptr kAllocatorSpace = ~(uptr)0;
197+
# endif // SANITIZER_APPLE
198+
193199
# if defined(__powerpc64__)
194200
const uptr kAllocatorSize = 0x20000000000ULL; // 2T.
195201
typedef DefaultSizeClassMap SizeClassMap;

compiler-rt/test/nsan/stable_sort.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// RUN: %clangxx_nsan -O2 -g %s -o %t
2+
// RUN: %run %t 2>&1 | FileCheck %s
3+
4+
// Check compilation mode that is required to call memcpy/memmove.
5+
// RUN: %clangxx_nsan -fno-builtin -O2 -g %s -o %t
6+
// RUN: %run %t 2>&1 | FileCheck %s
7+
8+
// This tests a particularaly hard case of memory tracking. stable_sort does
9+
// conditional swaps of pairs of elements with mixed types (int/double).
10+
11+
#include <algorithm>
12+
#include <cstddef>
13+
#include <cstdio>
14+
#include <utility>
15+
#include <vector>
16+
17+
extern "C" void __nsan_dump_shadow_mem(const char *addr, size_t size_bytes,
18+
size_t bytes_per_line, size_t reserved);
19+
20+
__attribute__((noinline)) void Run(std::vector<int> &indices,
21+
std::vector<double> &values) {
22+
const auto num_entries = indices.size();
23+
std::vector<std::pair<int, double>> entries;
24+
entries.reserve(num_entries);
25+
for (size_t i = 0; i < num_entries; ++i)
26+
entries.emplace_back(indices[i], values[i]);
27+
28+
__nsan_dump_shadow_mem((const char *)&entries[0].second, sizeof(double),
29+
sizeof(double), 0);
30+
__nsan_dump_shadow_mem((const char *)&entries[1].second, sizeof(double),
31+
sizeof(double), 0);
32+
// CHECK: {{.*}}: d0 d1 d2 d3 d4 d5 d6 d7 (1.02800000000000002487)
33+
// CHECK-NEXT: {{.*}}: d0 d1 d2 d3 d4 d5 d6 d7 (7.95099999999999962341)
34+
std::stable_sort(
35+
entries.begin(), entries.end(),
36+
[](const std::pair<int, double> &a, const std::pair<int, double> &b) {
37+
return a.first < b.first;
38+
});
39+
__nsan_dump_shadow_mem((const char *)&entries[0].second, sizeof(double),
40+
sizeof(double), 0);
41+
__nsan_dump_shadow_mem((const char *)&entries[1].second, sizeof(double),
42+
sizeof(double), 0);
43+
// We make sure that the shadow values have been swapped correctly.
44+
// CHECK-NEXT: {{.*}}: d0 d1 d2 d3 d4 d5 d6 d7 (7.95099999999999962341)
45+
// CHECK-NEXT: {{.*}}: d0 d1 d2 d3 d4 d5 d6 d7 (1.02800000000000002487)
46+
}
47+
48+
int main() {
49+
std::vector<int> indices;
50+
std::vector<double> values;
51+
indices.push_back(75);
52+
values.push_back(1.028);
53+
indices.push_back(74);
54+
values.push_back(7.951);
55+
Run(indices, values);
56+
}

0 commit comments

Comments
 (0)