Skip to content

Commit 394b2b5

Browse files
committed
Merge branch 'main' into fast_isel_fix
2 parents 1f8f7d5 + 69577b2 commit 394b2b5

File tree

687 files changed

+12708
-13181
lines changed

Some content is hidden

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

687 files changed

+12708
-13181
lines changed

clang-tools-extra/clang-tidy/boost/UseRangesCheck.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ utils::UseRangesCheck::ReplacerMap UseRangesCheck::getReplacerMap() const {
204204
ReplacerMap Results;
205205
static const Signature SingleSig = {{0}};
206206
static const Signature TwoSig = {{0}, {2}};
207-
static const auto AddFrom =
207+
const auto AddFrom =
208208
[&Results](llvm::IntrusiveRefCntPtr<UseRangesCheck::Replacer> Replacer,
209209
std::initializer_list<StringRef> Names, StringRef Prefix) {
210210
llvm::SmallString<64> Buffer;
@@ -214,17 +214,17 @@ utils::UseRangesCheck::ReplacerMap UseRangesCheck::getReplacerMap() const {
214214
}
215215
};
216216

217-
static const auto AddFromStd =
218-
[](llvm::IntrusiveRefCntPtr<UseRangesCheck::Replacer> Replacer,
219-
std::initializer_list<StringRef> Names) {
217+
const auto AddFromStd =
218+
[&](llvm::IntrusiveRefCntPtr<UseRangesCheck::Replacer> Replacer,
219+
std::initializer_list<StringRef> Names) {
220220
AddFrom(Replacer, Names, "std");
221221
};
222222

223-
static const auto AddFromBoost =
224-
[](llvm::IntrusiveRefCntPtr<UseRangesCheck::Replacer> Replacer,
225-
std::initializer_list<
226-
std::pair<StringRef, std::initializer_list<StringRef>>>
227-
NamespaceAndNames) {
223+
const auto AddFromBoost =
224+
[&](llvm::IntrusiveRefCntPtr<UseRangesCheck::Replacer> Replacer,
225+
std::initializer_list<
226+
std::pair<StringRef, std::initializer_list<StringRef>>>
227+
NamespaceAndNames) {
228228
for (auto [Namespace, Names] : NamespaceAndNames)
229229
AddFrom(Replacer, Names,
230230
SmallString<64>{"boost", (Namespace.empty() ? "" : "::"),
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//===--- BitwisePointerCastCheck.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 "BitwisePointerCastCheck.h"
10+
#include "clang/ASTMatchers/ASTMatchFinder.h"
11+
12+
using namespace clang::ast_matchers;
13+
14+
namespace clang::tidy::bugprone {
15+
16+
void BitwisePointerCastCheck::registerMatchers(MatchFinder *Finder) {
17+
if (getLangOpts().CPlusPlus20) {
18+
auto IsPointerType = refersToType(qualType(isAnyPointer()));
19+
Finder->addMatcher(callExpr(hasDeclaration(functionDecl(allOf(
20+
hasName("::std::bit_cast"),
21+
hasTemplateArgument(0, IsPointerType),
22+
hasTemplateArgument(1, IsPointerType)))))
23+
.bind("bit_cast"),
24+
this);
25+
}
26+
27+
auto IsDoublePointerType =
28+
hasType(qualType(pointsTo(qualType(isAnyPointer()))));
29+
Finder->addMatcher(callExpr(hasArgument(0, IsDoublePointerType),
30+
hasArgument(1, IsDoublePointerType),
31+
hasDeclaration(functionDecl(hasName("::memcpy"))))
32+
.bind("memcpy"),
33+
this);
34+
}
35+
36+
void BitwisePointerCastCheck::check(const MatchFinder::MatchResult &Result) {
37+
if (const auto *Call = Result.Nodes.getNodeAs<CallExpr>("bit_cast"))
38+
diag(Call->getBeginLoc(),
39+
"do not use 'std::bit_cast' to cast between pointers")
40+
<< Call->getSourceRange();
41+
else if (const auto *Call = Result.Nodes.getNodeAs<CallExpr>("memcpy"))
42+
diag(Call->getBeginLoc(), "do not use 'memcpy' to cast between pointers")
43+
<< Call->getSourceRange();
44+
}
45+
46+
} // namespace clang::tidy::bugprone
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//===--- BitwisePointerCastCheck.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_BUGPRONE_BITWISEPOINTERCASTCHECK_H
10+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_BITWISEPOINTERCASTCHECK_H
11+
12+
#include "../ClangTidyCheck.h"
13+
14+
namespace clang::tidy::bugprone {
15+
16+
/// Warns about code that tries to cast between pointers by means of
17+
/// ``std::bit_cast`` or ``memcpy``.
18+
///
19+
/// For the user-facing documentation see:
20+
/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/bitwise-pointer-cast.html
21+
class BitwisePointerCastCheck : public ClangTidyCheck {
22+
public:
23+
BitwisePointerCastCheck(StringRef Name, ClangTidyContext *Context)
24+
: ClangTidyCheck(Name, Context) {}
25+
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
26+
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
27+
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
28+
return LangOpts.CPlusPlus;
29+
}
30+
};
31+
32+
} // namespace clang::tidy::bugprone
33+
34+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_BITWISEPOINTERCASTCHECK_H

clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "AssertSideEffectCheck.h"
1515
#include "AssignmentInIfConditionCheck.h"
1616
#include "BadSignalToKillThreadCheck.h"
17+
#include "BitwisePointerCastCheck.h"
1718
#include "BoolPointerImplicitConversionCheck.h"
1819
#include "BranchCloneCheck.h"
1920
#include "CastingThroughVoidCheck.h"
@@ -109,6 +110,8 @@ class BugproneModule : public ClangTidyModule {
109110
"bugprone-assignment-in-if-condition");
110111
CheckFactories.registerCheck<BadSignalToKillThreadCheck>(
111112
"bugprone-bad-signal-to-kill-thread");
113+
CheckFactories.registerCheck<BitwisePointerCastCheck>(
114+
"bugprone-bitwise-pointer-cast");
112115
CheckFactories.registerCheck<BoolPointerImplicitConversionCheck>(
113116
"bugprone-bool-pointer-implicit-conversion");
114117
CheckFactories.registerCheck<BranchCloneCheck>("bugprone-branch-clone");

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ add_clang_library(clangTidyBugproneModule
88
AssertSideEffectCheck.cpp
99
AssignmentInIfConditionCheck.cpp
1010
BadSignalToKillThreadCheck.cpp
11+
BitwisePointerCastCheck.cpp
1112
BoolPointerImplicitConversionCheck.cpp
1213
BranchCloneCheck.cpp
1314
BugproneTidyModule.cpp

clang-tools-extra/clangd/ClangdServer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ void ClangdServer::codeComplete(PathRef File, Position Pos,
451451

452452
CodeCompleteOpts.MainFileSignals = IP->Signals;
453453
CodeCompleteOpts.AllScopes = Config::current().Completion.AllScopes;
454+
CodeCompleteOpts.ArgumentLists = Config::current().Completion.ArgumentLists;
454455
// FIXME(ibiryukov): even if Preamble is non-null, we may want to check
455456
// both the old and the new version in case only one of them matches.
456457
CodeCompleteResult Result = clangd::codeComplete(

clang-tools-extra/clangd/CodeComplete.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "AST.h"
2222
#include "CodeCompletionStrings.h"
2323
#include "Compiler.h"
24+
#include "Config.h"
2425
#include "ExpectedTypes.h"
2526
#include "Feature.h"
2627
#include "FileDistance.h"
@@ -350,8 +351,7 @@ struct CodeCompletionBuilder {
350351
CodeCompletionContext::Kind ContextKind,
351352
const CodeCompleteOptions &Opts,
352353
bool IsUsingDeclaration, tok::TokenKind NextTokenKind)
353-
: ASTCtx(ASTCtx),
354-
EnableFunctionArgSnippets(Opts.EnableFunctionArgSnippets),
354+
: ASTCtx(ASTCtx), ArgumentLists(Opts.ArgumentLists),
355355
IsUsingDeclaration(IsUsingDeclaration), NextTokenKind(NextTokenKind) {
356356
Completion.Deprecated = true; // cleared by any non-deprecated overload.
357357
add(C, SemaCCS, ContextKind);
@@ -561,14 +561,23 @@ struct CodeCompletionBuilder {
561561
}
562562

563563
std::string summarizeSnippet() const {
564+
/// localize ArgumentLists tests for better readability
565+
const bool None = ArgumentLists == Config::ArgumentListsPolicy::None;
566+
const bool Open =
567+
ArgumentLists == Config::ArgumentListsPolicy::OpenDelimiter;
568+
const bool Delim = ArgumentLists == Config::ArgumentListsPolicy::Delimiters;
569+
const bool Full =
570+
ArgumentLists == Config::ArgumentListsPolicy::FullPlaceholders ||
571+
(!None && !Open && !Delim); // <-- failsafe: Full is default
572+
564573
if (IsUsingDeclaration)
565574
return "";
566575
auto *Snippet = onlyValue<&BundledEntry::SnippetSuffix>();
567576
if (!Snippet)
568577
// All bundles are function calls.
569578
// FIXME(ibiryukov): sometimes add template arguments to a snippet, e.g.
570579
// we need to complete 'forward<$1>($0)'.
571-
return "($0)";
580+
return None ? "" : (Open ? "(" : "($0)");
572581

573582
if (Snippet->empty())
574583
return "";
@@ -607,7 +616,7 @@ struct CodeCompletionBuilder {
607616
return "";
608617
}
609618
}
610-
if (EnableFunctionArgSnippets)
619+
if (Full)
611620
return *Snippet;
612621

613622
// Replace argument snippets with a simplified pattern.
@@ -622,9 +631,9 @@ struct CodeCompletionBuilder {
622631

623632
bool EmptyArgs = llvm::StringRef(*Snippet).ends_with("()");
624633
if (Snippet->front() == '<')
625-
return EmptyArgs ? "<$1>()$0" : "<$1>($0)";
634+
return None ? "" : (Open ? "<" : (EmptyArgs ? "<$1>()$0" : "<$1>($0)"));
626635
if (Snippet->front() == '(')
627-
return EmptyArgs ? "()" : "($0)";
636+
return None ? "" : (Open ? "(" : (EmptyArgs ? "()" : "($0)"));
628637
return *Snippet; // Not an arg snippet?
629638
}
630639
// 'CompletionItemKind::Interface' matches template type aliases.
@@ -638,7 +647,7 @@ struct CodeCompletionBuilder {
638647
// e.g. Foo<${1:class}>.
639648
if (llvm::StringRef(*Snippet).ends_with("<>"))
640649
return "<>"; // can happen with defaulted template arguments.
641-
return "<$0>";
650+
return None ? "" : (Open ? "<" : "<$0>");
642651
}
643652
return *Snippet;
644653
}
@@ -654,7 +663,8 @@ struct CodeCompletionBuilder {
654663
ASTContext *ASTCtx;
655664
CodeCompletion Completion;
656665
llvm::SmallVector<BundledEntry, 1> Bundled;
657-
bool EnableFunctionArgSnippets;
666+
/// the way argument lists are handled.
667+
Config::ArgumentListsPolicy ArgumentLists;
658668
// No snippets will be generated for using declarations and when the function
659669
// arguments are already present.
660670
bool IsUsingDeclaration;

clang-tools-extra/clangd/CodeComplete.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "ASTSignals.h"
1919
#include "Compiler.h"
20+
#include "Config.h"
2021
#include "Protocol.h"
2122
#include "Quality.h"
2223
#include "index/Index.h"
@@ -101,17 +102,17 @@ struct CodeCompleteOptions {
101102
/// '->' on member access etc.
102103
bool IncludeFixIts = false;
103104

104-
/// Whether to generate snippets for function arguments on code-completion.
105-
/// Needs snippets to be enabled as well.
106-
bool EnableFunctionArgSnippets = true;
107-
108105
/// Whether to include index symbols that are not defined in the scopes
109106
/// visible from the code completion point. This applies in contexts without
110107
/// explicit scope qualifiers.
111108
///
112109
/// Such completions can insert scope qualifiers.
113110
bool AllScopes = false;
114111

112+
/// The way argument list on calls '()' and generics '<>' are handled.
113+
Config::ArgumentListsPolicy ArgumentLists =
114+
Config::ArgumentListsPolicy::FullPlaceholders;
115+
115116
/// Whether to use the clang parser, or fallback to text-based completion
116117
/// (using identifiers in the current file and symbol indexes).
117118
enum CodeCompletionParse {

clang-tools-extra/clangd/Config.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,25 @@ struct Config {
126126
std::vector<std::string> FullyQualifiedNamespaces;
127127
} Style;
128128

129+
/// controls the completion options for argument lists.
130+
enum class ArgumentListsPolicy {
131+
/// nothing, no argument list and also NO Delimiters "()" or "<>".
132+
None,
133+
/// open, only opening delimiter "(" or "<".
134+
OpenDelimiter,
135+
/// empty pair of delimiters "()" or "<>".
136+
Delimiters,
137+
/// full name of both type and variable.
138+
FullPlaceholders,
139+
};
140+
129141
/// Configures code completion feature.
130142
struct {
131143
/// Whether code completion includes results that are not visible in current
132144
/// scopes.
133145
bool AllScopes = true;
146+
/// controls the completion options for argument lists.
147+
ArgumentListsPolicy ArgumentLists = ArgumentListsPolicy::FullPlaceholders;
134148
} Completion;
135149

136150
/// Configures hover feature.

clang-tools-extra/clangd/ConfigCompile.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,21 @@ struct FragmentCompiler {
622622
C.Completion.AllScopes = AllScopes;
623623
});
624624
}
625+
if (F.ArgumentLists) {
626+
if (auto Val =
627+
compileEnum<Config::ArgumentListsPolicy>("ArgumentLists",
628+
*F.ArgumentLists)
629+
.map("None", Config::ArgumentListsPolicy::None)
630+
.map("OpenDelimiter",
631+
Config::ArgumentListsPolicy::OpenDelimiter)
632+
.map("Delimiters", Config::ArgumentListsPolicy::Delimiters)
633+
.map("FullPlaceholders",
634+
Config::ArgumentListsPolicy::FullPlaceholders)
635+
.value())
636+
Out.Apply.push_back([Val](const Params &, Config &C) {
637+
C.Completion.ArgumentLists = *Val;
638+
});
639+
}
625640
}
626641

627642
void compile(Fragment::HoverBlock &&F) {

0 commit comments

Comments
 (0)