Skip to content

Commit d775205

Browse files
authored
merge main into amd-staging (llvm#862)
2 parents 08a31b4 + 78b6c3a commit d775205

File tree

606 files changed

+14301
-13436
lines changed

Some content is hidden

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

606 files changed

+14301
-13436
lines changed

clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "UnnecessaryValueParamCheck.h"
10-
1110
#include "../utils/DeclRefExprUtils.h"
1211
#include "../utils/FixItHintUtils.h"
1312
#include "../utils/Matchers.h"
@@ -30,14 +29,6 @@ std::string paramNameOrIndex(StringRef Name, size_t Index) {
3029
.str();
3130
}
3231

33-
bool isReferencedOutsideOfCallExpr(const FunctionDecl &Function,
34-
ASTContext &Context) {
35-
auto Matches = match(declRefExpr(to(functionDecl(equalsNode(&Function))),
36-
unless(hasAncestor(callExpr()))),
37-
Context);
38-
return !Matches.empty();
39-
}
40-
4132
bool hasLoopStmtAncestor(const DeclRefExpr &DeclRef, const Decl &Decl,
4233
ASTContext &Context) {
4334
auto Matches = match(
@@ -155,12 +146,9 @@ void UnnecessaryValueParamCheck::handleConstRefFix(const FunctionDecl &Function,
155146
// Do not propose fixes when:
156147
// 1. the ParmVarDecl is in a macro, since we cannot place them correctly
157148
// 2. the function is virtual as it might break overrides
158-
// 3. the function is referenced outside of a call expression within the
159-
// compilation unit as the signature change could introduce build errors.
160-
// 4. the function is an explicit template/ specialization.
149+
// 3. the function is an explicit template/ specialization.
161150
const auto *Method = llvm::dyn_cast<CXXMethodDecl>(&Function);
162151
if (Param.getBeginLoc().isMacroID() || (Method && Method->isVirtual()) ||
163-
isReferencedOutsideOfCallExpr(Function, Context) ||
164152
Function.getTemplateSpecializationKind() == TSK_ExplicitSpecialization)
165153
return;
166154
for (const auto *FunctionDecl = &Function; FunctionDecl != nullptr;

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ Changes in existing checks
115115
<clang-tidy/checks/misc/redundant-expression>` check by providing additional
116116
examples and fixing some macro related false positives.
117117

118+
- Improved :doc:`performance/unnecessary-value-param
119+
<clang-tidy/checks/performance/unnecessary-value-param>` check performance by
120+
tolerating fix-it breaking compilation when functions is used as pointers
121+
to avoid matching usage of functions within the current compilation unit.
122+
118123
Removed checks
119124
^^^^^^^^^^^^^^
120125

clang-tools-extra/docs/clang-tidy/checks/performance/unnecessary-value-param.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ Will become:
5454
Field = std::move(Value);
5555
}
5656

57+
Because the fix-it needs to change the signature of the function, it may break
58+
builds if the function is used in multiple translation units or some codes
59+
depends on funcion signatures.
60+
5761
Options
5862
-------
5963

clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-value-param.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -332,11 +332,7 @@ void PositiveNonConstDeclaration(const ExpensiveToCopyType A) {
332332

333333
void PositiveOnlyMessageAsReferencedInCompilationUnit(ExpensiveToCopyType A) {
334334
// CHECK-MESSAGES: [[@LINE-1]]:75: warning: the parameter 'A' is copied
335-
// CHECK-FIXES: void PositiveOnlyMessageAsReferencedInCompilationUnit(ExpensiveToCopyType A) {
336-
}
337-
338-
void ReferenceFunctionOutsideOfCallExpr() {
339-
void (*ptr)(ExpensiveToCopyType) = &PositiveOnlyMessageAsReferencedInCompilationUnit;
335+
// CHECK-FIXES: void PositiveOnlyMessageAsReferencedInCompilationUnit(const ExpensiveToCopyType& A) {
340336
}
341337

342338
void PositiveMessageAndFixAsFunctionIsCalled(ExpensiveToCopyType A) {

clang/docs/ReleaseNotes.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,12 @@ Improvements to Clang's diagnostics
199199
- Diagnostics on chained comparisons (``a < b < c``) are now an error by default. This can be disabled with
200200
``-Wno-error=parentheses``.
201201

202+
- The :doc:`ThreadSafetyAnalysis` now supports ``-Wthread-safety-pointer``,
203+
which enables warning on passing or returning pointers to guarded variables
204+
as function arguments or return value respectively. Note that
205+
:doc:`ThreadSafetyAnalysis` still does not perform alias analysis. The
206+
feature will be default-enabled with ``-Wthread-safety`` in a future release.
207+
202208
Improvements to Clang's time-trace
203209
----------------------------------
204210

clang/docs/ThreadSafetyAnalysis.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,8 +515,12 @@ Warning flags
515515
+ ``-Wthread-safety-analysis``: The core analysis.
516516
+ ``-Wthread-safety-precise``: Requires that mutex expressions match precisely.
517517
This warning can be disabled for code which has a lot of aliases.
518-
+ ``-Wthread-safety-reference``: Checks when guarded members are passed by reference.
518+
+ ``-Wthread-safety-reference``: Checks when guarded members are passed or
519+
returned by reference.
519520

521+
* ``-Wthread-safety-pointer``: Checks when passing or returning pointers to
522+
guarded variables, or pointers to guarded data, as function argument or
523+
return value respectively.
520524

521525
:ref:`negative` are an experimental feature, which are enabled with:
522526

clang/include/clang/AST/ASTContext.h

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -410,14 +410,8 @@ class ASTContext : public RefCountedBase<ASTContext> {
410410
/// The identifier 'NSCopying'.
411411
IdentifierInfo *NSCopyingName = nullptr;
412412

413-
/// The identifier '__make_integer_seq'.
414-
mutable IdentifierInfo *MakeIntegerSeqName = nullptr;
415-
416-
/// The identifier '__type_pack_element'.
417-
mutable IdentifierInfo *TypePackElementName = nullptr;
418-
419-
/// The identifier '__builtin_common_type'.
420-
mutable IdentifierInfo *BuiltinCommonTypeName = nullptr;
413+
#define BuiltinTemplate(BTName) mutable IdentifierInfo *Name##BTName = nullptr;
414+
#include "clang/Basic/BuiltinTemplates.inc"
421415

422416
QualType ObjCConstantStringType;
423417
mutable RecordDecl *CFConstantStringTagDecl = nullptr;
@@ -629,9 +623,10 @@ class ASTContext : public RefCountedBase<ASTContext> {
629623

630624
TranslationUnitDecl *TUDecl = nullptr;
631625
mutable ExternCContextDecl *ExternCContext = nullptr;
632-
mutable BuiltinTemplateDecl *MakeIntegerSeqDecl = nullptr;
633-
mutable BuiltinTemplateDecl *TypePackElementDecl = nullptr;
634-
mutable BuiltinTemplateDecl *BuiltinCommonTypeDecl = nullptr;
626+
627+
#define BuiltinTemplate(BTName) \
628+
mutable BuiltinTemplateDecl *Decl##BTName = nullptr;
629+
#include "clang/Basic/BuiltinTemplates.inc"
635630

636631
/// The associated SourceManager object.
637632
SourceManager &SourceMgr;
@@ -1157,9 +1152,9 @@ class ASTContext : public RefCountedBase<ASTContext> {
11571152
}
11581153

11591154
ExternCContextDecl *getExternCContextDecl() const;
1160-
BuiltinTemplateDecl *getMakeIntegerSeqDecl() const;
1161-
BuiltinTemplateDecl *getTypePackElementDecl() const;
1162-
BuiltinTemplateDecl *getBuiltinCommonTypeDecl() const;
1155+
1156+
#define BuiltinTemplate(BTName) BuiltinTemplateDecl *get##BTName##Decl() const;
1157+
#include "clang/Basic/BuiltinTemplates.inc"
11631158

11641159
// Builtin Types.
11651160
CanQualType VoidTy;
@@ -2107,23 +2102,13 @@ class ASTContext : public RefCountedBase<ASTContext> {
21072102
return BoolName;
21082103
}
21092104

2110-
IdentifierInfo *getMakeIntegerSeqName() const {
2111-
if (!MakeIntegerSeqName)
2112-
MakeIntegerSeqName = &Idents.get("__make_integer_seq");
2113-
return MakeIntegerSeqName;
2114-
}
2115-
2116-
IdentifierInfo *getTypePackElementName() const {
2117-
if (!TypePackElementName)
2118-
TypePackElementName = &Idents.get("__type_pack_element");
2119-
return TypePackElementName;
2120-
}
2121-
2122-
IdentifierInfo *getBuiltinCommonTypeName() const {
2123-
if (!BuiltinCommonTypeName)
2124-
BuiltinCommonTypeName = &Idents.get("__builtin_common_type");
2125-
return BuiltinCommonTypeName;
2105+
#define BuiltinTemplate(BTName) \
2106+
IdentifierInfo *get##BTName##Name() const { \
2107+
if (!Name##BTName) \
2108+
Name##BTName = &Idents.get(#BTName); \
2109+
return Name##BTName; \
21262110
}
2111+
#include "clang/Basic/BuiltinTemplates.inc"
21272112

21282113
/// Retrieve the Objective-C "instancetype" type, if already known;
21292114
/// otherwise, returns a NULL type;

clang/include/clang/AST/DeclID.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,20 +71,14 @@ enum PredefinedDeclIDs {
7171
/// The extern "C" context.
7272
PREDEF_DECL_EXTERN_C_CONTEXT_ID,
7373

74-
/// The internal '__make_integer_seq' template.
75-
PREDEF_DECL_MAKE_INTEGER_SEQ_ID,
76-
7774
/// The internal '__NSConstantString' typedef.
7875
PREDEF_DECL_CF_CONSTANT_STRING_ID,
7976

8077
/// The internal '__NSConstantString' tag type.
8178
PREDEF_DECL_CF_CONSTANT_STRING_TAG_ID,
8279

83-
/// The internal '__type_pack_element' template.
84-
PREDEF_DECL_TYPE_PACK_ELEMENT_ID,
85-
86-
/// The internal '__builtin_common_type' template.
87-
PREDEF_DECL_COMMON_TYPE_ID,
80+
#define BuiltinTemplate(BTName) PREDEF_DECL##BTName##_ID,
81+
#include "clang/Basic/BuiltinTemplates.inc"
8882

8983
/// The number of declaration IDs that are predefined.
9084
NUM_PREDEF_DECL_IDS

clang/include/clang/Analysis/Analyses/ThreadSafety.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ enum ProtectedOperationKind {
5454

5555
/// Returning a pt-guarded variable by reference.
5656
POK_PtReturnByRef,
57+
58+
/// Passing pointer to a guarded variable.
59+
POK_PassPointer,
60+
61+
/// Passing a pt-guarded pointer.
62+
POK_PtPassPointer,
63+
64+
/// Returning pointer to a guarded variable.
65+
POK_ReturnPointer,
66+
67+
/// Returning a pt-guarded pointer.
68+
POK_PtReturnPointer,
5769
};
5870

5971
/// This enum distinguishes between different kinds of lock actions. For
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//===--- BuiltinTemplates.td - Clang builtin template aliases ---*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
class TemplateArg<string name> {
10+
string Name = name;
11+
}
12+
13+
class Template<list<TemplateArg> args, string name> : TemplateArg<name> {
14+
list<TemplateArg> Args = args;
15+
}
16+
17+
class Class<string name, bit is_variadic = 0> : TemplateArg<name> {
18+
bit IsVariadic = is_variadic;
19+
}
20+
21+
class NTTP<string type_name, string name, bit is_variadic = 0> : TemplateArg<name> {
22+
string TypeName = type_name;
23+
bit IsVariadic = is_variadic;
24+
}
25+
26+
class BuiltinNTTP<string type_name> : TemplateArg<""> {
27+
string TypeName = type_name;
28+
}
29+
30+
def SizeT : BuiltinNTTP<"size_t"> {}
31+
32+
class BuiltinTemplate<list<TemplateArg> template_head> {
33+
list<TemplateArg> TemplateHead = template_head;
34+
}
35+
36+
// template <template <class T, T... Ints> IntSeq, class T, T N>
37+
def __make_integer_seq : BuiltinTemplate<
38+
[Template<[Class<"T">, NTTP<"T", "Ints", /*is_variadic=*/1>], "IntSeq">, Class<"T">, NTTP<"T", "N">]>;
39+
40+
// template <size_t, class... T>
41+
def __type_pack_element : BuiltinTemplate<
42+
[SizeT, Class<"T", /*is_variadic=*/1>]>;
43+
44+
// template <template <class... Args> BaseTemplate,
45+
// template <class TypeMember> HasTypeMember,
46+
// class HasNoTypeMember
47+
// class... Ts>
48+
def __builtin_common_type : BuiltinTemplate<
49+
[Template<[Class<"Args", /*is_variadic=*/1>], "BaseTemplate">,
50+
Template<[Class<"TypeMember">], "HasTypeMember">,
51+
Class<"HasNoTypeMember">,
52+
Class<"Ts", /*is_variadic=*/1>]>;

0 commit comments

Comments
 (0)