Skip to content

Commit 41424af

Browse files
authored
LLVM and SPIRV-LLVM-Translator pulldown
2 parents a33ffb5 + 88c64da commit 41424af

File tree

4,219 files changed

+63352
-26974
lines changed

Some content is hidden

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

4,219 files changed

+63352
-26974
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ void ProTypeMemberInitCheck::checkMissingMemberInitializer(
454454
return;
455455
// Don't suggest fixes for enums because we don't know a good default.
456456
// Don't suggest fixes for bitfields because in-class initialization is not
457-
// possible until C++2a.
457+
// possible until C++20.
458458
if (F->getType()->isEnumeralType() ||
459459
(!getLangOpts().CPlusPlus20 && F->isBitField()))
460460
return;

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

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "ProTypeVarargCheck.h"
1010
#include "clang/AST/ASTContext.h"
1111
#include "clang/ASTMatchers/ASTMatchFinder.h"
12+
#include "clang/ASTMatchers/ASTMatchers.h"
1213

1314
using namespace clang::ast_matchers;
1415

@@ -18,11 +19,72 @@ namespace cppcoreguidelines {
1819

1920
const internal::VariadicDynCastAllOfMatcher<Stmt, VAArgExpr> vAArgExpr;
2021

22+
static constexpr StringRef AllowedVariadics[] = {
23+
// clang-format off
24+
"__builtin_isgreater",
25+
"__builtin_isgreaterequal",
26+
"__builtin_isless",
27+
"__builtin_islessequal",
28+
"__builtin_islessgreater",
29+
"__builtin_isunordered",
30+
"__builtin_fpclassify",
31+
"__builtin_isfinite",
32+
"__builtin_isinf",
33+
"__builtin_isinf_sign",
34+
"__builtin_isnan",
35+
"__builtin_isnormal",
36+
"__builtin_signbit",
37+
"__builtin_constant_p",
38+
"__builtin_classify_type",
39+
"__builtin_va_start",
40+
"__builtin_assume_aligned", // Documented as variadic to support default
41+
// parameters.
42+
"__builtin_prefetch", // Documented as variadic to support default
43+
// parameters.
44+
"__builtin_shufflevector", // Documented as variadic but with a defined
45+
// number of args based on vector size.
46+
"__builtin_convertvector",
47+
"__builtin_call_with_static_chain",
48+
"__builtin_annotation",
49+
"__builtin_add_overflow",
50+
"__builtin_sub_overflow",
51+
"__builtin_mul_overflow",
52+
"__builtin_preserve_access_index",
53+
"__builtin_nontemporal_store",
54+
"__builtin_nontemporal_load",
55+
"__builtin_ms_va_start",
56+
// clang-format on
57+
};
58+
59+
namespace {
60+
AST_MATCHER(QualType, isVAList) {
61+
ASTContext &Context = Finder->getASTContext();
62+
QualType Desugar = Node.getDesugaredType(Context);
63+
return Context.getBuiltinVaListType().getDesugaredType(Context) == Desugar ||
64+
Context.getBuiltinMSVaListType().getDesugaredType(Context) == Desugar;
65+
}
66+
67+
AST_MATCHER_P(AdjustedType, hasOriginalType,
68+
ast_matchers::internal::Matcher<QualType>, InnerType) {
69+
return InnerType.matches(Node.getOriginalType(), Finder, Builder);
70+
}
71+
} // namespace
72+
2173
void ProTypeVarargCheck::registerMatchers(MatchFinder *Finder) {
2274
Finder->addMatcher(vAArgExpr().bind("va_use"), this);
2375

2476
Finder->addMatcher(
25-
callExpr(callee(functionDecl(isVariadic()))).bind("callvararg"), this);
77+
callExpr(callee(functionDecl(isVariadic(),
78+
unless(hasAnyName(AllowedVariadics)))))
79+
.bind("callvararg"),
80+
this);
81+
82+
Finder->addMatcher(
83+
varDecl(unless(parmVarDecl()),
84+
hasType(qualType(
85+
anyOf(isVAList(), decayedType(hasOriginalType(isVAList()))))))
86+
.bind("va_list"),
87+
this);
2688
}
2789

2890
static bool hasSingleVariadicArgumentWithValue(const CallExpr *C, uint64_t I) {
@@ -54,7 +116,7 @@ void ProTypeVarargCheck::check(const MatchFinder::MatchResult &Result) {
54116

55117
if (const auto *Matched = Result.Nodes.getNodeAs<Expr>("va_use")) {
56118
diag(Matched->getExprLoc(),
57-
"do not use va_start/va_arg to define c-style vararg functions; "
119+
"do not use va_arg to define c-style vararg functions; "
58120
"use variadic templates instead");
59121
}
60122

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ static bool areEquivalentExpr(const Expr *Left, const Expr *Right) {
7272
Expr::const_child_iterator LeftIter = Left->child_begin();
7373
Expr::const_child_iterator RightIter = Right->child_begin();
7474
while (LeftIter != Left->child_end() && RightIter != Right->child_end()) {
75-
if (!areEquivalentExpr(dyn_cast<Expr>(*LeftIter),
76-
dyn_cast<Expr>(*RightIter)))
75+
if (!areEquivalentExpr(dyn_cast_or_null<Expr>(*LeftIter),
76+
dyn_cast_or_null<Expr>(*RightIter)))
7777
return false;
7878
++LeftIter;
7979
++RightIter;
@@ -117,6 +117,9 @@ static bool areEquivalentExpr(const Expr *Left, const Expr *Right) {
117117
case Stmt::MemberExprClass:
118118
return cast<MemberExpr>(Left)->getMemberDecl() ==
119119
cast<MemberExpr>(Right)->getMemberDecl();
120+
case Stmt::CXXFoldExprClass:
121+
return cast<CXXFoldExpr>(Left)->getOperator() ==
122+
cast<CXXFoldExpr>(Right)->getOperator();
120123
case Stmt::CXXFunctionalCastExprClass:
121124
case Stmt::CStyleCastExprClass:
122125
return cast<ExplicitCastExpr>(Left)->getTypeAsWritten() ==

clang-tools-extra/clang-tidy/modernize/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ add_clang_library(clangTidyModernizeModule
1919
RawStringLiteralCheck.cpp
2020
RedundantVoidArgCheck.cpp
2121
ReplaceAutoPtrCheck.cpp
22+
ReplaceDisallowCopyAndAssignMacroCheck.cpp
2223
ReplaceRandomShuffleCheck.cpp
2324
ReturnBracedInitListCheck.cpp
2425
ShrinkToFitCheck.cpp

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,7 @@ void LoopConvertCheck::doConversion(
621621
QualType Type = Context->getAutoDeductType();
622622
if (!Descriptor.ElemType.isNull() && Descriptor.ElemType->isFundamentalType())
623623
Type = Descriptor.ElemType.getUnqualifiedType();
624+
Type = Type.getDesugaredType(*Context);
624625

625626
// If the new variable name is from the aliased variable, then the reference
626627
// type for the new variable should only be used if the aliased variable was

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "RawStringLiteralCheck.h"
2222
#include "RedundantVoidArgCheck.h"
2323
#include "ReplaceAutoPtrCheck.h"
24+
#include "ReplaceDisallowCopyAndAssignMacroCheck.h"
2425
#include "ReplaceRandomShuffleCheck.h"
2526
#include "ReturnBracedInitListCheck.h"
2627
#include "ShrinkToFitCheck.h"
@@ -67,6 +68,8 @@ class ModernizeModule : public ClangTidyModule {
6768
"modernize-redundant-void-arg");
6869
CheckFactories.registerCheck<ReplaceAutoPtrCheck>(
6970
"modernize-replace-auto-ptr");
71+
CheckFactories.registerCheck<ReplaceDisallowCopyAndAssignMacroCheck>(
72+
"modernize-replace-disallow-copy-and-assign-macro");
7073
CheckFactories.registerCheck<ReplaceRandomShuffleCheck>(
7174
"modernize-replace-random-shuffle");
7275
CheckFactories.registerCheck<ReturnBracedInitListCheck>(
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
//===--- ReplaceDisallowCopyAndAssignMacroCheck.cpp - clang-tidy ----------===//
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+
#include "ReplaceDisallowCopyAndAssignMacroCheck.h"
10+
#include "clang/Frontend/CompilerInstance.h"
11+
#include "clang/Lex/MacroArgs.h"
12+
#include "llvm/Support/FormatVariadic.h"
13+
14+
namespace clang {
15+
namespace tidy {
16+
namespace modernize {
17+
18+
namespace {
19+
20+
class ReplaceDisallowCopyAndAssignMacroCallbacks : public PPCallbacks {
21+
public:
22+
explicit ReplaceDisallowCopyAndAssignMacroCallbacks(
23+
ReplaceDisallowCopyAndAssignMacroCheck &Check, Preprocessor &PP)
24+
: Check(Check), PP(PP) {}
25+
26+
void MacroExpands(const Token &MacroNameTok, const MacroDefinition &MD,
27+
SourceRange Range, const MacroArgs *Args) override {
28+
IdentifierInfo *Info = MacroNameTok.getIdentifierInfo();
29+
if (!Info || !Args || Args->getNumMacroArguments() != 1)
30+
return;
31+
if (Info->getName() != Check.getMacroName())
32+
return;
33+
// The first argument to the DISALLOW_COPY_AND_ASSIGN macro is exptected to
34+
// be the class name.
35+
const Token *ClassNameTok = Args->getUnexpArgument(0);
36+
if (Args->ArgNeedsPreexpansion(ClassNameTok, PP))
37+
// For now we only support simple argument that don't need to be
38+
// pre-expanded.
39+
return;
40+
clang::IdentifierInfo *ClassIdent = ClassNameTok->getIdentifierInfo();
41+
if (!ClassIdent)
42+
return;
43+
44+
std::string Replacement = llvm::formatv(
45+
R"cpp({0}(const {0} &) = delete;
46+
const {0} &operator=(const {0} &) = delete{1})cpp",
47+
ClassIdent->getName(), shouldAppendSemi(Range) ? ";" : "");
48+
49+
Check.diag(MacroNameTok.getLocation(),
50+
"prefer deleting copy constructor and assignment operator over "
51+
"using macro '%0'")
52+
<< Check.getMacroName()
53+
<< FixItHint::CreateReplacement(
54+
PP.getSourceManager().getExpansionRange(Range), Replacement);
55+
}
56+
57+
private:
58+
/// \returns \c true if the next token after the given \p MacroLoc is \b not a
59+
/// semicolon.
60+
bool shouldAppendSemi(SourceRange MacroLoc) {
61+
llvm::Optional<Token> Next = Lexer::findNextToken(
62+
MacroLoc.getEnd(), PP.getSourceManager(), PP.getLangOpts());
63+
return !(Next && Next->is(tok::semi));
64+
}
65+
66+
ReplaceDisallowCopyAndAssignMacroCheck &Check;
67+
Preprocessor &PP;
68+
};
69+
} // namespace
70+
71+
ReplaceDisallowCopyAndAssignMacroCheck::ReplaceDisallowCopyAndAssignMacroCheck(
72+
StringRef Name, ClangTidyContext *Context)
73+
: ClangTidyCheck(Name, Context),
74+
MacroName(Options.get("MacroName", "DISALLOW_COPY_AND_ASSIGN")) {}
75+
76+
void ReplaceDisallowCopyAndAssignMacroCheck::registerPPCallbacks(
77+
const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) {
78+
PP->addPPCallbacks(
79+
::std::make_unique<ReplaceDisallowCopyAndAssignMacroCallbacks>(
80+
*this, *ModuleExpanderPP));
81+
}
82+
83+
void ReplaceDisallowCopyAndAssignMacroCheck::storeOptions(
84+
ClangTidyOptions::OptionMap &Opts) {
85+
Options.store(Opts, "MacroName", MacroName);
86+
}
87+
88+
} // namespace modernize
89+
} // namespace tidy
90+
} // namespace clang
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
//===--- ReplaceDisallowCopyAndAssignMacroCheck.h - clang-tidy --*- 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+
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACEDISALLOWCOPYANDASSIGNMACROCHECK_H
10+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACEDISALLOWCOPYANDASSIGNMACROCHECK_H
11+
12+
#include "../ClangTidyCheck.h"
13+
14+
namespace clang {
15+
namespace tidy {
16+
namespace modernize {
17+
18+
/// This check finds macro expansions of ``DISALLOW_COPY_AND_ASSIGN(Type)`` and
19+
/// replaces them with a deleted copy constructor and a deleted assignment
20+
/// operator.
21+
///
22+
/// Before:
23+
/// ~~~{.cpp}
24+
/// class Foo {
25+
/// private:
26+
/// DISALLOW_COPY_AND_ASSIGN(Foo);
27+
/// };
28+
/// ~~~
29+
///
30+
/// After:
31+
/// ~~~{.cpp}
32+
/// class Foo {
33+
/// private:
34+
/// Foo(const Foo &) = delete;
35+
/// const Foo &operator=(const Foo &) = delete;
36+
/// };
37+
/// ~~~
38+
///
39+
/// For the user-facing documentation see:
40+
/// http://clang.llvm.org/extra/clang-tidy/checks/modernize-replace-disallow-copy-and-assign-macro.html
41+
class ReplaceDisallowCopyAndAssignMacroCheck : public ClangTidyCheck {
42+
public:
43+
ReplaceDisallowCopyAndAssignMacroCheck(StringRef Name,
44+
ClangTidyContext *Context);
45+
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
46+
return LangOpts.CPlusPlus11;
47+
}
48+
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
49+
Preprocessor *ModuleExpanderPP) override;
50+
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
51+
52+
const std::string &getMacroName() const { return MacroName; }
53+
54+
private:
55+
const std::string MacroName;
56+
};
57+
58+
} // namespace modernize
59+
} // namespace tidy
60+
} // namespace clang
61+
62+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACEDISALLOWCOPYANDASSIGNMACROCHECK_H

clang-tools-extra/clang-tidy/readability/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ add_clang_library(clangTidyReadabilityModule
4242
StringCompareCheck.cpp
4343
UniqueptrDeleteReleaseCheck.cpp
4444
UppercaseLiteralSuffixCheck.cpp
45+
UseAnyOfAllOfCheck.cpp
4546

4647
LINK_LIBS
48+
clangAnalysis
4749
clangAST
4850
clangASTMatchers
4951
clangBasic

clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "StringCompareCheck.h"
4646
#include "UniqueptrDeleteReleaseCheck.h"
4747
#include "UppercaseLiteralSuffixCheck.h"
48+
#include "UseAnyOfAllOfCheck.h"
4849

4950
namespace clang {
5051
namespace tidy {
@@ -125,6 +126,8 @@ class ReadabilityModule : public ClangTidyModule {
125126
"readability-uniqueptr-delete-release");
126127
CheckFactories.registerCheck<UppercaseLiteralSuffixCheck>(
127128
"readability-uppercase-literal-suffix");
129+
CheckFactories.registerCheck<UseAnyOfAllOfCheck>(
130+
"readability-use-anyofallof");
128131
}
129132
};
130133

0 commit comments

Comments
 (0)