Skip to content

Commit 3b0e8db

Browse files
committed
Merge remote-tracking branch 'upstream/release/10.x' into rustc/10.0-2020-02-05
2 parents 45e825c + 001c8aa commit 3b0e8db

File tree

235 files changed

+5232
-1681
lines changed

Some content is hidden

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

235 files changed

+5232
-1681
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,15 @@ static std::string getCondVarNames(const Stmt *Cond) {
152152
return Result;
153153
}
154154

155+
static bool isKnownFalse(const Expr &Cond, const ASTContext &Ctx) {
156+
if (Cond.isValueDependent())
157+
return false;
158+
bool Result = false;
159+
if (Cond.EvaluateAsBooleanCondition(Result, Ctx))
160+
return !Result;
161+
return false;
162+
}
163+
155164
void InfiniteLoopCheck::registerMatchers(MatchFinder *Finder) {
156165
const auto LoopCondition = allOf(
157166
hasCondition(
@@ -170,6 +179,9 @@ void InfiniteLoopCheck::check(const MatchFinder::MatchResult &Result) {
170179
const auto *LoopStmt = Result.Nodes.getNodeAs<Stmt>("loop-stmt");
171180
const auto *Func = Result.Nodes.getNodeAs<FunctionDecl>("func");
172181

182+
if (isKnownFalse(*Cond, *Result.Context))
183+
return;
184+
173185
bool ShouldHaveConditionVariables = true;
174186
if (const auto *While = dyn_cast<WhileStmt>(LoopStmt)) {
175187
if (const VarDecl *LoopVarDecl = While->getConditionVariable()) {

clang-tools-extra/clangd/CodeComplete.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1842,6 +1842,8 @@ CompletionItem CodeCompletion::render(const CodeCompleteOptions &Opts) const {
18421842
if (InsertInclude && InsertInclude->Insertion)
18431843
LSP.additionalTextEdits.push_back(*InsertInclude->Insertion);
18441844

1845+
LSP.score = Score.ExcludingName;
1846+
18451847
return LSP;
18461848
}
18471849

clang-tools-extra/clangd/FindTarget.cpp

Lines changed: 49 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "llvm/Support/Compiler.h"
3636
#include "llvm/Support/raw_ostream.h"
3737
#include <utility>
38+
#include <vector>
3839

3940
namespace clang {
4041
namespace clangd {
@@ -134,6 +135,35 @@ const Type *getPointeeType(const Type *T) {
134135
return FirstArg.getAsType().getTypePtrOrNull();
135136
}
136137

138+
const NamedDecl *getTemplatePattern(const NamedDecl *D) {
139+
if (const CXXRecordDecl *CRD = dyn_cast<CXXRecordDecl>(D)) {
140+
return CRD->getTemplateInstantiationPattern();
141+
} else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
142+
return FD->getTemplateInstantiationPattern();
143+
} else if (auto *VD = dyn_cast<VarDecl>(D)) {
144+
// Hmm: getTIP returns its arg if it's not an instantiation?!
145+
VarDecl *T = VD->getTemplateInstantiationPattern();
146+
return (T == D) ? nullptr : T;
147+
} else if (const auto *ED = dyn_cast<EnumDecl>(D)) {
148+
return ED->getInstantiatedFromMemberEnum();
149+
} else if (isa<FieldDecl>(D) || isa<TypedefNameDecl>(D)) {
150+
if (const auto *Parent = llvm::dyn_cast<NamedDecl>(D->getDeclContext()))
151+
if (const DeclContext *ParentPat =
152+
dyn_cast_or_null<DeclContext>(getTemplatePattern(Parent)))
153+
for (const NamedDecl *BaseND : ParentPat->lookup(D->getDeclName()))
154+
if (!BaseND->isImplicit() && BaseND->getKind() == D->getKind())
155+
return BaseND;
156+
} else if (const auto *ECD = dyn_cast<EnumConstantDecl>(D)) {
157+
if (const auto *ED = dyn_cast<EnumDecl>(ECD->getDeclContext())) {
158+
if (const EnumDecl *Pattern = ED->getInstantiatedFromMemberEnum()) {
159+
for (const NamedDecl *BaseECD : Pattern->lookup(ECD->getDeclName()))
160+
return BaseECD;
161+
}
162+
}
163+
}
164+
return nullptr;
165+
}
166+
137167
// TargetFinder locates the entities that an AST node refers to.
138168
//
139169
// Typically this is (possibly) one declaration and (possibly) one type, but
@@ -167,37 +197,12 @@ const Type *getPointeeType(const Type *T) {
167197
struct TargetFinder {
168198
using RelSet = DeclRelationSet;
169199
using Rel = DeclRelation;
170-
llvm::SmallDenseMap<const NamedDecl *, RelSet> Decls;
171-
RelSet Flags;
172200

173-
static const NamedDecl *getTemplatePattern(const NamedDecl *D) {
174-
if (const CXXRecordDecl *CRD = dyn_cast<CXXRecordDecl>(D)) {
175-
return CRD->getTemplateInstantiationPattern();
176-
} else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
177-
return FD->getTemplateInstantiationPattern();
178-
} else if (auto *VD = dyn_cast<VarDecl>(D)) {
179-
// Hmm: getTIP returns its arg if it's not an instantiation?!
180-
VarDecl *T = VD->getTemplateInstantiationPattern();
181-
return (T == D) ? nullptr : T;
182-
} else if (const auto *ED = dyn_cast<EnumDecl>(D)) {
183-
return ED->getInstantiatedFromMemberEnum();
184-
} else if (isa<FieldDecl>(D) || isa<TypedefNameDecl>(D)) {
185-
if (const auto *Parent = llvm::dyn_cast<NamedDecl>(D->getDeclContext()))
186-
if (const DeclContext *ParentPat =
187-
dyn_cast_or_null<DeclContext>(getTemplatePattern(Parent)))
188-
for (const NamedDecl *BaseND : ParentPat->lookup(D->getDeclName()))
189-
if (!BaseND->isImplicit() && BaseND->getKind() == D->getKind())
190-
return BaseND;
191-
} else if (const auto *ECD = dyn_cast<EnumConstantDecl>(D)) {
192-
if (const auto *ED = dyn_cast<EnumDecl>(ECD->getDeclContext())) {
193-
if (const EnumDecl *Pattern = ED->getInstantiatedFromMemberEnum()) {
194-
for (const NamedDecl *BaseECD : Pattern->lookup(ECD->getDeclName()))
195-
return BaseECD;
196-
}
197-
}
198-
}
199-
return nullptr;
200-
}
201+
private:
202+
llvm::SmallDenseMap<const NamedDecl *,
203+
std::pair<RelSet, /*InsertionOrder*/ size_t>>
204+
Decls;
205+
RelSet Flags;
201206

202207
template <typename T> void debug(T &Node, RelSet Flags) {
203208
dlog("visit [{0}] {1}", Flags,
@@ -207,10 +212,22 @@ struct TargetFinder {
207212
void report(const NamedDecl *D, RelSet Flags) {
208213
dlog("--> [{0}] {1}", Flags,
209214
nodeToString(ast_type_traits::DynTypedNode::create(*D)));
210-
Decls[D] |= Flags;
215+
auto It = Decls.try_emplace(D, std::make_pair(Flags, Decls.size()));
216+
// If already exists, update the flags.
217+
if (!It.second)
218+
It.first->second.first |= Flags;
211219
}
212220

213221
public:
222+
llvm::SmallVector<std::pair<const NamedDecl *, RelSet>, 1> takeDecls() const {
223+
using ValTy = std::pair<const NamedDecl *, RelSet>;
224+
llvm::SmallVector<ValTy, 1> Result;
225+
Result.resize(Decls.size());
226+
for (const auto &Elem : Decls)
227+
Result[Elem.second.second] = {Elem.first, Elem.second.first};
228+
return Result;
229+
}
230+
214231
void add(const Decl *Dcl, RelSet Flags) {
215232
const NamedDecl *D = llvm::dyn_cast<NamedDecl>(Dcl);
216233
if (!D)
@@ -485,7 +502,7 @@ allTargetDecls(const ast_type_traits::DynTypedNode &N) {
485502
else if (const CXXCtorInitializer *CCI = N.get<CXXCtorInitializer>())
486503
Finder.add(CCI, Flags);
487504

488-
return {Finder.Decls.begin(), Finder.Decls.end()};
505+
return Finder.takeDecls();
489506
}
490507

491508
llvm::SmallVector<const NamedDecl *, 1>

clang-tools-extra/clangd/Protocol.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,7 @@ llvm::json::Value toJSON(const CompletionItem &CI) {
826826
Result["additionalTextEdits"] = llvm::json::Array(CI.additionalTextEdits);
827827
if (CI.deprecated)
828828
Result["deprecated"] = CI.deprecated;
829+
Result["score"] = CI.score;
829830
return std::move(Result);
830831
}
831832

clang-tools-extra/clangd/Protocol.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,13 @@ struct CompletionItem {
995995
/// Indicates if this item is deprecated.
996996
bool deprecated = false;
997997

998+
/// This is Clangd extension.
999+
/// The score that Clangd calculates to rank completion items. This score can
1000+
/// be used to adjust the ranking on the client side.
1001+
/// NOTE: This excludes fuzzy matching score which is typically calculated on
1002+
/// the client side.
1003+
float score = 0.f;
1004+
9981005
// TODO(krasimir): The following optional fields defined by the language
9991006
// server protocol are unsupported:
10001007
//

clang-tools-extra/clangd/test/completion-auto-trigger.test

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
# CHECK-NEXT: "insertTextFormat": 1,
2525
# CHECK-NEXT: "kind": 5,
2626
# CHECK-NEXT: "label": " size",
27+
# CHECK-NEXT: "score": {{[0-9]+.[0-9]+}},
2728
# CHECK-NEXT: "sortText": "{{.*}}size",
2829
# CHECK-NEXT: "textEdit": {
2930
# CHECK-NEXT: "newText": "size",
@@ -46,6 +47,7 @@
4647
# CHECK-NEXT: "insertTextFormat": 1,
4748
# CHECK-NEXT: "kind": 10,
4849
# CHECK-NEXT: "label": " default_capacity",
50+
# CHECK-NEXT: "score": {{[0-9]+.[0-9]+}},
4951
# CHECK-NEXT: "sortText": "{{.*}}default_capacity",
5052
# CHECK-NEXT: "textEdit": {
5153
# CHECK-NEXT: "newText": "default_capacity",
@@ -86,6 +88,7 @@
8688
# CHECK-NEXT: "insertTextFormat": 1,
8789
# CHECK-NEXT: "kind": 6,
8890
# CHECK-NEXT: "label": " ns_member",
91+
# CHECK-NEXT: "score": {{[0-9]+.[0-9]+}},
8992
# CHECK-NEXT: "sortText": "{{.*}}ns_member",
9093
# CHECK-NEXT: "textEdit": {
9194
# CHECK-NEXT: "newText": "ns_member",

clang-tools-extra/clangd/test/completion-snippets.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
# CHECK-NEXT: "insertTextFormat": 2,
3434
# CHECK-NEXT: "kind": 3,
3535
# CHECK-NEXT: "label": " func_with_args(int a, int b)",
36+
# CHECK-NEXT: "score": {{[0-9]+.[0-9]+}},
3637
# CHECK-NEXT: "sortText": "{{.*}}func_with_args"
3738
# CHECK-NEXT: "textEdit": {
3839
# CHECK-NEXT: "newText": "func_with_args(${1:int a}, ${2:int b})",

clang-tools-extra/clangd/test/completion.test

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# CHECK-NEXT: "insertTextFormat": 1,
1818
# CHECK-NEXT: "kind": 5,
1919
# CHECK-NEXT: "label": " a",
20+
# CHECK-NEXT: "score": {{[0-9]+.[0-9]+}},
2021
# CHECK-NEXT: "sortText": "{{.*}}a"
2122
# CHECK-NEXT: "textEdit": {
2223
# CHECK-NEXT: "newText": "a",
@@ -50,6 +51,7 @@
5051
# CHECK-NEXT: "insertTextFormat": 1,
5152
# CHECK-NEXT: "kind": 5,
5253
# CHECK-NEXT: "label": " b",
54+
# CHECK-NEXT: "score": {{[0-9]+.[0-9]+}},
5355
# CHECK-NEXT: "sortText": "{{.*}}b"
5456
# CHECK-NEXT: "textEdit": {
5557
# CHECK-NEXT: "newText": "b",

clang-tools-extra/clangd/test/protocol.test

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Content-Length: 146
3939
# CHECK-NEXT: "insertTextFormat": 1,
4040
# CHECK-NEXT: "kind": 5,
4141
# CHECK-NEXT: "label": " a",
42+
# CHECK-NEXT: "score": {{[0-9]+.[0-9]+}},
4243
# CHECK-NEXT: "sortText": "{{.*}}"
4344
# CHECK: ]
4445
# CHECK-NEXT: }
@@ -68,6 +69,7 @@ Content-Length: 146
6869
# CHECK-NEXT: "insertTextFormat": 1,
6970
# CHECK-NEXT: "kind": 5,
7071
# CHECK-NEXT: "label": " a",
72+
# CHECK-NEXT: "score": {{[0-9]+.[0-9]+}},
7173
# CHECK-NEXT: "sortText": "{{.*}}"
7274
# CHECK: ]
7375
# CHECK-NEXT: }
@@ -97,6 +99,7 @@ Content-Length: 146
9799
# CHECK-NEXT: "insertTextFormat": 1,
98100
# CHECK-NEXT: "kind": 5,
99101
# CHECK-NEXT: "label": " a",
102+
# CHECK-NEXT: "score": {{[0-9]+.[0-9]+}},
100103
# CHECK-NEXT: "sortText": "{{.*}}"
101104
# CHECK: ]
102105
# CHECK-NEXT: }

clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,6 +1643,7 @@ TEST(CompletionTest, Render) {
16431643
Include.Header = "\"foo.h\"";
16441644
C.Kind = CompletionItemKind::Method;
16451645
C.Score.Total = 1.0;
1646+
C.Score.ExcludingName = .5;
16461647
C.Origin = SymbolOrigin::AST | SymbolOrigin::Static;
16471648

16481649
CodeCompleteOptions Opts;
@@ -1660,6 +1661,7 @@ TEST(CompletionTest, Render) {
16601661
EXPECT_THAT(R.additionalTextEdits, IsEmpty());
16611662
EXPECT_EQ(R.sortText, sortText(1.0, "x"));
16621663
EXPECT_FALSE(R.deprecated);
1664+
EXPECT_EQ(R.score, .5f);
16631665

16641666
Opts.EnableSnippets = true;
16651667
R = C.render(Opts);

0 commit comments

Comments
 (0)