Skip to content

Commit 960c9fd

Browse files
committed
Merge remote-tracking branch 'upstream/release_60'
2 parents f0fcc27 + e4f84ab commit 960c9fd

File tree

17,798 files changed

+1245750
-485519
lines changed

Some content is hidden

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

17,798 files changed

+1245750
-485519
lines changed

clang-tools-extra/.arcconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"project_id" : "clang-tools-extra",
2+
"repository.callsign" : "CTE",
33
"conduit_uri" : "https://reviews.llvm.org/"
44
}

clang-tools-extra/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ add_subdirectory(pp-trace)
1515
add_subdirectory(tool-template)
1616

1717
# Add the common testsuite after all the tools.
18-
# TODO: Support tests with more granularity when features are off?
19-
if(CLANG_ENABLE_STATIC_ANALYZER AND CLANG_INCLUDE_TESTS)
18+
if(CLANG_INCLUDE_TESTS)
2019
add_subdirectory(test)
2120
add_subdirectory(unittests)
2221
endif()

clang-tools-extra/change-namespace/ChangeNamespace.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,8 @@ void ChangeNamespaceTool::registerMatchers(ast_matchers::MatchFinder *Finder) {
427427
unless(templateSpecializationType())))))),
428428
hasParent(nestedNameSpecifierLoc()),
429429
hasAncestor(isImplicit()),
430-
hasAncestor(UsingShadowDeclInClass))),
430+
hasAncestor(UsingShadowDeclInClass),
431+
hasAncestor(functionDecl(isDefaulted())))),
431432
hasAncestor(decl().bind("dc")))
432433
.bind("type"),
433434
this);
@@ -451,6 +452,7 @@ void ChangeNamespaceTool::registerMatchers(ast_matchers::MatchFinder *Finder) {
451452
specifiesType(hasDeclaration(DeclMatcher.bind("from_decl"))))),
452453
unless(anyOf(hasAncestor(isImplicit()),
453454
hasAncestor(UsingShadowDeclInClass),
455+
hasAncestor(functionDecl(isDefaulted())),
454456
hasAncestor(typeLoc(loc(qualType(hasDeclaration(
455457
decl(equalsBoundNode("from_decl"))))))))))
456458
.bind("nested_specifier_loc"),
@@ -550,6 +552,10 @@ void ChangeNamespaceTool::run(
550552
if (Loc.getTypeLocClass() == TypeLoc::Elaborated) {
551553
NestedNameSpecifierLoc NestedNameSpecifier =
552554
Loc.castAs<ElaboratedTypeLoc>().getQualifierLoc();
555+
// This happens for friend declaration of a base class with injected class
556+
// name.
557+
if (!NestedNameSpecifier.getNestedNameSpecifier())
558+
return;
553559
const Type *SpecifierType =
554560
NestedNameSpecifier.getNestedNameSpecifier()->getAsType();
555561
if (SpecifierType && SpecifierType->isRecordType())

clang-tools-extra/change-namespace/tool/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ add_clang_executable(clang-change-namespace
88
ClangChangeNamespace.cpp
99
)
1010
target_link_libraries(clang-change-namespace
11+
PRIVATE
1112
clangAST
1213
clangASTMatchers
1314
clangBasic

clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -288,13 +288,12 @@ bool mergeAndDeduplicate(const TUReplacements &TUs,
288288
for (const tooling::Replacement &R : TU.Replacements) {
289289
// Use the file manager to deduplicate paths. FileEntries are
290290
// automatically canonicalized.
291-
const FileEntry *Entry = SM.getFileManager().getFile(R.getFilePath());
292-
if (!Entry && Warned.insert(R.getFilePath()).second) {
293-
errs() << "Described file '" << R.getFilePath()
294-
<< "' doesn't exist. Ignoring...\n";
295-
continue;
291+
if (const FileEntry *Entry = SM.getFileManager().getFile(R.getFilePath())) {
292+
GroupedReplacements[Entry].push_back(R);
293+
} else if (Warned.insert(R.getFilePath()).second) {
294+
errs() << "Described file '" << R.getFilePath()
295+
<< "' doesn't exist. Ignoring...\n";
296296
}
297-
GroupedReplacements[Entry].push_back(R);
298297
}
299298
}
300299

@@ -314,13 +313,12 @@ bool mergeAndDeduplicate(const TUDiagnostics &TUs,
314313
for (const tooling::Replacement &R : Fix.second) {
315314
// Use the file manager to deduplicate paths. FileEntries are
316315
// automatically canonicalized.
317-
const FileEntry *Entry = SM.getFileManager().getFile(R.getFilePath());
318-
if (!Entry && Warned.insert(R.getFilePath()).second) {
319-
errs() << "Described file '" << R.getFilePath()
320-
<< "' doesn't exist. Ignoring...\n";
321-
continue;
316+
if (const FileEntry *Entry = SM.getFileManager().getFile(R.getFilePath())) {
317+
GroupedReplacements[Entry].push_back(R);
318+
} else if (Warned.insert(R.getFilePath()).second) {
319+
errs() << "Described file '" << R.getFilePath()
320+
<< "' doesn't exist. Ignoring...\n";
322321
}
323-
GroupedReplacements[Entry].push_back(R);
324322
}
325323
}
326324
}

clang-tools-extra/clang-apply-replacements/tool/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ add_clang_executable(clang-apply-replacements
66
ClangApplyReplacementsMain.cpp
77
)
88
target_link_libraries(clang-apply-replacements
9+
PRIVATE
910
clangApplyReplacements
1011
clangBasic
1112
clangFormat

clang-tools-extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ class ScopedFileRemover {
8282
};
8383
} // namespace
8484

85-
static void printVersion() {
86-
outs() << "clang-apply-replacements version " CLANG_VERSION_STRING << "\n";
85+
static void printVersion(raw_ostream &OS) {
86+
OS << "clang-apply-replacements version " CLANG_VERSION_STRING << "\n";
8787
}
8888

8989
/// \brief Convenience function to get rewritten content for \c Filename from
@@ -199,7 +199,7 @@ applyFormatting(const std::vector<tooling::Replacement> &Replacements,
199199
int main(int argc, char **argv) {
200200
cl::HideUnrelatedOptions(makeArrayRef(VisibleCategories));
201201

202-
cl::SetVersionPrinter(&printVersion);
202+
cl::SetVersionPrinter(printVersion);
203203
cl::ParseCommandLineOptions(argc, argv);
204204

205205
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts(new DiagnosticOptions());

clang-tools-extra/clang-move/tool/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ add_clang_executable(clang-move
55
)
66

77
target_link_libraries(clang-move
8+
PRIVATE
89
clangAST
910
clangASTMatchers
1011
clangBasic

clang-tools-extra/clang-query/tool/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
22

33
add_clang_executable(clang-query ClangQuery.cpp)
44
target_link_libraries(clang-query
5+
PRIVATE
56
clangAST
67
clangASTMatchers
78
clangBasic

clang-tools-extra/clang-reorder-fields/ReorderFieldsAction.cpp

Lines changed: 73 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,23 @@
2222
#include "clang/ASTMatchers/ASTMatchFinder.h"
2323
#include "clang/Lex/Lexer.h"
2424
#include "clang/Tooling/Refactoring.h"
25+
#include "llvm/ADT/SetVector.h"
2526
#include <algorithm>
2627
#include <string>
2728

2829
namespace clang {
2930
namespace reorder_fields {
3031
using namespace clang::ast_matchers;
32+
using llvm::SmallSetVector;
3133

3234
/// \brief Finds the definition of a record by name.
3335
///
3436
/// \returns nullptr if the name is ambiguous or not found.
35-
static const CXXRecordDecl *findDefinition(StringRef RecordName,
36-
ASTContext &Context) {
37-
auto Results = match(
38-
recordDecl(hasName(RecordName), isDefinition()).bind("cxxRecordDecl"),
39-
Context);
37+
static const RecordDecl *findDefinition(StringRef RecordName,
38+
ASTContext &Context) {
39+
auto Results =
40+
match(recordDecl(hasName(RecordName), isDefinition()).bind("recordDecl"),
41+
Context);
4042
if (Results.empty()) {
4143
llvm::errs() << "Definition of " << RecordName << " not found\n";
4244
return nullptr;
@@ -46,14 +48,14 @@ static const CXXRecordDecl *findDefinition(StringRef RecordName,
4648
<< " is ambiguous, several definitions found\n";
4749
return nullptr;
4850
}
49-
return selectFirst<CXXRecordDecl>("cxxRecordDecl", Results);
51+
return selectFirst<RecordDecl>("recordDecl", Results);
5052
}
5153

5254
/// \brief Calculates the new order of fields.
5355
///
5456
/// \returns empty vector if the list of fields doesn't match the definition.
5557
static SmallVector<unsigned, 4>
56-
getNewFieldsOrder(const CXXRecordDecl *Definition,
58+
getNewFieldsOrder(const RecordDecl *Definition,
5759
ArrayRef<std::string> DesiredFieldsOrder) {
5860
assert(Definition && "Definition is null");
5961

@@ -91,13 +93,35 @@ addReplacement(SourceRange Old, SourceRange New, const ASTContext &Context,
9193
consumeError(Replacements[R.getFilePath()].add(R));
9294
}
9395

96+
/// \brief Find all member fields used in the given init-list initializer expr
97+
/// that belong to the same record
98+
///
99+
/// \returns a set of field declarations, empty if none were present
100+
static SmallSetVector<FieldDecl *, 1>
101+
findMembersUsedInInitExpr(const CXXCtorInitializer *Initializer,
102+
ASTContext &Context) {
103+
SmallSetVector<FieldDecl *, 1> Results;
104+
// Note that this does not pick up member fields of base classes since
105+
// for those accesses Sema::PerformObjectMemberConversion always inserts an
106+
// UncheckedDerivedToBase ImplicitCastExpr between the this expr and the
107+
// object expression
108+
auto FoundExprs =
109+
match(findAll(memberExpr(hasObjectExpression(cxxThisExpr())).bind("ME")),
110+
*Initializer->getInit(), Context);
111+
for (BoundNodes &BN : FoundExprs)
112+
if (auto *MemExpr = BN.getNodeAs<MemberExpr>("ME"))
113+
if (auto *FD = dyn_cast<FieldDecl>(MemExpr->getMemberDecl()))
114+
Results.insert(FD);
115+
return Results;
116+
}
117+
94118
/// \brief Reorders fields in the definition of a struct/class.
95119
///
96120
/// At the moment reodering of fields with
97121
/// different accesses (public/protected/private) is not supported.
98122
/// \returns true on success.
99123
static bool reorderFieldsInDefinition(
100-
const CXXRecordDecl *Definition, ArrayRef<unsigned> NewFieldsOrder,
124+
const RecordDecl *Definition, ArrayRef<unsigned> NewFieldsOrder,
101125
const ASTContext &Context,
102126
std::map<std::string, tooling::Replacements> &Replacements) {
103127
assert(Definition && "Definition is null");
@@ -129,11 +153,12 @@ static bool reorderFieldsInDefinition(
129153

130154
/// \brief Reorders initializers in a C++ struct/class constructor.
131155
///
132-
/// A constructor can have initializers for an arbitrary subset of the class's fields.
133-
/// Thus, we need to ensure that we reorder just the initializers that are present.
156+
/// A constructor can have initializers for an arbitrary subset of the class's
157+
/// fields. Thus, we need to ensure that we reorder just the initializers that
158+
/// are present.
134159
static void reorderFieldsInConstructor(
135160
const CXXConstructorDecl *CtorDecl, ArrayRef<unsigned> NewFieldsOrder,
136-
const ASTContext &Context,
161+
ASTContext &Context,
137162
std::map<std::string, tooling::Replacements> &Replacements) {
138163
assert(CtorDecl && "Constructor declaration is null");
139164
if (CtorDecl->isImplicit() || CtorDecl->getNumCtorInitializers() <= 1)
@@ -151,8 +176,26 @@ static void reorderFieldsInConstructor(
151176
SmallVector<const CXXCtorInitializer *, 10> OldWrittenInitializersOrder;
152177
SmallVector<const CXXCtorInitializer *, 10> NewWrittenInitializersOrder;
153178
for (const auto *Initializer : CtorDecl->inits()) {
154-
if (!Initializer->isWritten())
179+
if (!Initializer->isMemberInitializer() || !Initializer->isWritten())
155180
continue;
181+
182+
// Warn if this reordering violates initialization expr dependencies.
183+
const FieldDecl *ThisM = Initializer->getMember();
184+
const auto UsedMembers = findMembersUsedInInitExpr(Initializer, Context);
185+
for (const FieldDecl *UM : UsedMembers) {
186+
if (NewFieldsPositions[UM->getFieldIndex()] >
187+
NewFieldsPositions[ThisM->getFieldIndex()]) {
188+
DiagnosticsEngine &DiagEngine = Context.getDiagnostics();
189+
auto Description = ("reordering field " + UM->getName() + " after " +
190+
ThisM->getName() + " makes " + UM->getName() +
191+
" uninitialized when used in init expression")
192+
.str();
193+
unsigned ID = DiagEngine.getDiagnosticIDs()->getCustomDiagID(
194+
DiagnosticIDs::Warning, Description);
195+
DiagEngine.Report(Initializer->getSourceLocation(), ID);
196+
}
197+
}
198+
156199
OldWrittenInitializersOrder.push_back(Initializer);
157200
NewWrittenInitializersOrder.push_back(Initializer);
158201
}
@@ -182,12 +225,12 @@ static bool reorderFieldsInInitListExpr(
182225
const ASTContext &Context,
183226
std::map<std::string, tooling::Replacements> &Replacements) {
184227
assert(InitListEx && "Init list expression is null");
185-
// We care only about InitListExprs which originate from source code.
228+
// We care only about InitListExprs which originate from source code.
186229
// Implicit InitListExprs are created by the semantic analyzer.
187230
if (!InitListEx->isExplicit())
188231
return true;
189-
// The method InitListExpr::getSyntacticForm may return nullptr indicating that
190-
// the current initializer list also serves as its syntactic form.
232+
// The method InitListExpr::getSyntacticForm may return nullptr indicating
233+
// that the current initializer list also serves as its syntactic form.
191234
if (const auto *SyntacticForm = InitListEx->getSyntacticForm())
192235
InitListEx = SyntacticForm;
193236
// If there are no initializers we do not need to change anything.
@@ -199,10 +242,9 @@ static bool reorderFieldsInInitListExpr(
199242
}
200243
for (unsigned i = 0, e = InitListEx->getNumInits(); i < e; ++i)
201244
if (i != NewFieldsOrder[i])
202-
addReplacement(
203-
InitListEx->getInit(i)->getSourceRange(),
204-
InitListEx->getInit(NewFieldsOrder[i])->getSourceRange(), Context,
205-
Replacements);
245+
addReplacement(InitListEx->getInit(i)->getSourceRange(),
246+
InitListEx->getInit(NewFieldsOrder[i])->getSourceRange(),
247+
Context, Replacements);
206248
return true;
207249
}
208250

@@ -223,7 +265,7 @@ class ReorderingConsumer : public ASTConsumer {
223265
ReorderingConsumer &operator=(const ReorderingConsumer &) = delete;
224266

225267
void HandleTranslationUnit(ASTContext &Context) override {
226-
const CXXRecordDecl *RD = findDefinition(RecordName, Context);
268+
const RecordDecl *RD = findDefinition(RecordName, Context);
227269
if (!RD)
228270
return;
229271
SmallVector<unsigned, 4> NewFieldsOrder =
@@ -232,16 +274,21 @@ class ReorderingConsumer : public ASTConsumer {
232274
return;
233275
if (!reorderFieldsInDefinition(RD, NewFieldsOrder, Context, Replacements))
234276
return;
235-
for (const auto *C : RD->ctors())
236-
if (const auto *D = dyn_cast<CXXConstructorDecl>(C->getDefinition()))
237-
reorderFieldsInConstructor(cast<const CXXConstructorDecl>(D),
238-
NewFieldsOrder, Context, Replacements);
239277

240-
// We only need to reorder init list expressions for aggregate types.
278+
// CXXRD will be nullptr if C code (not C++) is being processed.
279+
const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD);
280+
if (CXXRD)
281+
for (const auto *C : CXXRD->ctors())
282+
if (const auto *D = dyn_cast<CXXConstructorDecl>(C->getDefinition()))
283+
reorderFieldsInConstructor(cast<const CXXConstructorDecl>(D),
284+
NewFieldsOrder, Context, Replacements);
285+
286+
// We only need to reorder init list expressions for
287+
// plain C structs or C++ aggregate types.
241288
// For other types the order of constructor parameters is used,
242289
// which we don't change at the moment.
243290
// Now (v0) partial initialization is not supported.
244-
if (RD->isAggregate())
291+
if (!CXXRD || CXXRD->isAggregate())
245292
for (auto Result :
246293
match(initListExpr(hasType(equalsNode(RD))).bind("initListExpr"),
247294
Context))
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
add_clang_executable(clang-reorder-fields ClangReorderFields.cpp)
1+
add_clang_tool(clang-reorder-fields ClangReorderFields.cpp)
22

33
target_link_libraries(clang-reorder-fields
4+
PRIVATE
45
clangBasic
56
clangFrontend
67
clangReorderFields
78
clangRewrite
89
clangTooling
910
clangToolingCore
1011
)
11-
12-
install(TARGETS clang-reorder-fields RUNTIME DESTINATION bin)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ add_subdirectory(boost)
3131
add_subdirectory(bugprone)
3232
add_subdirectory(cert)
3333
add_subdirectory(cppcoreguidelines)
34+
add_subdirectory(fuchsia)
3435
add_subdirectory(google)
3536
add_subdirectory(hicpp)
3637
add_subdirectory(llvm)
3738
add_subdirectory(misc)
3839
add_subdirectory(modernize)
3940
add_subdirectory(mpi)
41+
add_subdirectory(objc)
4042
add_subdirectory(performance)
4143
add_subdirectory(plugin)
4244
add_subdirectory(readability)

0 commit comments

Comments
 (0)