Skip to content

Commit 1f8bb4a

Browse files
authored
merge main into amd-staging (llvm#1085)
2 parents 5112f90 + 04aa331 commit 1f8bb4a

File tree

193 files changed

+4772
-1961
lines changed

Some content is hidden

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

193 files changed

+4772
-1961
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -296,16 +296,6 @@ Bug Fixes to C++ Support
296296
- Clang now uses the parameter location for abbreviated function templates in ``extern "C"``. (#GH46386)
297297
- Clang now correctly parses ``if constexpr`` expressions in immediate function context. (#GH123524)
298298

299-
Improvements to C++ diagnostics
300-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
301-
302-
- Clang now more consistently adds a note pointing to the relevant template
303-
parameter. Some diagnostics are reworded to better take advantage of this.
304-
- Template Template Parameter diagnostics now stop referring to template
305-
parameters as template arguments, in some circumstances, better hiding
306-
from the users template template parameter partial ordering arcana.
307-
308-
309299
Bug Fixes to AST Handling
310300
^^^^^^^^^^^^^^^^^^^^^^^^^
311301
- Fixed type checking when a statement expression ends in an l-value of atomic type. (#GH106576)

clang/docs/analyzer/checkers.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3522,6 +3522,19 @@ Raw pointers and references to an object which supports CheckedPtr or CheckedRef
35223522
35233523
See `WebKit Guidelines for Safer C++ Programming <https://github.com/WebKit/WebKit/wiki/Safer-CPP-Guidelines>`_ for details.
35243524
3525+
alpha.webkit.NoUnretainedMemberChecker
3526+
""""""""""""""""""""""""""""""""""""""""
3527+
Raw pointers and references to a NS or CF object can't be used as class members or ivars. Only RetainPtr is allowed for CF types regardless of whether ARC is enabled or disabled. Only RetainPtr is allowed for NS types when ARC is disabled.
3528+
3529+
.. code-block:: cpp
3530+
3531+
struct Foo {
3532+
NSObject *ptr; // warn
3533+
// ...
3534+
};
3535+
3536+
See `WebKit Guidelines for Safer C++ Programming <https://github.com/WebKit/WebKit/wiki/Safer-CPP-Guidelines>`_ for details.
3537+
35253538
alpha.webkit.UnretainedLambdaCapturesChecker
35263539
""""""""""""""""""""""""""""""""""""""""""""
35273540
Raw pointers and references to NS or CF types can't be captured in lambdas. Only RetainPtr is allowed for CF types regardless of whether ARC is enabled or disabled, and only RetainPtr is allowed for NS types when ARC is disabled.

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5210,11 +5210,16 @@ def err_template_unnamed_class : Error<
52105210
def err_template_param_list_different_arity : Error<
52115211
"%select{too few|too many}0 template parameters in template "
52125212
"%select{|template parameter }1redeclaration">;
5213+
def note_template_param_list_different_arity : Note<
5214+
"%select{too few|too many}0 template parameters in template template "
5215+
"argument">;
52135216
def note_template_prev_declaration : Note<
52145217
"previous template %select{declaration|template parameter}0 is here">;
52155218
def err_template_param_different_kind : Error<
52165219
"template parameter has a different kind in template "
52175220
"%select{|template parameter }0redeclaration">;
5221+
def note_template_param_different_kind : Note<
5222+
"template parameter has a different kind in template argument">;
52185223

52195224
def err_invalid_decl_specifier_in_nontype_parm : Error<
52205225
"invalid declaration specifier in template non-type parameter">;
@@ -5223,6 +5228,8 @@ def err_template_nontype_parm_different_type : Error<
52235228
"template non-type parameter has a different type %0 in template "
52245229
"%select{|template parameter }1redeclaration">;
52255230

5231+
def note_template_nontype_parm_different_type : Note<
5232+
"template non-type parameter has a different type %0 in template argument">;
52265233
def note_template_nontype_parm_prev_declaration : Note<
52275234
"previous non-type template parameter with type %0 is here">;
52285235
def err_template_nontype_parm_bad_type : Error<
@@ -5313,15 +5320,10 @@ def err_template_missing_args : Error<
53135320
"%select{class template|function template|variable template|alias template|"
53145321
"template template parameter|concept|template}0 %1 requires template "
53155322
"arguments">;
5316-
def err_template_param_missing_arg : Error<
5317-
"missing template argument for template parameter">;
5318-
def err_template_template_param_missing_param : Error<
5319-
"no template parameter in this template template parameter "
5320-
"corresponds to non-defaulted template parameter of argument template">;
5321-
def err_template_too_many_args : Error<
5322-
"too many template arguments for "
5323+
def err_template_arg_list_different_arity : Error<
5324+
"%select{too few|too many}0 template arguments for "
53235325
"%select{class template|function template|variable template|alias template|"
5324-
"template template parameter|concept|template}0 %1">;
5326+
"template template parameter|concept|template}1 %2">;
53255327
def note_template_decl_here : Note<"template is declared here">;
53265328
def note_template_decl_external : Note<
53275329
"template declaration from hidden source: %0">;
@@ -5359,8 +5361,11 @@ def err_template_arg_not_valid_template : Error<
53595361
"template parameter">;
53605362
def note_template_arg_refers_here_func : Note<
53615363
"template argument refers to function template %0, here">;
5364+
def err_template_arg_template_params_mismatch : Error<
5365+
"template template argument has different template parameters than its "
5366+
"corresponding template template parameter">;
53625367
def note_template_arg_template_params_mismatch : Note<
5363-
"template template argument is incompatible with its "
5368+
"template template argument has different template parameters than its "
53645369
"corresponding template template parameter">;
53655370
def err_non_deduced_mismatch : Error<
53665371
"could not match %diff{$ against $|types}0,1">;
@@ -5922,6 +5927,10 @@ def err_template_parameter_pack_non_pack : Error<
59225927
"%select{template type|non-type template|template template}0 parameter"
59235928
"%select{| pack}1 conflicts with previous %select{template type|"
59245929
"non-type template|template template}0 parameter%select{ pack|}1">;
5930+
def note_template_parameter_pack_non_pack : Note<
5931+
"%select{template type|non-type template|template template}0 parameter"
5932+
"%select{| pack}1 does not match %select{template type|non-type template"
5933+
"|template template}0 parameter%select{ pack|}1 in template argument">;
59255934
def note_template_parameter_pack_here : Note<
59265935
"previous %select{template type|non-type template|template template}0 "
59275936
"parameter%select{| pack}1 declared here">;

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4847,9 +4847,9 @@ def mno_long_calls : Flag<["-"], "mno-long-calls">, Group<m_Group>,
48474847
HelpText<"Restore the default behaviour of not generating long calls">;
48484848
} // let Flags = [TargetSpecific]
48494849
def mexecute_only : Flag<["-"], "mexecute-only">, Group<m_arm_Features_Group>,
4850-
HelpText<"Disallow generation of data access to code sections (ARM only)">;
4850+
HelpText<"Disallow generation of data access to code sections (AArch64/ARM only)">;
48514851
def mno_execute_only : Flag<["-"], "mno-execute-only">, Group<m_arm_Features_Group>,
4852-
HelpText<"Allow generation of data access to code sections (ARM only)">;
4852+
HelpText<"Allow generation of data access to code sections (AArch64/ARM only)">;
48534853
let Flags = [TargetSpecific] in {
48544854
def mtp_mode_EQ : Joined<["-"], "mtp=">, Group<m_arm_Features_Group>, Values<"soft,cp15,tpidrurw,tpidruro,tpidrprw,el0,el1,el2,el3,tpidr_el0,tpidr_el1,tpidr_el2,tpidr_el3,tpidrro_el0,auto">,
48554855
HelpText<"Thread pointer access method. "

clang/include/clang/Sema/Sema.h

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11833,7 +11833,7 @@ class Sema final : public SemaBase {
1183311833
bool *ConstraintsNotSatisfied = nullptr);
1183411834

1183511835
bool CheckTemplateTypeArgument(
11836-
TemplateArgumentLoc &Arg,
11836+
TemplateTypeParmDecl *Param, TemplateArgumentLoc &Arg,
1183711837
SmallVectorImpl<TemplateArgument> &SugaredConverted,
1183811838
SmallVectorImpl<TemplateArgument> &CanonicalConverted);
1183911839

@@ -11869,13 +11869,9 @@ class Sema final : public SemaBase {
1186911869
bool PartialOrdering,
1187011870
bool *StrictPackMatch);
1187111871

11872-
/// Print the given named declaration to a string,
11873-
/// using the current PrintingPolicy, except that
11874-
/// TerseOutput will always be set.
11875-
SmallString<128> toTerseString(const NamedDecl &D) const;
11876-
1187711872
void NoteTemplateLocation(const NamedDecl &Decl,
1187811873
std::optional<SourceRange> ParamRange = {});
11874+
void NoteTemplateParameterLocation(const NamedDecl &Decl);
1187911875

1188011876
/// Given a non-type template argument that refers to a
1188111877
/// declaration and the type of its corresponding non-type template
@@ -11990,13 +11986,15 @@ class Sema final : public SemaBase {
1199011986
bool TemplateParameterListsAreEqual(
1199111987
const TemplateCompareNewDeclInfo &NewInstFrom, TemplateParameterList *New,
1199211988
const NamedDecl *OldInstFrom, TemplateParameterList *Old, bool Complain,
11993-
TemplateParameterListEqualKind Kind);
11989+
TemplateParameterListEqualKind Kind,
11990+
SourceLocation TemplateArgLoc = SourceLocation());
1199411991

11995-
bool TemplateParameterListsAreEqual(TemplateParameterList *New,
11996-
TemplateParameterList *Old, bool Complain,
11997-
TemplateParameterListEqualKind Kind) {
11992+
bool TemplateParameterListsAreEqual(
11993+
TemplateParameterList *New, TemplateParameterList *Old, bool Complain,
11994+
TemplateParameterListEqualKind Kind,
11995+
SourceLocation TemplateArgLoc = SourceLocation()) {
1199811996
return TemplateParameterListsAreEqual(nullptr, New, nullptr, Old, Complain,
11999-
Kind);
11997+
Kind, TemplateArgLoc);
1200011998
}
1200111999

1200212000
/// Check whether a template can be declared within this scope.
@@ -12876,11 +12874,6 @@ class Sema final : public SemaBase {
1287612874

1287712875
/// We are performing partial ordering for template template parameters.
1287812876
PartialOrderingTTP,
12879-
12880-
/// We are Checking a Template Parameter, so for any diagnostics which
12881-
/// occur in this scope, we will add a context note which points to this
12882-
/// template parameter.
12883-
CheckTemplateParameter,
1288412877
} Kind;
1288512878

1288612879
/// Was the enclosing context a non-instantiation SFINAE context?
@@ -13108,11 +13101,6 @@ class Sema final : public SemaBase {
1310813101
PartialOrderingTTP, TemplateDecl *PArg,
1310913102
SourceRange InstantiationRange = SourceRange());
1311013103

13111-
struct CheckTemplateParameter {};
13112-
/// \brief Note that we are checking a template parameter.
13113-
InstantiatingTemplate(Sema &SemaRef, CheckTemplateParameter,
13114-
NamedDecl *Param);
13115-
1311613104
/// Note that we have finished instantiating this template.
1311713105
void Clear();
1311813106

@@ -13146,13 +13134,6 @@ class Sema final : public SemaBase {
1314613134
InstantiatingTemplate &operator=(const InstantiatingTemplate &) = delete;
1314713135
};
1314813136

13149-
/// For any diagnostics which occur within its scope, adds a context note
13150-
/// pointing to the declaration of the template parameter.
13151-
struct CheckTemplateParameterRAII : InstantiatingTemplate {
13152-
CheckTemplateParameterRAII(Sema &S, NamedDecl *Param)
13153-
: InstantiatingTemplate(S, CheckTemplateParameter(), Param) {}
13154-
};
13155-
1315613137
bool SubstTemplateArgument(const TemplateArgumentLoc &Input,
1315713138
const MultiLevelTemplateArgumentList &TemplateArgs,
1315813139
TemplateArgumentLoc &Output,

clang/include/clang/StaticAnalyzer/Checkers/Checkers.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1765,6 +1765,10 @@ def NoUncheckedPtrMemberChecker : Checker<"NoUncheckedPtrMemberChecker">,
17651765
HelpText<"Check for no unchecked member variables.">,
17661766
Documentation<HasDocumentation>;
17671767

1768+
def NoUnretainedMemberChecker : Checker<"NoUnretainedMemberChecker">,
1769+
HelpText<"Check for no unretained member variables.">,
1770+
Documentation<HasDocumentation>;
1771+
17681772
def UnretainedLambdaCapturesChecker : Checker<"UnretainedLambdaCapturesChecker">,
17691773
HelpText<"Check unretained lambda captures.">,
17701774
Documentation<HasDocumentation>;

clang/lib/AST/ExprConstant.cpp

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16903,24 +16903,19 @@ bool Expr::EvaluateAsConstantExpr(EvalResult &Result, const ASTContext &Ctx,
1690316903
APValue::LValueBase Base(&BaseMTE);
1690416904
Info.setEvaluatingDecl(Base, Result.Val);
1690516905

16906-
if (Info.EnableNewConstInterp) {
16907-
if (!Info.Ctx.getInterpContext().evaluateAsRValue(Info, this, Result.Val))
16908-
return false;
16909-
} else {
16910-
LValue LVal;
16911-
LVal.set(Base);
16912-
// C++23 [intro.execution]/p5
16913-
// A full-expression is [...] a constant-expression
16914-
// So we need to make sure temporary objects are destroyed after having
16915-
// evaluating the expression (per C++23 [class.temporary]/p4).
16916-
FullExpressionRAII Scope(Info);
16917-
if (!::EvaluateInPlace(Result.Val, Info, LVal, this) ||
16918-
Result.HasSideEffects || !Scope.destroy())
16919-
return false;
16906+
LValue LVal;
16907+
LVal.set(Base);
16908+
// C++23 [intro.execution]/p5
16909+
// A full-expression is [...] a constant-expression
16910+
// So we need to make sure temporary objects are destroyed after having
16911+
// evaluating the expression (per C++23 [class.temporary]/p4).
16912+
FullExpressionRAII Scope(Info);
16913+
if (!::EvaluateInPlace(Result.Val, Info, LVal, this) ||
16914+
Result.HasSideEffects || !Scope.destroy())
16915+
return false;
1692016916

16921-
if (!Info.discardCleanups())
16922-
llvm_unreachable("Unhandled cleanup; missing full expression marker?");
16923-
}
16917+
if (!Info.discardCleanups())
16918+
llvm_unreachable("Unhandled cleanup; missing full expression marker?");
1692416919

1692516920
if (!CheckConstantExpression(Info, getExprLoc(), getStorageType(Ctx, this),
1692616921
Result.Val, Kind))

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1534,7 +1534,7 @@ void CodeGenFunction::GenerateCode(GlobalDecl GD, llvm::Function *Fn,
15341534
// Initialize helper which will detect jumps which can cause invalid
15351535
// lifetime markers.
15361536
if (ShouldEmitLifetimeMarkers)
1537-
Bypasses.Init(Body);
1537+
Bypasses.Init(CGM, Body);
15381538
}
15391539

15401540
// Emit the standard function prologue.

clang/lib/CodeGen/VarBypassDetector.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "VarBypassDetector.h"
1010

11+
#include "CodeGenModule.h"
1112
#include "clang/AST/Decl.h"
1213
#include "clang/AST/Expr.h"
1314
#include "clang/AST/Stmt.h"
@@ -17,21 +18,21 @@ using namespace CodeGen;
1718

1819
/// Clear the object and pre-process for the given statement, usually function
1920
/// body statement.
20-
void VarBypassDetector::Init(const Stmt *Body) {
21+
void VarBypassDetector::Init(CodeGenModule &CGM, const Stmt *Body) {
2122
FromScopes.clear();
2223
ToScopes.clear();
2324
Bypasses.clear();
2425
Scopes = {{~0U, nullptr}};
2526
unsigned ParentScope = 0;
26-
AlwaysBypassed = !BuildScopeInformation(Body, ParentScope);
27+
AlwaysBypassed = !BuildScopeInformation(CGM, Body, ParentScope);
2728
if (!AlwaysBypassed)
2829
Detect();
2930
}
3031

3132
/// Build scope information for a declaration that is part of a DeclStmt.
3233
/// Returns false if we failed to build scope information and can't tell for
3334
/// which vars are being bypassed.
34-
bool VarBypassDetector::BuildScopeInformation(const Decl *D,
35+
bool VarBypassDetector::BuildScopeInformation(CodeGenModule &CGM, const Decl *D,
3536
unsigned &ParentScope) {
3637
const VarDecl *VD = dyn_cast<VarDecl>(D);
3738
if (VD && VD->hasLocalStorage()) {
@@ -41,7 +42,7 @@ bool VarBypassDetector::BuildScopeInformation(const Decl *D,
4142

4243
if (const VarDecl *VD = dyn_cast<VarDecl>(D))
4344
if (const Expr *Init = VD->getInit())
44-
return BuildScopeInformation(Init, ParentScope);
45+
return BuildScopeInformation(CGM, Init, ParentScope);
4546

4647
return true;
4748
}
@@ -50,7 +51,7 @@ bool VarBypassDetector::BuildScopeInformation(const Decl *D,
5051
/// LabelAndGotoScopes and recursively walking the AST as needed.
5152
/// Returns false if we failed to build scope information and can't tell for
5253
/// which vars are being bypassed.
53-
bool VarBypassDetector::BuildScopeInformation(const Stmt *S,
54+
bool VarBypassDetector::BuildScopeInformation(CodeGenModule &CGM, const Stmt *S,
5455
unsigned &origParentScope) {
5556
// If this is a statement, rather than an expression, scopes within it don't
5657
// propagate out into the enclosing scope. Otherwise we have to worry about
@@ -68,12 +69,12 @@ bool VarBypassDetector::BuildScopeInformation(const Stmt *S,
6869

6970
case Stmt::SwitchStmtClass:
7071
if (const Stmt *Init = cast<SwitchStmt>(S)->getInit()) {
71-
if (!BuildScopeInformation(Init, ParentScope))
72+
if (!BuildScopeInformation(CGM, Init, ParentScope))
7273
return false;
7374
++StmtsToSkip;
7475
}
7576
if (const VarDecl *Var = cast<SwitchStmt>(S)->getConditionVariable()) {
76-
if (!BuildScopeInformation(Var, ParentScope))
77+
if (!BuildScopeInformation(CGM, Var, ParentScope))
7778
return false;
7879
++StmtsToSkip;
7980
}
@@ -86,7 +87,7 @@ bool VarBypassDetector::BuildScopeInformation(const Stmt *S,
8687
case Stmt::DeclStmtClass: {
8788
const DeclStmt *DS = cast<DeclStmt>(S);
8889
for (auto *I : DS->decls())
89-
if (!BuildScopeInformation(I, origParentScope))
90+
if (!BuildScopeInformation(CGM, I, origParentScope))
9091
return false;
9192
return true;
9293
}
@@ -126,7 +127,11 @@ bool VarBypassDetector::BuildScopeInformation(const Stmt *S,
126127
}
127128

128129
// Recursively walk the AST.
129-
if (!BuildScopeInformation(SubStmt, ParentScope))
130+
bool Result;
131+
CGM.runWithSufficientStackSpace(S->getEndLoc(), [&] {
132+
Result = BuildScopeInformation(CGM, SubStmt, ParentScope);
133+
});
134+
if (!Result)
130135
return false;
131136
}
132137
return true;

clang/lib/CodeGen/VarBypassDetector.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#ifndef LLVM_CLANG_LIB_CODEGEN_VARBYPASSDETECTOR_H
1515
#define LLVM_CLANG_LIB_CODEGEN_VARBYPASSDETECTOR_H
1616

17+
#include "CodeGenModule.h"
1718
#include "clang/AST/Decl.h"
1819
#include "llvm/ADT/DenseMap.h"
1920
#include "llvm/ADT/DenseSet.h"
@@ -50,7 +51,7 @@ class VarBypassDetector {
5051
bool AlwaysBypassed = false;
5152

5253
public:
53-
void Init(const Stmt *Body);
54+
void Init(CodeGenModule &CGM, const Stmt *Body);
5455

5556
/// Returns true if the variable declaration was by bypassed by any goto or
5657
/// switch statement.
@@ -59,8 +60,10 @@ class VarBypassDetector {
5960
}
6061

6162
private:
62-
bool BuildScopeInformation(const Decl *D, unsigned &ParentScope);
63-
bool BuildScopeInformation(const Stmt *S, unsigned &origParentScope);
63+
bool BuildScopeInformation(CodeGenModule &CGM, const Decl *D,
64+
unsigned &ParentScope);
65+
bool BuildScopeInformation(CodeGenModule &CGM, const Stmt *S,
66+
unsigned &origParentScope);
6467
void Detect();
6568
void Detect(unsigned From, unsigned To);
6669
};

0 commit comments

Comments
 (0)