Skip to content

Commit cf0006c

Browse files
committed
Merge commit 'cd4deef28e4361af19cd5a208ef51a5f0b26ee61' into feature/merge-upstream-20220110
2 parents 5049a5e + cd4deef commit cf0006c

File tree

1,697 files changed

+41030
-29281
lines changed

Some content is hidden

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

1,697 files changed

+41030
-29281
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Issue Subscriber
2+
3+
on:
4+
issues:
5+
types:
6+
- labeled
7+
8+
jobs:
9+
auto-subscribe:
10+
runs-on: ubuntu-latest
11+
if: github.repository == 'llvm/llvm-project'
12+
steps:
13+
- name: Update watchers
14+
uses: actions/github-script@v5
15+
with:
16+
github-token: ${{ secrets.ISSUE_MENTION_SECRET }}
17+
script: |
18+
const teamname = "issue-subscribers-" + context.payload.label.name.replace(/ /g, "-").replace(":","-").replace("/","-");
19+
const comment = "@llvm/" + teamname;
20+
try {
21+
// This will throw an exception if the team does not exist and no
22+
// comment will be created.
23+
team = await github.rest.teams.getByName({
24+
org: context.repo.owner,
25+
team_slug: teamname
26+
});
27+
github.rest.issues.createComment({
28+
issue_number: context.issue.number,
29+
owner: context.repo.owner,
30+
repo: context.repo.repo,
31+
body: comment
32+
});
33+
} catch (e){
34+
console.log(e);
35+
}

clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ void ClangTidyDiagnosticConsumer::checkFilters(SourceLocation Location,
719719
}
720720

721721
if (!*Context.getOptions().SystemHeaders &&
722-
Sources.isInSystemHeader(Location))
722+
(Sources.isInSystemHeader(Location) || Sources.isInSystemMacro(Location)))
723723
return;
724724

725725
// FIXME: We start with a conservative approach here, but the actual type of

clang-tools-extra/clang-tidy/abseil/DurationRewriter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,4 @@ AST_MATCHER_FUNCTION_P(ast_matchers::internal::Matcher<Stmt>,
138138
} // namespace tidy
139139
} // namespace clang
140140

141-
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_DURATIONCOMPARISONCHECK_H
141+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_DURATIONREWRITER_H

clang-tools-extra/clang-tidy/add_new_check.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -324,16 +324,20 @@ def has_auto_fix(check_name):
324324
dirname, _, check_name = check_name.partition("-")
325325

326326
checker_code = get_actual_filename(os.path.join(clang_tidy_path, dirname),
327-
get_camel_name(check_name) + '.cpp')
328-
327+
get_camel_check_name(check_name) + '.cpp')
329328
if not os.path.isfile(checker_code):
330-
return ""
329+
# Some older checks don't end with 'Check.cpp'
330+
checker_code = get_actual_filename(os.path.join(clang_tidy_path, dirname),
331+
get_camel_name(check_name) + '.cpp')
332+
if not os.path.isfile(checker_code):
333+
return ''
331334

332335
with io.open(checker_code, encoding='utf8') as f:
333336
code = f.read()
334-
if 'FixItHint' in code or "ReplacementText" in code or "fixit" in code:
335-
# Some simple heuristics to figure out if a checker has an autofix or not.
336-
return ' "Yes"'
337+
for needle in ['FixItHint', 'ReplacementText', 'fixit', 'TransformerClangTidyCheck']:
338+
if needle in code:
339+
# Some simple heuristics to figure out if a checker has an autofix or not.
340+
return ' "Yes"'
337341
return ""
338342

339343
def process_doc(doc_file):
@@ -416,7 +420,11 @@ def write_docs(module_path, module, check_name):
416420

417421
def get_camel_name(check_name):
418422
return ''.join(map(lambda elem: elem.capitalize(),
419-
check_name.split('-'))) + 'Check'
423+
check_name.split('-')))
424+
425+
426+
def get_camel_check_name(check_name):
427+
return get_camel_name(check_name) + 'Check'
420428

421429

422430
def main():
@@ -458,7 +466,7 @@ def main():
458466

459467
module = args.module
460468
check_name = args.check
461-
check_name_camel = get_camel_name(check_name)
469+
check_name_camel = get_camel_check_name(check_name)
462470
if check_name.startswith(module):
463471
print('Check name "%s" must not start with the module "%s". Exiting.' % (
464472
check_name, module))

clang-tools-extra/clang-tidy/cert/NonTrivialTypesLibcMemoryCallsCheck.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ class NonTrivialTypesLibcMemoryCallsCheck : public ClangTidyCheck {
4141
} // namespace tidy
4242
} // namespace clang
4343

44-
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_NOTTRIVIALTYPESLIBCMEMORYCALLSCHECK_H
44+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_NONTRIVIALTYPESLIBCMEMORYCALLSCHECK_H

clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
#include "clang/ASTMatchers/ASTMatchFinder.h"
1212
#include "clang/ASTMatchers/ASTMatchers.h"
1313
#include "clang/Basic/TargetInfo.h"
14+
#include "clang/Lex/PPCallbacks.h"
15+
#include "clang/Lex/Preprocessor.h"
16+
#include "clang/Lex/Token.h"
1417

1518
using namespace clang::ast_matchers;
1619

@@ -57,6 +60,10 @@ static constexpr StringRef AllowedVariadics[] = {
5760
// clang-format on
5861
};
5962

63+
static constexpr StringRef VaArgWarningMessage =
64+
"do not use va_arg to define c-style vararg functions; "
65+
"use variadic templates instead";
66+
6067
namespace {
6168
AST_MATCHER(QualType, isVAList) {
6269
ASTContext &Context = Finder->getASTContext();
@@ -106,6 +113,21 @@ AST_MATCHER_P(AdjustedType, hasOriginalType,
106113
ast_matchers::internal::Matcher<QualType>, InnerType) {
107114
return InnerType.matches(Node.getOriginalType(), Finder, Builder);
108115
}
116+
117+
class VaArgPPCallbacks : public PPCallbacks {
118+
public:
119+
VaArgPPCallbacks(ProTypeVarargCheck *Check) : Check(Check) {}
120+
121+
void MacroExpands(const Token &MacroNameTok, const MacroDefinition &MD,
122+
SourceRange Range, const MacroArgs *Args) override {
123+
if (MacroNameTok.getIdentifierInfo()->getName() == "va_arg") {
124+
Check->diag(MacroNameTok.getLocation(), VaArgWarningMessage);
125+
}
126+
}
127+
128+
private:
129+
ProTypeVarargCheck *Check;
130+
};
109131
} // namespace
110132

111133
void ProTypeVarargCheck::registerMatchers(MatchFinder *Finder) {
@@ -125,6 +147,12 @@ void ProTypeVarargCheck::registerMatchers(MatchFinder *Finder) {
125147
this);
126148
}
127149

150+
void ProTypeVarargCheck::registerPPCallbacks(const SourceManager &SM,
151+
Preprocessor *PP,
152+
Preprocessor *ModuleExpanderPP) {
153+
PP->addPPCallbacks(std::make_unique<VaArgPPCallbacks>(this));
154+
}
155+
128156
static bool hasSingleVariadicArgumentWithValue(const CallExpr *C, uint64_t I) {
129157
const auto *FDecl = dyn_cast<FunctionDecl>(C->getCalleeDecl());
130158
if (!FDecl)
@@ -153,9 +181,7 @@ void ProTypeVarargCheck::check(const MatchFinder::MatchResult &Result) {
153181
}
154182

155183
if (const auto *Matched = Result.Nodes.getNodeAs<Expr>("va_use")) {
156-
diag(Matched->getExprLoc(),
157-
"do not use va_arg to define c-style vararg functions; "
158-
"use variadic templates instead");
184+
diag(Matched->getExprLoc(), VaArgWarningMessage);
159185
}
160186

161187
if (const auto *Matched = Result.Nodes.getNodeAs<VarDecl>("va_list")) {

clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class ProTypeVarargCheck : public ClangTidyCheck {
2828
return LangOpts.CPlusPlus;
2929
}
3030
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
31+
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
32+
Preprocessor *ModuleExpanderPP) override;
3133
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
3234
};
3335

clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,11 @@ void VirtualClassDestructorCheck::check(
173173
"destructor of %0 is private and prevents using the type")
174174
<< MatchedClassOrStruct;
175175
diag(MatchedClassOrStruct->getLocation(),
176-
/*FixDescription=*/"make it public and virtual", DiagnosticIDs::Note)
176+
/*Description=*/"make it public and virtual", DiagnosticIDs::Note)
177177
<< changePrivateDestructorVisibilityTo(
178178
"public", *Destructor, *Result.SourceManager, getLangOpts());
179179
diag(MatchedClassOrStruct->getLocation(),
180-
/*FixDescription=*/"make it protected", DiagnosticIDs::Note)
180+
/*Description=*/"make it protected", DiagnosticIDs::Note)
181181
<< changePrivateDestructorVisibilityTo(
182182
"protected", *Destructor, *Result.SourceManager, getLangOpts());
183183

clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ void DefinitionsInHeadersCheck::check(const MatchFinder::MatchResult &Result) {
130130
// inline is not allowed for main function.
131131
if (FD->isMain())
132132
return;
133-
diag(FD->getLocation(), /*FixDescription=*/"make as 'inline'",
133+
diag(FD->getLocation(), /*Description=*/"make as 'inline'",
134134
DiagnosticIDs::Note)
135135
<< FixItHint::CreateInsertion(FD->getInnerLocStart(), "inline ");
136136
} else if (const auto *VD = dyn_cast<VarDecl>(ND)) {

clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,75 @@ static bool paramReferredExactlyOnce(const CXXConstructorDecl *Ctor,
105105
return ExactlyOneUsageVisitor(ParamDecl).hasExactlyOneUsageIn(Ctor);
106106
}
107107

108+
/// Returns true if the given constructor is part of a lvalue/rvalue reference
109+
/// pair, i.e. `Param` is of lvalue reference type, and there exists another
110+
/// constructor such that:
111+
/// - it has the same number of parameters as `Ctor`.
112+
/// - the parameter at the same index as `Param` is an rvalue reference
113+
/// of the same pointee type
114+
/// - all other parameters have the same type as the corresponding parameter in
115+
/// `Ctor` or are rvalue references with the same pointee type.
116+
/// Examples:
117+
/// A::A(const B& Param)
118+
/// A::A(B&&)
119+
///
120+
/// A::A(const B& Param, const C&)
121+
/// A::A(B&& Param, C&&)
122+
///
123+
/// A::A(const B&, const C& Param)
124+
/// A::A(B&&, C&& Param)
125+
///
126+
/// A::A(const B&, const C& Param)
127+
/// A::A(const B&, C&& Param)
128+
///
129+
/// A::A(const B& Param, int)
130+
/// A::A(B&& Param, int)
131+
static bool hasRValueOverload(const CXXConstructorDecl *Ctor,
132+
const ParmVarDecl *Param) {
133+
if (!Param->getType().getCanonicalType()->isLValueReferenceType()) {
134+
// The parameter is passed by value.
135+
return false;
136+
}
137+
const int ParamIdx = Param->getFunctionScopeIndex();
138+
const CXXRecordDecl *Record = Ctor->getParent();
139+
140+
// Check whether a ctor `C` forms a pair with `Ctor` under the aforementionned
141+
// rules.
142+
const auto IsRValueOverload = [&Ctor, ParamIdx](const CXXConstructorDecl *C) {
143+
if (C == Ctor || C->isDeleted() ||
144+
C->getNumParams() != Ctor->getNumParams())
145+
return false;
146+
for (int I = 0, E = C->getNumParams(); I < E; ++I) {
147+
const clang::QualType CandidateParamType =
148+
C->parameters()[I]->getType().getCanonicalType();
149+
const clang::QualType CtorParamType =
150+
Ctor->parameters()[I]->getType().getCanonicalType();
151+
const bool IsLValueRValuePair =
152+
CtorParamType->isLValueReferenceType() &&
153+
CandidateParamType->isRValueReferenceType() &&
154+
CandidateParamType->getPointeeType()->getUnqualifiedDesugaredType() ==
155+
CtorParamType->getPointeeType()->getUnqualifiedDesugaredType();
156+
if (I == ParamIdx) {
157+
// The parameter of interest must be paired.
158+
if (!IsLValueRValuePair)
159+
return false;
160+
} else {
161+
// All other parameters can be similar or paired.
162+
if (!(CandidateParamType == CtorParamType || IsLValueRValuePair))
163+
return false;
164+
}
165+
}
166+
return true;
167+
};
168+
169+
for (const auto *Candidate : Record->ctors()) {
170+
if (IsRValueOverload(Candidate)) {
171+
return true;
172+
}
173+
}
174+
return false;
175+
}
176+
108177
/// Find all references to \p ParamDecl across all of the
109178
/// redeclarations of \p Ctor.
110179
static SmallVector<const ParmVarDecl *, 2>
@@ -188,6 +257,10 @@ void PassByValueCheck::check(const MatchFinder::MatchResult &Result) {
188257
*Result.Context))
189258
return;
190259

260+
// Do not trigger if we find a paired constructor with an rvalue.
261+
if (hasRValueOverload(Ctor, ParamDecl))
262+
return;
263+
191264
auto Diag = diag(ParamDecl->getBeginLoc(), "pass by value and use std::move");
192265

193266
// If we received a `const&` type, we need to rewrite the function

0 commit comments

Comments
 (0)