Skip to content

Commit f79988b

Browse files
SC llvm teamSC llvm team
SC llvm team
authored and
SC llvm team
committed
Merged main:f756061387c8 into amd-gfx:63e627b07a2b
Local branch amd-gfx 63e627b Merged main:e9b33d085da0 into amd-gfx:6510fa067355 Remote branch main f756061 [Clang] Add missing words to ReleaseNotes.rst
2 parents 63e627b + f756061 commit f79988b

File tree

117 files changed

+5126
-882
lines changed

Some content is hidden

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

117 files changed

+5126
-882
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ C++20 Feature Support
9191

9292
C++23 Feature Support
9393
^^^^^^^^^^^^^^^^^^^^^
94+
- Implemented `P0847R7: Deducing this <https://wg21.link/P0847R7>`_. Some related core issues were also
95+
implemented (`CWG2553 <https://wg21.link/CWG2553>`_, `CWG2554 <https://wg21.link/CWG2554>`_,
96+
`CWG2653 <https://wg21.link/CWG2653>`_, `CWG2687 <https://wg21.link/CWG2687>`_). Because the
97+
support for this feature is still experimental, the feature test macro ``__cpp_explicit_this_parameter``
98+
was not set in this version.
9499

95100
C++2c Feature Support
96101
^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/AST/ASTLambda.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,21 @@ inline bool isLambdaCallOperator(const DeclContext *DC) {
3535
return isLambdaCallOperator(cast<CXXMethodDecl>(DC));
3636
}
3737

38+
inline bool isLambdaCallWithExplicitObjectParameter(const DeclContext *DC) {
39+
return isLambdaCallOperator(DC) &&
40+
cast<CXXMethodDecl>(DC)->isExplicitObjectMemberFunction();
41+
}
42+
43+
inline bool isLambdaCallWithImplicitObjectParameter(const DeclContext *DC) {
44+
return isLambdaCallOperator(DC) &&
45+
// FIXME: Checking for a null type is not great
46+
// but lambdas with invalid captures or whose closure parameter list
47+
// have not fully been parsed may have a call operator whose type is
48+
// null.
49+
!cast<CXXMethodDecl>(DC)->getType().isNull() &&
50+
!cast<CXXMethodDecl>(DC)->isExplicitObjectMemberFunction();
51+
}
52+
3853
inline bool isGenericLambdaCallOperatorSpecialization(const CXXMethodDecl *MD) {
3954
if (!MD) return false;
4055
const CXXRecordDecl *LambdaClass = MD->getParent();

clang/include/clang/AST/Decl.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,6 +1809,18 @@ class ParmVarDecl : public VarDecl {
18091809
ParmVarDeclBits.IsKNRPromoted = promoted;
18101810
}
18111811

1812+
bool isExplicitObjectParameter() const {
1813+
return ExplicitObjectParameterIntroducerLoc.isValid();
1814+
}
1815+
1816+
void setExplicitObjectParameterLoc(SourceLocation Loc) {
1817+
ExplicitObjectParameterIntroducerLoc = Loc;
1818+
}
1819+
1820+
SourceLocation getExplicitObjectParamThisLoc() const {
1821+
return ExplicitObjectParameterIntroducerLoc;
1822+
}
1823+
18121824
Expr *getDefaultArg();
18131825
const Expr *getDefaultArg() const {
18141826
return const_cast<ParmVarDecl *>(this)->getDefaultArg();
@@ -1875,7 +1887,10 @@ class ParmVarDecl : public VarDecl {
18751887
static bool classofKind(Kind K) { return K == ParmVar; }
18761888

18771889
private:
1890+
friend class ASTDeclReader;
1891+
18781892
enum { ParameterIndexSentinel = (1 << NumParameterIndexBits) - 1 };
1893+
SourceLocation ExplicitObjectParameterIntroducerLoc;
18791894

18801895
void setParameterIndex(unsigned parameterIndex) {
18811896
if (parameterIndex >= ParameterIndexSentinel) {
@@ -2640,6 +2655,23 @@ class FunctionDecl : public DeclaratorDecl,
26402655
/// parameters have default arguments (in C++).
26412656
unsigned getMinRequiredArguments() const;
26422657

2658+
/// Returns the minimum number of non-object arguments needed to call this
2659+
/// function. This produces the same value as getMinRequiredArguments except
2660+
/// it does not count the explicit object argument, if any.
2661+
unsigned getMinRequiredExplicitArguments() const;
2662+
2663+
bool hasCXXExplicitFunctionObjectParameter() const;
2664+
2665+
unsigned getNumNonObjectParams() const;
2666+
2667+
const ParmVarDecl *getNonObjectParameter(unsigned I) const {
2668+
return getParamDecl(hasCXXExplicitFunctionObjectParameter() ? I + 1 : I);
2669+
}
2670+
2671+
ParmVarDecl *getNonObjectParameter(unsigned I) {
2672+
return getParamDecl(hasCXXExplicitFunctionObjectParameter() ? I + 1 : I);
2673+
}
2674+
26432675
/// Determine whether this function has a single parameter, or multiple
26442676
/// parameters where all but the first have default arguments.
26452677
///

clang/include/clang/AST/DeclCXX.h

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2061,6 +2061,17 @@ class CXXMethodDecl : public FunctionDecl {
20612061
bool isStatic() const;
20622062
bool isInstance() const { return !isStatic(); }
20632063

2064+
/// [C++2b][dcl.fct]/p7
2065+
/// An explicit object member function is a non-static
2066+
/// member function with an explicit object parameter. e.g.,
2067+
/// void func(this SomeType);
2068+
bool isExplicitObjectMemberFunction() const;
2069+
2070+
/// [C++2b][dcl.fct]/p7
2071+
/// An implicit object member function is a non-static
2072+
/// member function without an explicit object parameter.
2073+
bool isImplicitObjectMemberFunction() const;
2074+
20642075
/// Returns true if the given operator is implicitly static in a record
20652076
/// context.
20662077
static bool isStaticOverloadedOperator(OverloadedOperatorKind OOK) {
@@ -2169,14 +2180,19 @@ class CXXMethodDecl : public FunctionDecl {
21692180
/// Return the type of the object pointed by \c this.
21702181
///
21712182
/// See getThisType() for usage restriction.
2172-
QualType getThisObjectType() const;
2183+
2184+
QualType getFunctionObjectParameterReferenceType() const;
2185+
QualType getFunctionObjectParameterType() const {
2186+
return getFunctionObjectParameterReferenceType().getNonReferenceType();
2187+
}
2188+
2189+
unsigned getNumExplicitParams() const {
2190+
return getNumParams() - (isExplicitObjectMemberFunction() ? 1 : 0);
2191+
}
21732192

21742193
static QualType getThisType(const FunctionProtoType *FPT,
21752194
const CXXRecordDecl *Decl);
21762195

2177-
static QualType getThisObjectType(const FunctionProtoType *FPT,
2178-
const CXXRecordDecl *Decl);
2179-
21802196
Qualifiers getMethodQualifiers() const {
21812197
return getType()->castAs<FunctionProtoType>()->getMethodQuals();
21822198
}

clang/include/clang/AST/Expr.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,6 +1449,16 @@ class DeclRefExpr final
14491449
DeclRefExprBits.IsImmediateEscalating = Set;
14501450
}
14511451

1452+
bool isCapturedByCopyInLambdaWithExplicitObjectParameter() const {
1453+
return DeclRefExprBits.CapturedByCopyInLambdaWithExplicitObjectParameter;
1454+
}
1455+
1456+
void setCapturedByCopyInLambdaWithExplicitObjectParameter(
1457+
bool Set, const ASTContext &Context) {
1458+
DeclRefExprBits.CapturedByCopyInLambdaWithExplicitObjectParameter = Set;
1459+
setDependence(computeDependence(this, Context));
1460+
}
1461+
14521462
static bool classof(const Stmt *T) {
14531463
return T->getStmtClass() == DeclRefExprClass;
14541464
}

clang/include/clang/AST/Stmt.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ class alignas(void *) Stmt {
383383
unsigned HasFoundDecl : 1;
384384
unsigned HadMultipleCandidates : 1;
385385
unsigned RefersToEnclosingVariableOrCapture : 1;
386+
unsigned CapturedByCopyInLambdaWithExplicitObjectParameter : 1;
386387
unsigned NonOdrUseReason : 2;
387388
unsigned IsImmediateEscalating : 1;
388389

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 61 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4681,12 +4681,14 @@ def note_ovl_candidate_non_deduced_mismatch_qualified : Note<
46814681
// Note that we don't treat templates differently for this diagnostic.
46824682
def note_ovl_candidate_arity : Note<"candidate "
46834683
"%sub{select_ovl_candidate_kind}0,1,2 not viable: "
4684-
"requires%select{ at least| at most|}3 %4 argument%s4, but %5 "
4684+
"requires%select{ at least| at most|}3 %4 "
4685+
"%select{|non-object }6argument%s4, but %5 "
46854686
"%plural{1:was|:were}5 provided">;
46864687

46874688
def note_ovl_candidate_arity_one : Note<"candidate "
46884689
"%sub{select_ovl_candidate_kind}0,1,2 not viable: "
46894690
"%select{requires at least|allows at most single|requires single}3 "
4691+
"%select{|non-object }6"
46904692
"argument %4, but %plural{0:no|:%5}5 arguments were provided">;
46914693

46924694
def note_ovl_candidate_deleted : Note<
@@ -4869,7 +4871,7 @@ def err_ovl_deleted_object_call : Error<
48694871
"call to deleted function call operator in type %0">;
48704872
def note_ovl_surrogate_cand : Note<"conversion candidate of type %0">;
48714873
def err_member_call_without_object : Error<
4872-
"call to non-static member function without an object argument">;
4874+
"call to %select{non-static|explicit}0 member function without an object argument">;
48734875

48744876
// C++ Address of Overloaded Function
48754877
def err_addr_ovl_no_viable : Error<
@@ -7289,21 +7291,43 @@ def note_logical_not_silence_with_parens : Note<
72897291
"add parentheses around left hand side expression to silence this warning">;
72907292

72917293
def err_invalid_this_use : Error<
7292-
"invalid use of 'this' outside of a non-static member function">;
7294+
"invalid use of 'this' %select{outside of a non-static member function"
7295+
"|in a function with an explicit object parameter}0">;
72937296
def err_this_static_member_func : Error<
72947297
"'this' cannot be%select{| implicitly}0 used in a static member function "
72957298
"declaration">;
7296-
def err_invalid_member_use_in_static_method : Error<
7297-
"invalid use of member %0 in static member function">;
7299+
def err_invalid_member_use_in_method : Error<
7300+
"invalid use of member %0 in %select{static|explicit object}1 member function">;
7301+
72987302
def err_invalid_qualified_function_type : Error<
7299-
"%select{non-member function|static member function|deduction guide}0 "
7303+
"%select{non-member function|static member function|explicit object member function|deduction guide}0 "
73007304
"%select{of type %2 |}1cannot have '%3' qualifier">;
73017305
def err_compound_qualified_function_type : Error<
73027306
"%select{block pointer|pointer|reference}0 to function type %select{%2 |}1"
73037307
"cannot have '%3' qualifier">;
73047308
def err_qualified_function_typeid : Error<
73057309
"type operand %0 of 'typeid' cannot have '%1' qualifier">;
73067310

7311+
def err_cxx20_deducing_this : Error<
7312+
"explicit object parameters are incompatible with C++ standards before C++2b">;
7313+
def err_explicit_object_default_arg: Error<
7314+
"the explicit object parameter cannot have a default argument">;
7315+
def err_explicit_object_parameter_pack: Error<
7316+
"the explicit object parameter cannot be a function parameter pack">;
7317+
def err_explicit_object_parameter_must_be_first: Error<
7318+
"an explicit object parameter can only appear as the first parameter "
7319+
"of the %select{function|lambda}0">;
7320+
def err_explicit_object_parameter_nonmember: Error<
7321+
"an explicit object parameter cannot appear in a "
7322+
"%select{static|virtual|non-member}0 %select{function|lambda}1">;
7323+
def err_explicit_object_parameter_constructor: Error<
7324+
"an explicit object parameter cannot appear in a %select{constructor|destructor}0">;
7325+
def err_explicit_object_parameter_mutable: Error<
7326+
"a lambda with an explicit object parameter cannot be mutable">;
7327+
def err_invalid_explicit_object_type_in_lambda: Error<
7328+
"invalid explicit object parameter type %0 in lambda with capture; "
7329+
"the type must be the same as, or derived from, the lambda">;
7330+
73077331
def err_ref_qualifier_overload : Error<
73087332
"cannot overload a member function %select{without a ref-qualifier|with "
73097333
"ref-qualifier '&'|with ref-qualifier '&&'}0 with a member function %select{"
@@ -8525,53 +8549,65 @@ def err_call_function_incomplete_return : Error<
85258549
def err_call_incomplete_argument : Error<
85268550
"argument type %0 is incomplete">;
85278551
def err_typecheck_call_too_few_args : Error<
8528-
"too few %select{|||execution configuration }0arguments to "
8552+
"too few %select{|||execution configuration }0"
8553+
"%select{|non-object }3arguments to "
85298554
"%select{function|block|method|kernel function}0 call, "
85308555
"expected %1, have %2">;
85318556
def err_typecheck_call_too_few_args_one : Error<
8532-
"too few %select{|||execution configuration }0arguments to "
8557+
"too few %select{|||execution configuration }0"
8558+
"%select{|non-object }2arguments to "
85338559
"%select{function|block|method|kernel function}0 call, "
85348560
"single argument %1 was not specified">;
85358561
def err_typecheck_call_too_few_args_at_least : Error<
8536-
"too few %select{|||execution configuration }0arguments to "
8562+
"too few %select{|||execution configuration }0"
8563+
"%select{|non-object }3arguments to "
85378564
"%select{function|block|method|kernel function}0 call, "
85388565
"expected at least %1, have %2">;
85398566
def err_typecheck_call_too_few_args_at_least_one : Error<
8540-
"too few %select{|||execution configuration }0arguments to "
8567+
"too few %select{|||execution configuration }0"
8568+
"%select{|non-object }2arguments to "
85418569
"%select{function|block|method|kernel function}0 call, "
85428570
"at least argument %1 must be specified">;
85438571
def err_typecheck_call_too_few_args_suggest : Error<
8544-
"too few %select{|||execution configuration }0arguments to "
8572+
"too few %select{|||execution configuration }0"
8573+
"%select{|non-object }3arguments to "
85458574
"%select{function|block|method|kernel function}0 call, "
8546-
"expected %1, have %2; did you mean %3?">;
8575+
"expected %1, have %2; did you mean %4?">;
85478576
def err_typecheck_call_too_few_args_at_least_suggest : Error<
8548-
"too few %select{|||execution configuration }0arguments to "
8577+
"too few %select{|||execution configuration }0"
8578+
"%select{|non-object }3arguments to "
85498579
"%select{function|block|method|kernel function}0 call, "
8550-
"expected at least %1, have %2; did you mean %3?">;
8580+
"expected at least %1, have %2; did you mean %4?">;
85518581
def err_typecheck_call_too_many_args : Error<
8552-
"too many %select{|||execution configuration }0arguments to "
8582+
"too many %select{|||execution configuration }0"
8583+
"%select{|non-object }3arguments to "
85538584
"%select{function|block|method|kernel function}0 call, "
85548585
"expected %1, have %2">;
85558586
def err_typecheck_call_too_many_args_one : Error<
8556-
"too many %select{|||execution configuration }0arguments to "
8587+
"too many %select{|||execution configuration }0"
8588+
"%select{|non-object }3arguments to "
85578589
"%select{function|block|method|kernel function}0 call, "
85588590
"expected single argument %1, have %2 arguments">;
85598591
def err_typecheck_call_too_many_args_at_most : Error<
8560-
"too many %select{|||execution configuration }0arguments to "
8592+
"too many %select{|||execution configuration }0"
8593+
"%select{|non-object }3arguments to "
85618594
"%select{function|block|method|kernel function}0 call, "
85628595
"expected at most %1, have %2">;
85638596
def err_typecheck_call_too_many_args_at_most_one : Error<
85648597
"too many %select{|||execution configuration }0arguments to "
85658598
"%select{function|block|method|kernel function}0 call, "
8566-
"expected at most single argument %1, have %2 arguments">;
8599+
"expected at most single %select{|non-object }3argument %1, "
8600+
"have %2%select{|non-object}3 arguments">;
85678601
def err_typecheck_call_too_many_args_suggest : Error<
8568-
"too many %select{|||execution configuration }0arguments to "
8602+
"too many %select{|||execution configuration }0"
8603+
"%select{|non-object }3arguments to "
85698604
"%select{function|block|method|kernel function}0 call, "
8570-
"expected %1, have %2; did you mean %3?">;
8605+
"expected %1, have %2; did you mean %4?">;
85718606
def err_typecheck_call_too_many_args_at_most_suggest : Error<
8572-
"too many %select{|||execution configuration }0arguments to "
8607+
"too many %select{|||execution configuration }0"
8608+
"%select{|non-object }3arguments to "
85738609
"%select{function|block|method|kernel function}0 call, "
8574-
"expected at most %1, have %2; did you mean %3?">;
8610+
"expected at most %1, have %2; did you mean %4?">;
85758611

85768612
def err_arc_typecheck_convert_incompatible_pointer : Error<
85778613
"incompatible pointer types passing retainable parameter of type %0"
@@ -9389,10 +9425,10 @@ def warn_cxx98_compat_explicit_conversion_functions : Warning<
93899425

93909426
// C++11 defaulted functions
93919427
def err_defaulted_special_member_params : Error<
9392-
"an explicitly-defaulted %select{|copy |move }0constructor cannot "
9428+
"an explicitly-defaulted %sub{select_special_member_kind}0 cannot "
93939429
"have default arguments">;
93949430
def err_defaulted_special_member_variadic : Error<
9395-
"an explicitly-defaulted %select{|copy |move }0constructor cannot "
9431+
"an explicitly-defaulted %sub{select_special_member_kind}0 cannot "
93969432
"be variadic">;
93979433
def err_defaulted_special_member_return_type : Error<
93989434
"explicitly-defaulted %select{copy|move}0 assignment operator must "
@@ -9455,7 +9491,7 @@ def err_defaulted_comparison_template : Error<
94559491
"comparison operator template cannot be defaulted">;
94569492
def err_defaulted_comparison_num_args : Error<
94579493
"%select{non-member|member}0 %sub{select_defaulted_comparison_kind}1"
9458-
" comparison operator must have %select{2|1}0 parameters">;
9494+
" must have %select{2|1}0 parameters">;
94599495
def err_defaulted_comparison_param : Error<
94609496
"invalid parameter type for defaulted %sub{select_defaulted_comparison_kind}0"
94619497
"; found %1, expected %2%select{| or %4}3">;

clang/include/clang/Sema/DeclSpec.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2674,6 +2674,8 @@ class Declarator {
26742674
/// redeclaration time if the decl is static.
26752675
bool isStaticMember();
26762676

2677+
bool isExplicitObjectMemberFunction();
2678+
26772679
/// Returns true if this declares a constructor or a destructor.
26782680
bool isCtorOrDtor();
26792681

clang/include/clang/Sema/ScopeInfo.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,8 @@ class LambdaScopeInfo final :
847847
/// is known.
848848
bool AfterParameterList = true;
849849

850+
ParmVarDecl *ExplicitObjectParameter = nullptr;
851+
850852
/// Source range covering the lambda introducer [...].
851853
SourceRange IntroducerRange;
852854

@@ -1042,6 +1044,8 @@ class LambdaScopeInfo final :
10421044

10431045
void visitPotentialCaptures(
10441046
llvm::function_ref<void(ValueDecl *, Expr *)> Callback) const;
1047+
1048+
bool lambdaCaptureShouldBeConst() const;
10451049
};
10461050

10471051
FunctionScopeInfo::WeakObjectProfileTy::WeakObjectProfileTy()

0 commit comments

Comments
 (0)