Skip to content

Commit f1798e8

Browse files
committed
Merge branch 'upstream' into x86-insertvector-subvbroadcast-oneuse
2 parents 5b93950 + 1b17d1e commit f1798e8

File tree

455 files changed

+10462
-10630
lines changed

Some content is hidden

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

455 files changed

+10462
-10630
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/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
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>]>;

clang/include/clang/Basic/Builtins.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -459,14 +459,8 @@ bool evaluateRequiredTargetFeatures(
459459

460460
/// Kinds of BuiltinTemplateDecl.
461461
enum BuiltinTemplateKind : int {
462-
/// This names the __make_integer_seq BuiltinTemplateDecl.
463-
BTK__make_integer_seq,
464-
465-
/// This names the __type_pack_element BuiltinTemplateDecl.
466-
BTK__type_pack_element,
467-
468-
/// This names the __builtin_common_type BuiltinTemplateDecl.
469-
BTK__builtin_common_type,
462+
#define BuiltinTemplate(BTName) BTK##BTName,
463+
#include "clang/Basic/BuiltinTemplates.inc"
470464
};
471465

472466
} // end namespace clang

clang/include/clang/Basic/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ clang_tablegen(BuiltinsX86_64.inc -gen-clang-builtins
9696
SOURCE BuiltinsX86_64.td
9797
TARGET ClangBuiltinsX86_64)
9898

99+
clang_tablegen(BuiltinTemplates.inc -gen-clang-builtin-templates
100+
SOURCE BuiltinTemplates.td
101+
TARGET ClangBuiltinTemplates)
102+
99103
# ARM NEON and MVE
100104
clang_tablegen(arm_neon.inc -gen-arm-neon-sema
101105
SOURCE arm_neon.td

clang/lib/AST/ASTContext.cpp

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,28 +1198,14 @@ ASTContext::buildBuiltinTemplateDecl(BuiltinTemplateKind BTK,
11981198
return BuiltinTemplate;
11991199
}
12001200

1201-
BuiltinTemplateDecl *
1202-
ASTContext::getMakeIntegerSeqDecl() const {
1203-
if (!MakeIntegerSeqDecl)
1204-
MakeIntegerSeqDecl = buildBuiltinTemplateDecl(BTK__make_integer_seq,
1205-
getMakeIntegerSeqName());
1206-
return MakeIntegerSeqDecl;
1207-
}
1208-
1209-
BuiltinTemplateDecl *
1210-
ASTContext::getTypePackElementDecl() const {
1211-
if (!TypePackElementDecl)
1212-
TypePackElementDecl = buildBuiltinTemplateDecl(BTK__type_pack_element,
1213-
getTypePackElementName());
1214-
return TypePackElementDecl;
1215-
}
1216-
1217-
BuiltinTemplateDecl *ASTContext::getBuiltinCommonTypeDecl() const {
1218-
if (!BuiltinCommonTypeDecl)
1219-
BuiltinCommonTypeDecl = buildBuiltinTemplateDecl(
1220-
BTK__builtin_common_type, getBuiltinCommonTypeName());
1221-
return BuiltinCommonTypeDecl;
1222-
}
1201+
#define BuiltinTemplate(BTName) \
1202+
BuiltinTemplateDecl *ASTContext::get##BTName##Decl() const { \
1203+
if (!Decl##BTName) \
1204+
Decl##BTName = \
1205+
buildBuiltinTemplateDecl(BTK##BTName, get##BTName##Name()); \
1206+
return Decl##BTName; \
1207+
}
1208+
#include "clang/Basic/BuiltinTemplates.inc"
12231209

12241210
RecordDecl *ASTContext::buildImplicitRecord(StringRef Name,
12251211
RecordDecl::TagKind TK) const {

0 commit comments

Comments
 (0)