Skip to content

Commit 599be57

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:f7f7574afe4cfc11ebe5d8cb811d5cd28dc862f6 into amd-gfx:1656d3862359
Local branch amd-gfx 1656d38 Merged main:567941bcc3b1fc3b1d2a902cf7ae2e173247a45f into amd-gfx:11905d93bff7 Remote branch main f7f7574 [InstCombine] Canonicalize `switch(C-X)` to `switch(X)` (llvm#77051)
2 parents 1656d38 + f7f7574 commit 599be57

File tree

174 files changed

+923
-556
lines changed

Some content is hidden

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

174 files changed

+923
-556
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,9 @@ Bug Fixes in This Version
692692
Fixes (`#64347 <https://github.com/llvm/llvm-project/issues/64347>`_)
693693
- Fix crash when using C++ only tokens like ``::`` in C compiler clang.
694694
Fixes (`#73559 <https://github.com/llvm/llvm-project/issues/73559>`_)
695+
- Clang now accepts recursive non-dependent calls to functions with deduced
696+
return type.
697+
Fixes (`#71015 <https://github.com/llvm/llvm-project/issues/71015>`_)
695698

696699

697700
Bug Fixes to Compiler Builtins
@@ -720,7 +723,8 @@ Bug Fixes to C++ Support
720723

721724
- Clang emits an error on substitution failure within lambda body inside a
722725
requires-expression. This fixes:
723-
(`#64138 <https://github.com/llvm/llvm-project/issues/64138>`_).
726+
(`#64138 <https://github.com/llvm/llvm-project/issues/64138>`_) and
727+
(`#71684 <https://github.com/llvm/llvm-project/issues/71684>`_).
724728

725729
- Update ``FunctionDeclBitfields.NumFunctionDeclBits``. This fixes:
726730
(`#64171 <https://github.com/llvm/llvm-project/issues/64171>`_).

clang/lib/AST/ASTStructuralEquivalence.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,8 +1463,9 @@ IsStructurallyEquivalentLambdas(StructuralEquivalenceContext &Context,
14631463
}
14641464

14651465
/// Determine if context of a class is equivalent.
1466-
static bool IsRecordContextStructurallyEquivalent(RecordDecl *D1,
1467-
RecordDecl *D2) {
1466+
static bool
1467+
IsRecordContextStructurallyEquivalent(StructuralEquivalenceContext &Context,
1468+
RecordDecl *D1, RecordDecl *D2) {
14681469
// The context should be completely equal, including anonymous and inline
14691470
// namespaces.
14701471
// We compare objects as part of full translation units, not subtrees of
@@ -1491,6 +1492,12 @@ static bool IsRecordContextStructurallyEquivalent(RecordDecl *D1,
14911492
return false;
14921493
}
14931494

1495+
if (auto *D1Spec = dyn_cast<ClassTemplateSpecializationDecl>(DC1)) {
1496+
auto *D2Spec = dyn_cast<ClassTemplateSpecializationDecl>(DC2);
1497+
if (!IsStructurallyEquivalent(Context, D1Spec, D2Spec))
1498+
return false;
1499+
}
1500+
14941501
DC1 = DC1->getParent()->getNonTransparentContext();
14951502
DC2 = DC2->getParent()->getNonTransparentContext();
14961503
}
@@ -1544,7 +1551,7 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
15441551
// If the records occur in different context (namespace), these should be
15451552
// different. This is specially important if the definition of one or both
15461553
// records is missing.
1547-
if (!IsRecordContextStructurallyEquivalent(D1, D2))
1554+
if (!IsRecordContextStructurallyEquivalent(Context, D1, D2))
15481555
return false;
15491556

15501557
// If both declarations are class template specializations, we know

clang/lib/AST/ComputeDependence.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,8 @@ ExprDependence clang::computeDependence(PredefinedExpr *E) {
603603
ExprDependence clang::computeDependence(CallExpr *E,
604604
llvm::ArrayRef<Expr *> PreArgs) {
605605
auto D = E->getCallee()->getDependence();
606+
if (E->getType()->isDependentType())
607+
D |= ExprDependence::Type;
606608
for (auto *A : llvm::ArrayRef(E->getArgs(), E->getNumArgs())) {
607609
if (A)
608610
D |= A->getDependence();

clang/lib/Sema/SemaOverload.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13994,6 +13994,24 @@ ExprResult Sema::BuildOverloadedCallExpr(Scope *S, Expr *Fn,
1399413994
OverloadCandidateSet::iterator Best;
1399513995
OverloadingResult OverloadResult =
1399613996
CandidateSet.BestViableFunction(*this, Fn->getBeginLoc(), Best);
13997+
FunctionDecl *FDecl = Best->Function;
13998+
13999+
// Model the case with a call to a templated function whose definition
14000+
// encloses the call and whose return type contains a placeholder type as if
14001+
// the UnresolvedLookupExpr was type-dependent.
14002+
if (OverloadResult == OR_Success && FDecl &&
14003+
FDecl->isTemplateInstantiation() &&
14004+
FDecl->getReturnType()->isUndeducedType()) {
14005+
if (auto TP = FDecl->getTemplateInstantiationPattern(false)) {
14006+
if (TP->willHaveBody()) {
14007+
CallExpr *CE =
14008+
CallExpr::Create(Context, Fn, Args, Context.DependentTy, VK_PRValue,
14009+
RParenLoc, CurFPFeatureOverrides());
14010+
result = CE;
14011+
return result;
14012+
}
14013+
}
14014+
}
1399714015

1399814016
return FinishOverloadedCallExpr(*this, S, Fn, ULE, LParenLoc, Args, RParenLoc,
1399914017
ExecConfig, &CandidateSet, &Best,

clang/lib/Sema/SemaTemplateInstantiate.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
#include "clang/Sema/Template.h"
3636
#include "clang/Sema/TemplateDeduction.h"
3737
#include "clang/Sema/TemplateInstCallback.h"
38-
#include "llvm/ADT/ScopeExit.h"
3938
#include "llvm/ADT/StringExtras.h"
4039
#include "llvm/Support/ErrorHandling.h"
4140
#include "llvm/Support/TimeProfiler.h"
@@ -1142,8 +1141,7 @@ std::optional<TemplateDeductionInfo *> Sema::isSFINAEContext() const {
11421141
case CodeSynthesisContext::DeducedTemplateArgumentSubstitution:
11431142
// We're either substituting explicitly-specified template arguments,
11441143
// deduced template arguments. SFINAE applies unless we are in a lambda
1145-
// expression, see [temp.deduct]p9.
1146-
[[fallthrough]];
1144+
// body, see [temp.deduct]p9.
11471145
case CodeSynthesisContext::ConstraintSubstitution:
11481146
case CodeSynthesisContext::RequirementInstantiation:
11491147
case CodeSynthesisContext::RequirementParameterInstantiation:
@@ -1445,13 +1443,6 @@ namespace {
14451443
LocalInstantiationScope Scope(SemaRef, /*CombineWithOuterScope=*/true);
14461444
Sema::ConstraintEvalRAII<TemplateInstantiator> RAII(*this);
14471445

1448-
Sema::CodeSynthesisContext C;
1449-
C.Kind = clang::Sema::CodeSynthesisContext::LambdaExpressionSubstitution;
1450-
C.PointOfInstantiation = E->getBeginLoc();
1451-
SemaRef.pushCodeSynthesisContext(C);
1452-
auto PopCtx =
1453-
llvm::make_scope_exit([this] { SemaRef.popCodeSynthesisContext(); });
1454-
14551446
ExprResult Result = inherited::TransformLambdaExpr(E);
14561447
if (Result.isInvalid())
14571448
return Result;

clang/lib/Sema/TreeTransform.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13685,10 +13685,17 @@ TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
1368513685
getSema().PushExpressionEvaluationContext(
1368613686
Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
1368713687

13688+
Sema::CodeSynthesisContext C;
13689+
C.Kind = clang::Sema::CodeSynthesisContext::LambdaExpressionSubstitution;
13690+
C.PointOfInstantiation = E->getBody()->getBeginLoc();
13691+
getSema().pushCodeSynthesisContext(C);
13692+
1368813693
// Instantiate the body of the lambda expression.
1368913694
StmtResult Body =
1369013695
Invalid ? StmtError() : getDerived().TransformLambdaBody(E, E->getBody());
1369113696

13697+
getSema().popCodeSynthesisContext();
13698+
1369213699
// ActOnLambda* will pop the function scope for us.
1369313700
FuncScopeCleanup.disable();
1369413701

clang/test/CXX/drs/dr26xx.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ void f(...);
211211

212212
template <class T>
213213
void bar(T) requires requires {
214-
decltype([]() -> T {})::foo();
214+
[]() -> decltype(T::foo()) {};
215215
};
216216
void bar(...);
217217

clang/test/CXX/expr/expr.prim/expr.prim.lambda/default-arguments.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ struct NoDefaultCtor {
3535
template<typename T>
3636
void defargs_in_template_unused(T t) {
3737
auto l1 = [](const T& value = T()) { }; // expected-error{{no matching constructor for initialization of 'NoDefaultCtor'}} \
38-
// expected-note {{in instantiation of default function argument expression for 'operator()<NoDefaultCtor>' required here}} \
39-
// expected-note {{while substituting into a lambda expression here}}
38+
// expected-note {{in instantiation of default function argument expression for 'operator()<NoDefaultCtor>' required here}}
4039
l1(t);
4140
}
4241

@@ -46,8 +45,7 @@ template void defargs_in_template_unused(NoDefaultCtor); // expected-note{{in i
4645
template<typename T>
4746
void defargs_in_template_used() {
4847
auto l1 = [](const T& value = T()) { }; // expected-error{{no matching constructor for initialization of 'NoDefaultCtor'}} \
49-
// expected-note {{in instantiation of default function argument expression for 'operator()<NoDefaultCtor>' required here}} \
50-
// expected-note {{while substituting into a lambda expression here}}
48+
// expected-note {{in instantiation of default function argument expression for 'operator()<NoDefaultCtor>' required here}}
5149
l1();
5250
}
5351

clang/test/CXX/expr/expr.prim/expr.prim.lambda/p11-1y.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ auto init_kind_2 = [ec = ExplicitCopy()] {}; // expected-error {{no matching con
3535
template<typename T> void init_kind_template() {
3636
auto init_kind_1 = [ec(T())] {};
3737
auto init_kind_2 = [ec = T()] {}; // expected-error {{no matching constructor}}
38-
// expected-note@-1 {{while substituting into a lambda expression here}}
3938
}
4039
template void init_kind_template<int>();
4140
template void init_kind_template<ExplicitCopy>(); // expected-note {{instantiation of}}
@@ -53,7 +52,6 @@ auto bad_init_6 = [a{overload_fn}] {}; // expected-error {{cannot deduce type fo
5352
auto bad_init_7 = [a{{1}}] {}; // expected-error {{cannot deduce type for lambda capture 'a' from nested initializer list}}
5453

5554
template<typename...T> void pack_1(T...t) { (void)[a(t...)] {}; } // expected-error {{initializer missing for lambda capture 'a'}}
56-
// expected-note@-1 {{while substituting into a lambda expression here}}
5755
template void pack_1<>(); // expected-note {{instantiation of}}
5856

5957
// No lifetime-extension of the temporary here.

clang/test/CXX/expr/expr.prim/expr.prim.lambda/p23.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ void init_capture_pack_err(Args ...args) {
8585
template<typename ...Args>
8686
void init_capture_pack_multi(Args ...args) {
8787
[as(args...)] {} (); // expected-error {{initializer missing for lambda capture 'as'}} expected-error {{multiple}}
88-
// expected-note@-1 2{{while substituting into a lambda expression}}
8988
}
9089
template void init_capture_pack_multi(); // expected-note {{instantiation}}
9190
template void init_capture_pack_multi(int);

clang/test/CXX/expr/expr.prim/expr.prim.lambda/p4.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,11 @@ void test_result_type(int N) { // expected-note {{declared here}}
5555
template <typename T>
5656
void test_result_type_tpl(int N) { // expected-note 2{{declared here}}
5757
auto l1 = []() -> T {}; // expected-error{{incomplete result type 'Incomplete' in lambda expression}}
58-
// expected-note@-1{{while substituting into a lambda expression here}}
5958
typedef int vla[N]; // expected-warning 2{{variable length arrays in C++ are a Clang extension}} \
6059
expected-note 2{{function parameter 'N' with unknown value cannot be used in a constant expression}}
6160
auto l2 = []() -> vla {}; // expected-error{{function cannot return array type 'vla' (aka 'int[N]')}}
6261
}
6362

6463
void test_result_type_call() {
65-
test_result_type_tpl<Incomplete>(10); // expected-note 2{{requested here}}
64+
test_result_type_tpl<Incomplete>(10); // expected-note {{requested here}}
6665
}

clang/test/CXX/temp/temp.deduct/p9.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,14 @@ template <class T>
2828
auto h(T) -> decltype([x = T::invalid]() { });
2929
void h(...);
3030
void test_h() {
31-
h(0); // expected-error@-3 {{type 'int' cannot be used prior to '::'}}
32-
// expected-note@-1 {{while substituting deduced template arguments}}
33-
// expected-note@-5 {{while substituting into a lambda expression here}}
31+
h(0);
3432
}
3533

3634
template <class T>
3735
auto i(T) -> decltype([]() -> typename T::invalid { });
3836
void i(...);
3937
void test_i() {
40-
i(0); // expected-error@-3 {{type 'int' cannot be used prior to '::'}}
41-
// expected-note@-1 {{while substituting deduced template arguments}}
42-
// expected-note@-5 {{while substituting into a lambda expression here}}
38+
i(0);
4339
}
4440

4541

clang/test/SemaCXX/cxx1y-init-captures.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ namespace variadic_expansion {
2121
return a;
2222
}() ...);
2323
};
24-
auto N2 = [x = y, //expected-note3{{begins here}} expected-note 6 {{default capture by}} expected-note 2 {{substituting into a lambda}}
24+
auto N2 = [x = y, //expected-note3{{begins here}} expected-note 6 {{default capture by}}
2525
&z = y, n = f(t...),
26-
o = f([&a(t)](T& ... t)->decltype(auto) { return a; }(t...)...)](T& ... s) { // expected-note 6 {{capture 't' by}}
27-
fv([&a(t)]()->decltype(auto) { //expected-error 3{{captured}} expected-note 2{{substituting into a lambda}}
26+
o = f([&a(t)](T& ... t)->decltype(auto) { return a; }(t...)...)](T& ... s) { // expected-note 6 {{capture 't' by}} expected-note {{substituting into a lambda}}
27+
fv([&a(t)]()->decltype(auto) { //expected-error 3{{captured}}
2828
return a;
2929
}() ...);
3030
};
3131

3232
}
3333

34-
void h(int i, char c) { g(i, c); } //expected-note 2{{in instantiation}}
34+
void h(int i, char c) { g(i, c); } // expected-note {{requested here}}
3535
}
3636

3737
namespace odr_use_within_init_capture {

clang/test/SemaCXX/cxx1z-lambda-star-this.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class B {
4646
template <class T = int>
4747
void foo() {
4848
(void)[this] { return x; };
49-
(void)[*this] { return x; }; //expected-error2{{call to deleted}} expected-note {{while substituting into a lambda}}
49+
(void)[*this] { return x; }; //expected-error2{{call to deleted}}
5050
}
5151

5252
B() = default;
@@ -63,7 +63,7 @@ class B {
6363
public:
6464
template <class T = int>
6565
auto foo() {
66-
const auto &L = [*this](auto a) mutable { //expected-error{{call to deleted}} expected-note {{while substituting into a lambda}}
66+
const auto &L = [*this](auto a) mutable { //expected-error{{call to deleted}}
6767
d += a;
6868
return [this](auto b) { return d += b; };
6969
};

clang/test/SemaCXX/deduced-return-type-cxx14.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,3 +640,49 @@ namespace PR46637 {
640640
template<typename T> struct Y { T x; };
641641
Y<auto() -> auto> y; // expected-error {{'auto' not allowed in template argument}}
642642
}
643+
644+
namespace GH71015 {
645+
646+
// Check that there is no error in case a templated function is recursive and
647+
// has a placeholder return type.
648+
struct Node {
649+
int value;
650+
Node* left;
651+
Node* right;
652+
};
653+
654+
bool parse(const char*);
655+
Node* parsePrimaryExpr();
656+
657+
auto parseMulExpr(auto node) { // cxx14-error {{'auto' not allowed in function prototype}} \
658+
// cxx14-note {{not viable}}
659+
if (node == nullptr) node = parsePrimaryExpr();
660+
if (!parse("*")) return node;
661+
return parseMulExpr(new Node{.left = node, .right = parsePrimaryExpr()});
662+
}
663+
664+
template <typename T>
665+
auto parseMulExpr2(T node) {
666+
if (node == nullptr) node = parsePrimaryExpr();
667+
if (!parse("*")) return node;
668+
return parseMulExpr2(new Node{.left = node, .right = parsePrimaryExpr()});
669+
}
670+
671+
template <typename T>
672+
auto parseMulExpr3(T node) { // expected-note {{declared here}}
673+
if (node == nullptr) node = parsePrimaryExpr();
674+
return parseMulExpr3(new Node{.left = node, .right = parsePrimaryExpr()}); // expected-error {{cannot be used before it is defined}}
675+
}
676+
677+
void foo() {
678+
parseMulExpr(new Node{}); // cxx14-error {{no matching function}}
679+
parseMulExpr2(new Node{});
680+
parseMulExpr3(new Node{}); // expected-note {{in instantiation}}
681+
}
682+
683+
auto f(auto x) { // cxx14-error {{'auto' not allowed in function prototype}}
684+
if (x == 0) return 0;
685+
return f(1) + 1;
686+
}
687+
688+
}

clang/test/SemaCXX/lambda-expressions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ struct S {
393393
namespace PR18473 {
394394
template<typename T> void f() {
395395
T t(0);
396-
(void) [=]{ int n = t; }; // expected-error {{deleted}} expected-note {{while substituting into a lambda}}
396+
(void) [=]{ int n = t; }; // expected-error {{deleted}}
397397
}
398398

399399
template void f<int>();
@@ -476,7 +476,7 @@ namespace error_in_transform_prototype {
476476
void f(T t) {
477477
// expected-error@+2 {{type 'int' cannot be used prior to '::' because it has no members}}
478478
// expected-error@+1 {{no member named 'ns' in 'error_in_transform_prototype::S'}}
479-
auto x = [](typename T::ns::type &k) {}; // expected-note 2 {{while substituting into a lambda}}
479+
auto x = [](typename T::ns::type &k) {};
480480
}
481481
class S {};
482482
void foo() {

clang/test/SemaCXX/lambda-pack-expansion.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ struct X {
88

99
void take_by_copy(auto &...args) {
1010
[...args = args] {}(); // expected-error {{call to deleted constructor}}
11-
// expected-note@-1 {{substituting into a lambda}}
1211
}
1312

1413
void take_by_ref(auto &...args) {

clang/test/SemaCXX/vartemplate-lambda.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ template<typename T> auto v1 = [](int a = T()) { return a; }();
88
// expected-error@-1{{cannot initialize a parameter of type 'int' with an rvalue of type 'int *'}}
99
// expected-note@-2{{in instantiation of default function argument expression for 'operator()<int *>' required here}}
1010
// expected-note@-3{{passing argument to parameter 'a' here}}
11-
// expected-note@-4{{substituting into a lambda}}
1211

1312
struct S {
1413
template<class T>

0 commit comments

Comments
 (0)