Skip to content

Commit 71f48b8

Browse files
Merge branch 'main' into move-verify-1
2 parents df8db82 + 73a4c36 commit 71f48b8

File tree

1,111 files changed

+65536
-40182
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,111 files changed

+65536
-40182
lines changed

.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ jobs:
205205
steps.docs-changed-subprojects.outputs.workflow_any_changed == 'true'
206206
run: |
207207
cmake -B flang-build -GNinja -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS="clang;mlir;flang" -DLLVM_ENABLE_SPHINX=ON ./llvm
208-
TZ=UTC ninja -C flang-build docs-flang-html
208+
TZ=UTC ninja -C flang-build docs-flang-html docs-flang-man
209209
mkdir built-docs/flang
210210
cp -r flang-build/docs/* built-docs/flang/
211211
- name: Upload docs

clang-tools-extra/clang-include-fixer/tool/ClangIncludeFixer.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,11 @@ createSymbolIndexManager(StringRef FilePath) {
167167
// Parse input and fill the database with it.
168168
// <symbol>=<header><, header...>
169169
// Multiple symbols can be given, separated by semicolons.
170-
std::map<std::string, std::vector<std::string>> SymbolsMap;
171170
SmallVector<StringRef, 4> SemicolonSplits;
172171
StringRef(Input).split(SemicolonSplits, ";");
173172
std::vector<find_all_symbols::SymbolAndSignals> Symbols;
174173
for (StringRef Pair : SemicolonSplits) {
175174
auto Split = Pair.split('=');
176-
std::vector<std::string> Headers;
177175
SmallVector<StringRef, 4> CommaSplits;
178176
Split.second.split(CommaSplits, ",");
179177
for (size_t I = 0, E = CommaSplits.size(); I != E; ++I)

clang-tools-extra/clang-tidy/altera/SingleWorkItemBarrierCheck.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ namespace clang::tidy::altera {
1616

1717
void SingleWorkItemBarrierCheck::registerMatchers(MatchFinder *Finder) {
1818
// Find any function that calls barrier but does not call an ID function.
19-
// hasAttr(attr::Kind::OpenCLKernel) restricts it to only kernel functions.
19+
// hasAttr(attr::Kind::DeviceKernel) restricts it to only kernel functions.
2020
// FIXME: Have it accept all functions but check for a parameter that gets an
2121
// ID from one of the four ID functions.
2222
Finder->addMatcher(
2323
// Find function declarations...
2424
functionDecl(
25-
// That are OpenCL kernels...
26-
hasAttr(attr::Kind::OpenCLKernel),
25+
// That are device kernels...
26+
hasAttr(attr::Kind::DeviceKernel),
2727
// And call a barrier function (either 1.x or 2.x version)...
2828
forEachDescendant(callExpr(callee(functionDecl(hasAnyName(
2929
"barrier", "work_group_barrier"))))

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

Lines changed: 151 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,30 @@
1717
#include <cctype>
1818
#include <optional>
1919

20+
namespace clang::tidy {
21+
22+
template <>
23+
struct OptionEnumMapping<
24+
modernize::UseTrailingReturnTypeCheck::TransformLambda> {
25+
static llvm::ArrayRef<std::pair<
26+
modernize::UseTrailingReturnTypeCheck::TransformLambda, StringRef>>
27+
getEnumMapping() {
28+
static constexpr std::pair<
29+
modernize::UseTrailingReturnTypeCheck::TransformLambda, StringRef>
30+
Mapping[] = {
31+
{modernize::UseTrailingReturnTypeCheck::TransformLambda::All,
32+
"all"},
33+
{modernize::UseTrailingReturnTypeCheck::TransformLambda::
34+
AllExceptAuto,
35+
"all_except_auto"},
36+
{modernize::UseTrailingReturnTypeCheck::TransformLambda::None,
37+
"none"}};
38+
return Mapping;
39+
}
40+
};
41+
42+
} // namespace clang::tidy
43+
2044
using namespace clang::ast_matchers;
2145

2246
namespace clang::tidy::modernize {
@@ -111,10 +135,17 @@ struct UnqualNameVisitor : public RecursiveASTVisitor<UnqualNameVisitor> {
111135
private:
112136
const FunctionDecl &F;
113137
};
138+
139+
AST_MATCHER(LambdaExpr, hasExplicitResultType) {
140+
return Node.hasExplicitResultType();
141+
}
142+
114143
} // namespace
115144

116145
constexpr llvm::StringLiteral ErrorMessageOnFunction =
117146
"use a trailing return type for this function";
147+
constexpr llvm::StringLiteral ErrorMessageOnLambda =
148+
"use a trailing return type for this lambda";
118149

119150
static SourceLocation expandIfMacroId(SourceLocation Loc,
120151
const SourceManager &SM) {
@@ -329,6 +360,48 @@ findReturnTypeAndCVSourceRange(const FunctionDecl &F, const TypeLoc &ReturnLoc,
329360
return ReturnTypeRange;
330361
}
331362

363+
static SourceLocation findLambdaTrailingReturnInsertLoc(
364+
const CXXMethodDecl *Method, const SourceManager &SM,
365+
const LangOptions &LangOpts, const ASTContext &Ctx) {
366+
// 'requires' keyword is present in lambda declaration
367+
if (Method->getTrailingRequiresClause()) {
368+
SourceLocation ParamEndLoc;
369+
if (Method->param_empty())
370+
ParamEndLoc = Method->getBeginLoc();
371+
else
372+
ParamEndLoc = Method->getParametersSourceRange().getEnd();
373+
374+
std::pair<FileID, unsigned> ParamEndLocInfo =
375+
SM.getDecomposedLoc(ParamEndLoc);
376+
StringRef Buffer = SM.getBufferData(ParamEndLocInfo.first);
377+
378+
Lexer Lexer(SM.getLocForStartOfFile(ParamEndLocInfo.first), LangOpts,
379+
Buffer.begin(), Buffer.data() + ParamEndLocInfo.second,
380+
Buffer.end());
381+
382+
Token Token;
383+
while (!Lexer.LexFromRawLexer(Token)) {
384+
if (Token.is(tok::raw_identifier)) {
385+
IdentifierInfo &Info = Ctx.Idents.get(StringRef(
386+
SM.getCharacterData(Token.getLocation()), Token.getLength()));
387+
Token.setIdentifierInfo(&Info);
388+
Token.setKind(Info.getTokenID());
389+
}
390+
391+
if (Token.is(tok::kw_requires))
392+
return Token.getLocation().getLocWithOffset(-1);
393+
}
394+
395+
return {};
396+
}
397+
398+
// If no requires clause, insert before the body
399+
if (const Stmt *Body = Method->getBody())
400+
return Body->getBeginLoc().getLocWithOffset(-1);
401+
402+
return {};
403+
}
404+
332405
static void keepSpecifiers(std::string &ReturnType, std::string &Auto,
333406
SourceRange ReturnTypeCVRange, const FunctionDecl &F,
334407
const FriendDecl *Fr, const ASTContext &Ctx,
@@ -382,14 +455,43 @@ static void keepSpecifiers(std::string &ReturnType, std::string &Auto,
382455
}
383456
}
384457

458+
UseTrailingReturnTypeCheck::UseTrailingReturnTypeCheck(
459+
StringRef Name, ClangTidyContext *Context)
460+
: ClangTidyCheck(Name, Context),
461+
TransformFunctions(Options.get("TransformFunctions", true)),
462+
TransformLambdas(Options.get("TransformLambdas", TransformLambda::All)) {
463+
464+
if (TransformFunctions == false && TransformLambdas == TransformLambda::None)
465+
this->configurationDiag(
466+
"The check 'modernize-use-trailing-return-type' will not perform any "
467+
"analysis because 'TransformFunctions' and 'TransformLambdas' are "
468+
"disabled.");
469+
}
470+
471+
void UseTrailingReturnTypeCheck::storeOptions(
472+
ClangTidyOptions::OptionMap &Opts) {
473+
Options.store(Opts, "TransformFunctions", TransformFunctions);
474+
Options.store(Opts, "TransformLambdas", TransformLambdas);
475+
}
476+
385477
void UseTrailingReturnTypeCheck::registerMatchers(MatchFinder *Finder) {
386-
auto F = functionDecl(
387-
unless(anyOf(hasTrailingReturn(), returns(voidType()),
388-
cxxConversionDecl(), cxxMethodDecl(isImplicit()))))
389-
.bind("Func");
478+
auto F =
479+
functionDecl(
480+
unless(anyOf(
481+
hasTrailingReturn(), returns(voidType()), cxxConversionDecl(),
482+
cxxMethodDecl(
483+
anyOf(isImplicit(),
484+
hasParent(cxxRecordDecl(hasParent(lambdaExpr()))))))))
485+
.bind("Func");
486+
487+
if (TransformFunctions) {
488+
Finder->addMatcher(F, this);
489+
Finder->addMatcher(friendDecl(hasDescendant(F)).bind("Friend"), this);
490+
}
390491

391-
Finder->addMatcher(F, this);
392-
Finder->addMatcher(friendDecl(hasDescendant(F)).bind("Friend"), this);
492+
if (TransformLambdas != TransformLambda::None)
493+
Finder->addMatcher(
494+
lambdaExpr(unless(hasExplicitResultType())).bind("Lambda"), this);
393495
}
394496

395497
void UseTrailingReturnTypeCheck::registerPPCallbacks(
@@ -401,8 +503,13 @@ void UseTrailingReturnTypeCheck::check(const MatchFinder::MatchResult &Result) {
401503
assert(PP && "Expected registerPPCallbacks() to have been called before so "
402504
"preprocessor is available");
403505

404-
const auto *F = Result.Nodes.getNodeAs<FunctionDecl>("Func");
506+
if (const auto *Lambda = Result.Nodes.getNodeAs<LambdaExpr>("Lambda")) {
507+
diagOnLambda(Lambda, Result);
508+
return;
509+
}
510+
405511
const auto *Fr = Result.Nodes.getNodeAs<FriendDecl>("Friend");
512+
const auto *F = Result.Nodes.getNodeAs<FunctionDecl>("Func");
406513
assert(F && "Matcher is expected to find only FunctionDecls");
407514

408515
// Three-way comparison operator<=> is syntactic sugar and generates implicit
@@ -495,4 +602,41 @@ void UseTrailingReturnTypeCheck::check(const MatchFinder::MatchResult &Result) {
495602
<< FixItHint::CreateInsertion(InsertionLoc, " -> " + ReturnType);
496603
}
497604

605+
void UseTrailingReturnTypeCheck::diagOnLambda(
606+
const LambdaExpr *Lambda,
607+
const ast_matchers::MatchFinder::MatchResult &Result) {
608+
609+
const CXXMethodDecl *Method = Lambda->getCallOperator();
610+
if (!Method || Lambda->hasExplicitResultType())
611+
return;
612+
613+
const ASTContext *Ctx = Result.Context;
614+
const QualType ReturnType = Method->getReturnType();
615+
616+
// We can't write 'auto' in C++11 mode, try to write generic msg and bail out.
617+
if (ReturnType->isDependentType() &&
618+
Ctx->getLangOpts().LangStd == LangStandard::lang_cxx11) {
619+
if (TransformLambdas == TransformLambda::All)
620+
diag(Lambda->getBeginLoc(), ErrorMessageOnLambda);
621+
return;
622+
}
623+
624+
if (ReturnType->isUndeducedAutoType() &&
625+
TransformLambdas == TransformLambda::AllExceptAuto)
626+
return;
627+
628+
const SourceLocation TrailingReturnInsertLoc =
629+
findLambdaTrailingReturnInsertLoc(Method, *Result.SourceManager,
630+
getLangOpts(), *Result.Context);
631+
632+
if (TrailingReturnInsertLoc.isValid())
633+
diag(Lambda->getBeginLoc(), "use a trailing return type for this lambda")
634+
<< FixItHint::CreateInsertion(
635+
TrailingReturnInsertLoc,
636+
" -> " +
637+
ReturnType.getAsString(Result.Context->getPrintingPolicy()));
638+
else
639+
diag(Lambda->getBeginLoc(), ErrorMessageOnLambda);
640+
}
641+
498642
} // namespace clang::tidy::modernize

clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,25 @@ struct ClassifiedToken {
2626
/// http://clang.llvm.org/extra/clang-tidy/checks/modernize/use-trailing-return-type.html
2727
class UseTrailingReturnTypeCheck : public ClangTidyCheck {
2828
public:
29-
UseTrailingReturnTypeCheck(StringRef Name, ClangTidyContext *Context)
30-
: ClangTidyCheck(Name, Context) {}
29+
UseTrailingReturnTypeCheck(StringRef Name, ClangTidyContext *Context);
3130
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
3231
return LangOpts.CPlusPlus11;
3332
}
33+
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
3434
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
3535
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
3636
Preprocessor *ModuleExpanderPP) override;
3737
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
3838

39+
enum TransformLambda { All, AllExceptAuto, None };
40+
3941
private:
4042
Preprocessor *PP = nullptr;
43+
const bool TransformFunctions;
44+
const TransformLambda TransformLambdas;
45+
46+
void diagOnLambda(const LambdaExpr *Lambda,
47+
const ast_matchers::MatchFinder::MatchResult &Result);
4148
};
4249

4350
} // namespace clang::tidy::modernize

clang-tools-extra/clang-tidy/openmp/ExceptionEscapeCheck.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ ExceptionEscapeCheck::ExceptionEscapeCheck(StringRef Name,
2020
ClangTidyContext *Context)
2121
: ClangTidyCheck(Name, Context),
2222
RawIgnoredExceptions(Options.get("IgnoredExceptions", "")) {
23-
llvm::SmallVector<StringRef, 8> FunctionsThatShouldNotThrowVec,
24-
IgnoredExceptionsVec;
23+
llvm::SmallVector<StringRef, 8> IgnoredExceptionsVec;
2524

2625
llvm::StringSet<> IgnoredExceptions;
2726
StringRef(RawIgnoredExceptions).split(IgnoredExceptionsVec, ",", -1, false);

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ using namespace clang::ast_matchers;
1616
namespace clang::tidy::readability {
1717

1818
void MathMissingParenthesesCheck::registerMatchers(MatchFinder *Finder) {
19-
Finder->addMatcher(binaryOperator(unless(hasParent(binaryOperator())),
20-
unless(isAssignmentOperator()),
21-
unless(isComparisonOperator()),
22-
unless(hasAnyOperatorName("&&", "||")),
23-
hasDescendant(binaryOperator()))
24-
.bind("binOp"),
25-
this);
19+
Finder->addMatcher(
20+
binaryOperator(
21+
unless(hasParent(binaryOperator(unless(isAssignmentOperator()),
22+
unless(isComparisonOperator())))),
23+
unless(isAssignmentOperator()), unless(isComparisonOperator()),
24+
unless(hasAnyOperatorName("&&", "||")),
25+
hasDescendant(binaryOperator()))
26+
.bind("binOp"),
27+
this);
2628
}
2729

2830
static int getPrecedence(const BinaryOperator *BinOp) {
@@ -88,10 +90,6 @@ static void addParantheses(const BinaryOperator *BinOp,
8890
void MathMissingParenthesesCheck::check(
8991
const MatchFinder::MatchResult &Result) {
9092
const auto *BinOp = Result.Nodes.getNodeAs<BinaryOperator>("binOp");
91-
std::vector<
92-
std::pair<clang::SourceRange, std::pair<const clang::BinaryOperator *,
93-
const clang::BinaryOperator *>>>
94-
Insertions;
9593
const SourceManager &SM = *Result.SourceManager;
9694
const clang::LangOptions &LO = Result.Context->getLangOpts();
9795
addParantheses(BinOp, nullptr, this, SM, LO);

clang-tools-extra/clangd/IncludeCleaner.cpp

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ bool mayConsiderUnused(const Inclusion &Inc, ParsedAST &AST,
117117

118118
std::vector<Diag> generateMissingIncludeDiagnostics(
119119
ParsedAST &AST, llvm::ArrayRef<MissingIncludeDiagInfo> MissingIncludes,
120-
llvm::StringRef Code, HeaderFilter IgnoreHeaders, const ThreadsafeFS &TFS) {
120+
llvm::StringRef Code, HeaderFilter IgnoreHeaders,
121+
HeaderFilter AngledHeaders, HeaderFilter QuotedHeaders,
122+
const ThreadsafeFS &TFS) {
121123
std::vector<Diag> Result;
122124
const SourceManager &SM = AST.getSourceManager();
123125
const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID());
@@ -141,7 +143,18 @@ std::vector<Diag> generateMissingIncludeDiagnostics(
141143
AST.getPreprocessor().getHeaderSearchInfo(), MainFile});
142144

143145
llvm::StringRef HeaderRef{Spelling};
146+
144147
bool Angled = HeaderRef.starts_with("<");
148+
if (SymbolWithMissingInclude.Providers.front().kind() ==
149+
include_cleaner::Header::Kind::Physical) {
150+
for (auto &Filter : Angled ? QuotedHeaders : AngledHeaders) {
151+
if (Filter(ResolvedPath)) {
152+
Angled = !Angled;
153+
break;
154+
}
155+
}
156+
}
157+
145158
// We might suggest insertion of an existing include in edge cases, e.g.,
146159
// include is present in a PP-disabled region, or spelling of the header
147160
// turns out to be the same as one of the unresolved includes in the
@@ -151,6 +164,11 @@ std::vector<Diag> generateMissingIncludeDiagnostics(
151164
if (!Replacement.has_value())
152165
continue;
153166

167+
if (Angled != (Spelling.front() == '<')) {
168+
Spelling.front() = Angled ? '<' : '"';
169+
Spelling.back() = Angled ? '>' : '"';
170+
}
171+
154172
Diag &D = Result.emplace_back();
155173
D.Message =
156174
llvm::formatv("No header providing \"{0}\" is directly included",
@@ -481,18 +499,19 @@ bool isPreferredProvider(const Inclusion &Inc,
481499
return false; // no header provides the symbol
482500
}
483501

484-
std::vector<Diag>
485-
issueIncludeCleanerDiagnostics(ParsedAST &AST, llvm::StringRef Code,
486-
const IncludeCleanerFindings &Findings,
487-
const ThreadsafeFS &TFS,
488-
HeaderFilter IgnoreHeaders) {
502+
std::vector<Diag> issueIncludeCleanerDiagnostics(
503+
ParsedAST &AST, llvm::StringRef Code,
504+
const IncludeCleanerFindings &Findings, const ThreadsafeFS &TFS,
505+
HeaderFilter IgnoreHeaders, HeaderFilter AngledHeaders,
506+
HeaderFilter QuotedHeaders) {
489507
trace::Span Tracer("IncludeCleaner::issueIncludeCleanerDiagnostics");
490508
std::vector<Diag> UnusedIncludes = generateUnusedIncludeDiagnostics(
491509
AST.tuPath(), Findings.UnusedIncludes, Code, IgnoreHeaders);
492510
std::optional<Fix> RemoveAllUnused = removeAllUnusedIncludes(UnusedIncludes);
493511

494512
std::vector<Diag> MissingIncludeDiags = generateMissingIncludeDiagnostics(
495-
AST, Findings.MissingIncludes, Code, IgnoreHeaders, TFS);
513+
AST, Findings.MissingIncludes, Code, IgnoreHeaders, AngledHeaders,
514+
QuotedHeaders, TFS);
496515
std::optional<Fix> AddAllMissing = addAllMissingIncludes(MissingIncludeDiags);
497516

498517
std::optional<Fix> FixAll;

0 commit comments

Comments
 (0)