Skip to content

Commit bac2e99

Browse files
committed
Merge from 'main' to 'sycl-web' (intel#70)
CONFLICT (content): Merge conflict in llvm/lib/Support/CMakeLists.txt
2 parents ac68542 + 1527a5e commit bac2e99

File tree

569 files changed

+30693
-9888
lines changed

Some content is hidden

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

569 files changed

+30693
-9888
lines changed

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ llvm::Optional<int64_t> ClangTidyCheck::OptionsView::getEnumInt(
147147

148148
StringRef Value = Iter->getValue().Value;
149149
StringRef Closest;
150-
unsigned EditDistance = -1;
150+
unsigned EditDistance = 3;
151151
for (const auto &NameAndEnum : Mapping) {
152152
if (IgnoreCase) {
153153
if (Value.equals_lower(NameAndEnum.second))
@@ -159,7 +159,8 @@ llvm::Optional<int64_t> ClangTidyCheck::OptionsView::getEnumInt(
159159
EditDistance = 0;
160160
continue;
161161
}
162-
unsigned Distance = Value.edit_distance(NameAndEnum.second);
162+
unsigned Distance =
163+
Value.edit_distance(NameAndEnum.second, true, EditDistance);
163164
if (Distance < EditDistance) {
164165
EditDistance = Distance;
165166
Closest = NameAndEnum.second;

clang-tools-extra/clangd/ClangdLSPServer.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,6 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
571571
{"referencesProvider", true},
572572
{"astProvider", true}, // clangd extension
573573
{"typeHierarchyProvider", true},
574-
{"clangdInlayHintsProvider", true},
575574
{"memoryUsageProvider", true}, // clangd extension
576575
{"compilationDatabase", // clangd extension
577576
llvm::json::Object{{"automaticReload", true}}},
@@ -608,6 +607,9 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
608607
if (Opts.FoldingRanges)
609608
ServerCaps["foldingRangeProvider"] = true;
610609

610+
if (Opts.InlayHints)
611+
ServerCaps["clangdInlayHintsProvider"] = true;
612+
611613
std::vector<llvm::StringRef> Commands;
612614
for (llvm::StringRef Command : Handlers.CommandHandlers.keys())
613615
Commands.push_back(Command);

clang-tools-extra/clangd/ClangdLSPServer.h

+3
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ class ClangdLSPServer : private ClangdServer::Callbacks,
6262
std::function<bool(const Tweak &)> TweakFilter = [](const Tweak &T) {
6363
return !T.hidden(); // only enable non-hidden tweaks.
6464
};
65+
66+
/// Enable preview of InlayHints feature.
67+
bool InlayHints = false;
6568
};
6669

6770
ClangdLSPServer(Transport &Transp, const ThreadsafeFS &TFS,

clang-tools-extra/clangd/HeuristicResolver.cpp

+26-5
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,15 @@ HeuristicResolver::resolveTypeOfCallExpr(const CallExpr *CE) const {
130130
return {};
131131
}
132132

133+
std::vector<const NamedDecl *>
134+
HeuristicResolver::resolveCalleeOfCallExpr(const CallExpr *CE) const {
135+
if (const auto *ND = dyn_cast_or_null<NamedDecl>(CE->getCalleeDecl())) {
136+
return {ND};
137+
}
138+
139+
return resolveExprToDecls(CE->getCallee());
140+
}
141+
133142
std::vector<const NamedDecl *> HeuristicResolver::resolveUsingValueDecl(
134143
const UnresolvedUsingValueDecl *UUVD) const {
135144
return resolveDependentMember(UUVD->getQualifier()->getAsType(),
@@ -163,18 +172,30 @@ const Type *resolveDeclsToType(const std::vector<const NamedDecl *> &Decls) {
163172
return nullptr;
164173
}
165174

166-
const Type *HeuristicResolver::resolveExprToType(const Expr *E) const {
175+
std::vector<const NamedDecl *>
176+
HeuristicResolver::resolveExprToDecls(const Expr *E) const {
167177
if (const auto *ME = dyn_cast<CXXDependentScopeMemberExpr>(E)) {
168-
return resolveDeclsToType(resolveMemberExpr(ME));
178+
return resolveMemberExpr(ME);
169179
}
170180
if (const auto *RE = dyn_cast<DependentScopeDeclRefExpr>(E)) {
171-
return resolveDeclsToType(resolveDeclRefExpr(RE));
181+
return resolveDeclRefExpr(RE);
182+
}
183+
if (const auto *OE = dyn_cast<OverloadExpr>(E)) {
184+
return {OE->decls_begin(), OE->decls_end()};
172185
}
173186
if (const auto *CE = dyn_cast<CallExpr>(E)) {
174-
return resolveDeclsToType(resolveTypeOfCallExpr(CE));
187+
return resolveTypeOfCallExpr(CE);
175188
}
176189
if (const auto *ME = dyn_cast<MemberExpr>(E))
177-
return resolveDeclsToType({ME->getMemberDecl()});
190+
return {ME->getMemberDecl()};
191+
192+
return {};
193+
}
194+
195+
const Type *HeuristicResolver::resolveExprToType(const Expr *E) const {
196+
std::vector<const NamedDecl *> Decls = resolveExprToDecls(E);
197+
if (!Decls.empty())
198+
return resolveDeclsToType(Decls);
178199

179200
return E->getType().getTypePtr();
180201
}

clang-tools-extra/clangd/HeuristicResolver.h

+3
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ class HeuristicResolver {
5656
std::vector<const NamedDecl *>
5757
resolveTypeOfCallExpr(const CallExpr *CE) const;
5858
std::vector<const NamedDecl *>
59+
resolveCalleeOfCallExpr(const CallExpr *CE) const;
60+
std::vector<const NamedDecl *>
5961
resolveUsingValueDecl(const UnresolvedUsingValueDecl *UUVD) const;
6062
std::vector<const NamedDecl *>
6163
resolveDependentNameType(const DependentNameType *DNT) const;
@@ -87,6 +89,7 @@ class HeuristicResolver {
8789
// Try to heuristically resolve the type of a possibly-dependent expression
8890
// `E`.
8991
const Type *resolveExprToType(const Expr *E) const;
92+
std::vector<const NamedDecl *> resolveExprToDecls(const Expr *E) const;
9093

9194
// Given the type T of a dependent expression that appears of the LHS of a
9295
// "->", heuristically find a corresponding pointee type in whose scope we

clang-tools-extra/clangd/InlayHints.cpp

+16-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88
#include "InlayHints.h"
9+
#include "HeuristicResolver.h"
910
#include "ParsedAST.h"
1011
#include "support/Logger.h"
1112
#include "clang/AST/DeclarationName.h"
@@ -20,7 +21,8 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
2021
public:
2122
InlayHintVisitor(std::vector<InlayHint> &Results, ParsedAST &AST)
2223
: Results(Results), AST(AST.getASTContext()),
23-
MainFileID(AST.getSourceManager().getMainFileID()) {
24+
MainFileID(AST.getSourceManager().getMainFileID()),
25+
Resolver(AST.getHeuristicResolver()) {
2426
bool Invalid = false;
2527
llvm::StringRef Buf =
2628
AST.getSourceManager().getBufferData(MainFileID, &Invalid);
@@ -50,9 +52,18 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
5052
if (isa<CXXOperatorCallExpr>(E) || isa<UserDefinedLiteral>(E))
5153
return true;
5254

53-
processCall(E->getRParenLoc(),
54-
dyn_cast_or_null<FunctionDecl>(E->getCalleeDecl()),
55-
{E->getArgs(), E->getNumArgs()});
55+
auto CalleeDecls = Resolver->resolveCalleeOfCallExpr(E);
56+
if (CalleeDecls.size() != 1)
57+
return true;
58+
const FunctionDecl *Callee = nullptr;
59+
if (const auto *FD = dyn_cast<FunctionDecl>(CalleeDecls[0]))
60+
Callee = FD;
61+
else if (const auto *FTD = dyn_cast<FunctionTemplateDecl>(CalleeDecls[0]))
62+
Callee = FTD->getTemplatedDecl();
63+
if (!Callee)
64+
return true;
65+
66+
processCall(E->getRParenLoc(), Callee, {E->getArgs(), E->getNumArgs()});
5667
return true;
5768
}
5869

@@ -266,6 +277,7 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
266277
ASTContext &AST;
267278
FileID MainFileID;
268279
StringRef MainFileBuf;
280+
const HeuristicResolver *Resolver;
269281
};
270282

271283
std::vector<InlayHint> inlayHints(ParsedAST &AST) {

clang-tools-extra/clangd/ParsedAST.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "Diagnostics.h"
1717
#include "FeatureModule.h"
1818
#include "Headers.h"
19+
#include "HeuristicResolver.h"
1920
#include "IncludeFixer.h"
2021
#include "Preamble.h"
2122
#include "SourceCode.h"

clang-tools-extra/clangd/ParsedAST.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include "Compiler.h"
2525
#include "Diagnostics.h"
2626
#include "Headers.h"
27-
#include "HeuristicResolver.h"
2827
#include "Preamble.h"
2928
#include "index/CanonicalIncludes.h"
3029
#include "support/Path.h"
@@ -43,6 +42,7 @@
4342

4443
namespace clang {
4544
namespace clangd {
45+
class HeuristicResolver;
4646
class SymbolIndex;
4747

4848
/// Stores and provides access to parsed AST.

clang-tools-extra/clangd/SemanticHighlighting.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "SemanticHighlighting.h"
1010
#include "FindTarget.h"
11+
#include "HeuristicResolver.h"
1112
#include "ParsedAST.h"
1213
#include "Protocol.h"
1314
#include "SourceCode.h"

clang-tools-extra/clangd/test/initialize-params.test

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
# CHECK-NEXT: "capabilities": {
88
# CHECK-NEXT: "astProvider": true,
99
# CHECK-NEXT: "callHierarchyProvider": true,
10-
# CHECK-NEXT: "clangdInlayHintsProvider": true,
1110
# CHECK-NEXT: "codeActionProvider": true,
1211
# CHECK-NEXT: "compilationDatabase": {
1312
# CHECK-NEXT: "automaticReload": true

clang-tools-extra/clangd/tool/ClangdMain.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,9 @@ opt<bool> FoldingRanges{
308308
Hidden,
309309
};
310310

311+
opt<bool> InlayHints{"inlay-hints", cat(Features),
312+
desc("Enable preview of InlayHints feature"), init(false)};
313+
311314
opt<unsigned> WorkerThreadsCount{
312315
"j",
313316
cat(Misc),
@@ -829,6 +832,7 @@ clangd accepts flags on the commandline, and in the CLANGD_FLAGS environment var
829832
}
830833
Opts.AsyncThreadsCount = WorkerThreadsCount;
831834
Opts.FoldingRanges = FoldingRanges;
835+
Opts.InlayHints = InlayHints;
832836
Opts.MemoryCleanup = getMemoryCleanupFunction();
833837

834838
Opts.CodeComplete.IncludeIneligibleResults = IncludeIneligibleResults;

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

+23-7
Original file line numberDiff line numberDiff line change
@@ -244,19 +244,35 @@ TEST(ParameterHints, LeadingUnderscore) {
244244
ExpectedHint{"p3: ", "p3"});
245245
}
246246

247-
TEST(ParameterHints, DependentCall) {
248-
// FIXME: This doesn't currently produce a hint but should.
247+
TEST(ParameterHints, DependentCalls) {
249248
assertParameterHints(R"cpp(
250249
template <typename T>
251-
void foo(T param);
250+
void nonmember(T par1);
251+
252+
template <typename T>
253+
struct A {
254+
void member(T par2);
255+
static void static_member(T par3);
256+
};
257+
258+
void overload(int anInt);
259+
void overload(double aDouble);
252260
253261
template <typename T>
254262
struct S {
255-
void bar(T par) {
256-
foo($param[[par]]);
263+
void bar(A<T> a, T t) {
264+
nonmember($par1[[t]]);
265+
a.member($par2[[t]]);
266+
// FIXME: This one does not work yet.
267+
A<T>::static_member($par3[[t]]);
268+
// We don't want to arbitrarily pick between
269+
// "anInt" or "aDouble", so just show no hint.
270+
overload(T{});
257271
}
258272
};
259-
)cpp");
273+
)cpp",
274+
ExpectedHint{"par1: ", "par1"},
275+
ExpectedHint{"par2: ", "par2"});
260276
}
261277

262278
TEST(ParameterHints, VariadicFunction) {
@@ -362,4 +378,4 @@ TEST(ParameterHints, SetterFunctions) {
362378

363379
} // namespace
364380
} // namespace clangd
365-
} // namespace clang
381+
} // namespace clang

clang/include/clang/AST/DeclCXX.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -2425,12 +2425,12 @@ class CXXConstructorDecl final
24252425
: ExplicitSpecKind::ResolvedFalse);
24262426
}
24272427

2428-
enum TraillingAllocKind {
2428+
enum TrailingAllocKind {
24292429
TAKInheritsConstructor = 1,
24302430
TAKHasTailExplicit = 1 << 1,
24312431
};
24322432

2433-
uint64_t getTraillingAllocKind() const {
2433+
uint64_t getTrailingAllocKind() const {
24342434
return numTrailingObjects(OverloadToken<InheritedConstructor>()) |
24352435
(numTrailingObjects(OverloadToken<ExplicitSpecifier>()) << 1);
24362436
}

clang/include/clang/Basic/CodeGenOptions.def

+2-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ CODEGENOPT(NoInlineLineTables, 1, 0) ///< Whether debug info should contain
172172
CODEGENOPT(StackClashProtector, 1, 0) ///< Set when -fstack-clash-protection is enabled.
173173
CODEGENOPT(NoImplicitFloat , 1, 0) ///< Set when -mno-implicit-float is enabled.
174174
CODEGENOPT(NullPointerIsValid , 1, 0) ///< Assume Null pointer deference is defined.
175-
CODEGENOPT(CorrectlyRoundedDivSqrt, 1, 0) ///< -cl-fp32-correctly-rounded-divide-sqrt
175+
CODEGENOPT(OpenCLCorrectlyRoundedDivSqrt, 1, 0) ///< -cl-fp32-correctly-rounded-divide-sqrt
176+
CODEGENOPT(HIPCorrectlyRoundedDivSqrt, 1, 1) ///< -fno-hip-fp32-correctly-rounded-divide-sqrt
176177
CODEGENOPT(UniqueInternalLinkageNames, 1, 0) ///< Internal Linkage symbols get unique names.
177178
CODEGENOPT(SplitMachineFunctions, 1, 0) ///< Split machine functions using profile information.
178179

0 commit comments

Comments
 (0)