Skip to content

Commit 1e83db8

Browse files
rebase
Created using spr 1.3.6
2 parents e8b5f80 + 17dc500 commit 1e83db8

File tree

1,201 files changed

+15826
-7740
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,201 files changed

+15826
-7740
lines changed

bolt/lib/Core/BinaryContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2517,7 +2517,7 @@ BinaryContext::calculateEmittedSize(BinaryFunction &BF, bool FixBranches) {
25172517
// Clean-up the effect of the code emission.
25182518
for (const MCSymbol &Symbol : Assembler.symbols()) {
25192519
MCSymbol *MutableSymbol = const_cast<MCSymbol *>(&Symbol);
2520-
MutableSymbol->setUndefined();
2520+
MutableSymbol->setFragment(nullptr);
25212521
MutableSymbol->setIsRegistered(false);
25222522
}
25232523

bolt/lib/Passes/BinaryPasses.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ Error CleanMCState::runOnFunctions(BinaryContext &BC) {
662662
if (S->isDefined()) {
663663
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: Symbol \"" << S->getName()
664664
<< "\" is already defined\n");
665-
const_cast<MCSymbol *>(S)->setUndefined();
665+
const_cast<MCSymbol *>(S)->setFragment(nullptr);
666666
}
667667
if (S->isRegistered()) {
668668
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: Symbol \"" << S->getName()

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,10 @@ ClangTidyASTConsumerFactory::createASTConsumer(
424424
FinderOptions.CheckProfiling.emplace(Profiling->Records);
425425
}
426426

427+
// Avoid processing system headers, unless the user explicitly requests it
428+
if (!Context.getOptions().SystemHeaders.value_or(false))
429+
FinderOptions.IgnoreSystemHeaders = true;
430+
427431
std::unique_ptr<ast_matchers::MatchFinder> Finder(
428432
new ast_matchers::MatchFinder(std::move(FinderOptions)));
429433

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ void PreferMemberInitializerCheck::check(
191191
if (!AssignmentToMember)
192192
continue;
193193
const FieldDecl *Field = AssignmentToMember->Field;
194+
// Skip if the field is inherited from a base class.
195+
if (Field->getParent() != Class)
196+
continue;
194197
const Expr *InitValue = AssignmentToMember->Init;
195198
updateAssignmentLevel(Field, InitValue, Ctor, AssignedFields);
196199
if (!canAdvanceAssignment(AssignedFields[Field]))

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ add_clang_library(clangTidyMiscModule STATIC
3232
NoRecursionCheck.cpp
3333
NonCopyableObjects.cpp
3434
NonPrivateMemberVariablesInClassesCheck.cpp
35+
OverrideWithDifferentVisibilityCheck.cpp
3536
RedundantExpressionCheck.cpp
3637
StaticAssertCheck.cpp
3738
ThrowByValueCatchByReferenceCheck.cpp

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "NoRecursionCheck.h"
2323
#include "NonCopyableObjects.h"
2424
#include "NonPrivateMemberVariablesInClassesCheck.h"
25+
#include "OverrideWithDifferentVisibilityCheck.h"
2526
#include "RedundantExpressionCheck.h"
2627
#include "StaticAssertCheck.h"
2728
#include "ThrowByValueCatchByReferenceCheck.h"
@@ -81,6 +82,8 @@ class MiscModule : public ClangTidyModule {
8182
"misc-use-anonymous-namespace");
8283
CheckFactories.registerCheck<UseInternalLinkageCheck>(
8384
"misc-use-internal-linkage");
85+
CheckFactories.registerCheck<OverrideWithDifferentVisibilityCheck>(
86+
"misc-override-with-different-visibility");
8487
}
8588
};
8689

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
//===--- OverrideWithDifferentVisibilityCheck.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 "OverrideWithDifferentVisibilityCheck.h"
10+
#include "../utils/Matchers.h"
11+
#include "../utils/OptionsUtils.h"
12+
#include "clang/ASTMatchers/ASTMatchFinder.h"
13+
14+
using namespace clang::ast_matchers;
15+
using namespace clang;
16+
17+
namespace {
18+
19+
AST_MATCHER(NamedDecl, isOperatorDecl) {
20+
DeclarationName::NameKind const NK = Node.getDeclName().getNameKind();
21+
return NK != DeclarationName::Identifier &&
22+
NK != DeclarationName::CXXConstructorName &&
23+
NK != DeclarationName::CXXDestructorName;
24+
}
25+
26+
} // namespace
27+
28+
namespace clang::tidy {
29+
30+
template <>
31+
struct OptionEnumMapping<
32+
misc::OverrideWithDifferentVisibilityCheck::ChangeKind> {
33+
static llvm::ArrayRef<std::pair<
34+
misc::OverrideWithDifferentVisibilityCheck::ChangeKind, StringRef>>
35+
getEnumMapping() {
36+
static constexpr std::pair<
37+
misc::OverrideWithDifferentVisibilityCheck::ChangeKind, StringRef>
38+
Mapping[] = {
39+
{misc::OverrideWithDifferentVisibilityCheck::ChangeKind::Any,
40+
"any"},
41+
{misc::OverrideWithDifferentVisibilityCheck::ChangeKind::Widening,
42+
"widening"},
43+
{misc::OverrideWithDifferentVisibilityCheck::ChangeKind::Narrowing,
44+
"narrowing"},
45+
};
46+
return {Mapping};
47+
}
48+
};
49+
50+
namespace misc {
51+
52+
OverrideWithDifferentVisibilityCheck::OverrideWithDifferentVisibilityCheck(
53+
StringRef Name, ClangTidyContext *Context)
54+
: ClangTidyCheck(Name, Context),
55+
DetectVisibilityChange(
56+
Options.get("DisallowedVisibilityChange", ChangeKind::Any)),
57+
CheckDestructors(Options.get("CheckDestructors", false)),
58+
CheckOperators(Options.get("CheckOperators", false)),
59+
IgnoredFunctions(utils::options::parseStringList(
60+
Options.get("IgnoredFunctions", ""))) {}
61+
62+
void OverrideWithDifferentVisibilityCheck::storeOptions(
63+
ClangTidyOptions::OptionMap &Opts) {
64+
Options.store(Opts, "DisallowedVisibilityChange", DetectVisibilityChange);
65+
Options.store(Opts, "CheckDestructors", CheckDestructors);
66+
Options.store(Opts, "CheckOperators", CheckOperators);
67+
Options.store(Opts, "IgnoredFunctions",
68+
utils::options::serializeStringList(IgnoredFunctions));
69+
}
70+
71+
void OverrideWithDifferentVisibilityCheck::registerMatchers(
72+
MatchFinder *Finder) {
73+
const auto IgnoredDecl =
74+
namedDecl(matchers::matchesAnyListedName(IgnoredFunctions));
75+
const auto FilterDestructors =
76+
CheckDestructors ? decl() : decl(unless(cxxDestructorDecl()));
77+
const auto FilterOperators =
78+
CheckOperators ? namedDecl() : namedDecl(unless(isOperatorDecl()));
79+
Finder->addMatcher(
80+
cxxMethodDecl(
81+
isVirtual(), FilterDestructors, FilterOperators,
82+
ofClass(
83+
cxxRecordDecl(unless(isExpansionInSystemHeader())).bind("class")),
84+
forEachOverridden(cxxMethodDecl(ofClass(cxxRecordDecl().bind("base")),
85+
unless(IgnoredDecl))
86+
.bind("base_func")))
87+
.bind("func"),
88+
this);
89+
}
90+
91+
void OverrideWithDifferentVisibilityCheck::check(
92+
const MatchFinder::MatchResult &Result) {
93+
const auto *const MatchedFunction =
94+
Result.Nodes.getNodeAs<FunctionDecl>("func");
95+
if (!MatchedFunction->isCanonicalDecl())
96+
return;
97+
98+
const auto *const ParentClass =
99+
Result.Nodes.getNodeAs<CXXRecordDecl>("class");
100+
const auto *const BaseClass = Result.Nodes.getNodeAs<CXXRecordDecl>("base");
101+
CXXBasePaths Paths;
102+
if (!ParentClass->isDerivedFrom(BaseClass, Paths))
103+
return;
104+
105+
const auto *const OverriddenFunction =
106+
Result.Nodes.getNodeAs<FunctionDecl>("base_func");
107+
AccessSpecifier const ActualAccess = MatchedFunction->getAccess();
108+
AccessSpecifier OverriddenAccess = OverriddenFunction->getAccess();
109+
110+
const CXXBaseSpecifier *InheritanceWithStrictVisibility = nullptr;
111+
for (const CXXBasePath &Path : Paths) {
112+
for (const CXXBasePathElement &Elem : Path) {
113+
if (Elem.Base->getAccessSpecifier() > OverriddenAccess) {
114+
OverriddenAccess = Elem.Base->getAccessSpecifier();
115+
InheritanceWithStrictVisibility = Elem.Base;
116+
}
117+
}
118+
}
119+
120+
if (ActualAccess != OverriddenAccess) {
121+
if (DetectVisibilityChange == ChangeKind::Widening &&
122+
ActualAccess > OverriddenAccess)
123+
return;
124+
if (DetectVisibilityChange == ChangeKind::Narrowing &&
125+
ActualAccess < OverriddenAccess)
126+
return;
127+
128+
if (InheritanceWithStrictVisibility) {
129+
diag(MatchedFunction->getLocation(),
130+
"visibility of function %0 is changed from %1 (through %1 "
131+
"inheritance of class %2) to %3")
132+
<< MatchedFunction << OverriddenAccess
133+
<< InheritanceWithStrictVisibility->getType() << ActualAccess;
134+
diag(InheritanceWithStrictVisibility->getBeginLoc(),
135+
"%0 is inherited as %1 here", DiagnosticIDs::Note)
136+
<< InheritanceWithStrictVisibility->getType() << OverriddenAccess;
137+
} else {
138+
diag(MatchedFunction->getLocation(),
139+
"visibility of function %0 is changed from %1 in class %2 to %3")
140+
<< MatchedFunction << OverriddenAccess << BaseClass << ActualAccess;
141+
}
142+
diag(OverriddenFunction->getLocation(), "function declared here as %0",
143+
DiagnosticIDs::Note)
144+
<< OverriddenFunction->getAccess();
145+
}
146+
}
147+
148+
} // namespace misc
149+
150+
} // namespace clang::tidy
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//===--- OverrideWithDifferentVisibilityCheck.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_MISC_OVERRIDEWITHDIFFERENTVISIBILITYCHECK_H
10+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_OVERRIDEWITHDIFFERENTVISIBILITYCHECK_H
11+
12+
#include "../ClangTidyCheck.h"
13+
14+
namespace clang::tidy::misc {
15+
16+
/// Finds virtual function overrides with different visibility than the function
17+
/// in the base class.
18+
///
19+
/// For the user-facing documentation see:
20+
/// http://clang.llvm.org/extra/clang-tidy/checks/misc/override-with-different-visibility.html
21+
class OverrideWithDifferentVisibilityCheck : public ClangTidyCheck {
22+
public:
23+
enum class ChangeKind { Any, Widening, Narrowing };
24+
25+
OverrideWithDifferentVisibilityCheck(StringRef Name,
26+
ClangTidyContext *Context);
27+
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
28+
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
29+
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
30+
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
31+
return LangOpts.CPlusPlus;
32+
}
33+
34+
private:
35+
ChangeKind DetectVisibilityChange;
36+
bool CheckDestructors;
37+
bool CheckOperators;
38+
std::vector<llvm::StringRef> IgnoredFunctions;
39+
};
40+
41+
} // namespace clang::tidy::misc
42+
43+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_OVERRIDEWITHDIFFERENTVISIBILITYCHECK_H

clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import json
2929
import multiprocessing
3030
import os
31+
import queue
3132
import re
3233
import shutil
3334
import subprocess
@@ -42,13 +43,6 @@
4243
except ImportError:
4344
yaml = None
4445

45-
is_py2 = sys.version[0] == "2"
46-
47-
if is_py2:
48-
import Queue as queue
49-
else:
50-
import queue as queue
51-
5246

5347
def run_tidy(task_queue, lock, timeout, failed_files):
5448
watchdog = None

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ Improvements to clang-query
104104
Improvements to clang-tidy
105105
--------------------------
106106

107+
- :program:`clang-tidy` no longer attemps to analyze code from system headers
108+
by default, greatly improving performance. This behavior is disabled if the
109+
`SystemHeaders` option is enabled.
110+
107111
- The :program:`run-clang-tidy.py` and :program:`clang-tidy-diff.py` scripts
108112
now run checks in parallel by default using all available hardware threads.
109113
Both scripts display the number of threads being used in their output.
@@ -130,6 +134,12 @@ New checks
130134
Checks for uses of MLIR's old/to be deprecated ``OpBuilder::create<T>`` form
131135
and suggests using ``T::create`` instead.
132136

137+
- New :doc:`misc-override-with-different-visibility
138+
<clang-tidy/checks/misc/override-with-different-visibility>` check.
139+
140+
Finds virtual function overrides with different visibility than the function
141+
in the base class.
142+
133143
New check aliases
134144
^^^^^^^^^^^^^^^^^
135145

@@ -163,6 +173,10 @@ Changes in existing checks
163173
an additional matcher that generalizes the copy-and-swap idiom pattern
164174
detection.
165175

176+
- Improved :doc:`cppcoreguidelines-prefer-member-initializer
177+
<clang-tidy/checks/cppcoreguidelines/prefer-member-initializer>` check to
178+
avoid false positives on inherited members in class templates.
179+
166180
- Improved :doc:`misc-header-include-cycle
167181
<clang-tidy/checks/misc/header-include-cycle>` check performance.
168182

0 commit comments

Comments
 (0)