Skip to content

Commit ec4d77e

Browse files
committed
Merge commit 'bcaf57cae82500f40f2348f5ee41e57b11152825' into llvmspirv_pulldown
2 parents 018290f + bcaf57c commit ec4d77e

File tree

1,193 files changed

+107417
-28470
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,193 files changed

+107417
-28470
lines changed

clang-tools-extra/clangd/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# This is a no-op for building files in this dir, but is inherited by subdirs.
2+
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
3+
include_directories(${CMAKE_CURRENT_BINARY_DIR})
4+
15
add_subdirectory(support)
26

37
# Configure the Features.inc file.

clang-tools-extra/clangd/InlayHints.cpp

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
3232
TypeHintPolicy.SuppressScope = true; // keep type names short
3333
TypeHintPolicy.AnonymousTagLocations =
3434
false; // do not print lambda locations
35+
// Print canonical types. Otherwise, SuppressScope would result in
36+
// things like "metafunction<args>::type" being shorted to just "type",
37+
// which is useless. This is particularly important for structured
38+
// bindings that use the tuple_element protocol, where the non-canonical
39+
// types would be "tuple_element<I, A>::type".
40+
// Note, for "auto", we would often prefer sugared types, but the AST
41+
// doesn't currently retain them in DeducedType anyways.
42+
TypeHintPolicy.PrintCanonicalTypes = true;
3543
}
3644

3745
bool VisitCXXConstructExpr(CXXConstructExpr *E) {
@@ -76,20 +84,23 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
7684
if (auto *AT = D->getReturnType()->getContainedAutoType()) {
7785
QualType Deduced = AT->getDeducedType();
7886
if (!Deduced.isNull()) {
79-
addInlayHint(D->getFunctionTypeLoc().getRParenLoc(),
80-
InlayHintKind::TypeHint,
81-
"-> " + D->getReturnType().getAsString(TypeHintPolicy));
87+
addTypeHint(D->getFunctionTypeLoc().getRParenLoc(), D->getReturnType(),
88+
"-> ");
8289
}
8390
}
8491

8592
return true;
8693
}
8794

8895
bool VisitVarDecl(VarDecl *D) {
89-
// Do not show hints for the aggregate in a structured binding.
90-
// In the future, we may show hints for the individual bindings.
91-
if (isa<DecompositionDecl>(D))
96+
// Do not show hints for the aggregate in a structured binding,
97+
// but show hints for the individual bindings.
98+
if (auto *DD = dyn_cast<DecompositionDecl>(D)) {
99+
for (auto *Binding : DD->bindings()) {
100+
addTypeHint(Binding->getLocation(), Binding->getType(), ": ");
101+
}
92102
return true;
103+
}
93104

94105
if (D->getType()->getContainedAutoType()) {
95106
if (!D->getType()->isDependentType()) {
@@ -98,8 +109,7 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
98109
// (e.g. for `const auto& x = 42`, print `const int&`).
99110
// Alternatively, we could place the hint on the `auto`
100111
// (and then just print the type deduced for the `auto`).
101-
addInlayHint(D->getLocation(), InlayHintKind::TypeHint,
102-
": " + D->getType().getAsString(TypeHintPolicy));
112+
addTypeHint(D->getLocation(), D->getType(), ": ");
103113
}
104114
}
105115
return true;
@@ -311,6 +321,15 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
311321
Kind, Label.str()});
312322
}
313323

324+
void addTypeHint(SourceRange R, QualType T, llvm::StringRef Prefix) {
325+
// Do not print useless "NULL TYPE" hint.
326+
if (!T.getTypePtrOrNull())
327+
return;
328+
329+
addInlayHint(R, InlayHintKind::TypeHint,
330+
std::string(Prefix) + T.getAsString(TypeHintPolicy));
331+
}
332+
314333
std::vector<InlayHint> &Results;
315334
ASTContext &AST;
316335
FileID MainFileID;

clang-tools-extra/clangd/TUScheduler.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,11 +1380,13 @@ bool ASTWorker::blockUntilIdle(Deadline Timeout) const {
13801380
};
13811381
// Make sure ASTWorker has processed all requests, which might issue new
13821382
// updates to PreamblePeer.
1383-
WaitUntilASTWorkerIsIdle();
1383+
if (!WaitUntilASTWorkerIsIdle())
1384+
return false;
13841385
// Now that ASTWorker processed all requests, ensure PreamblePeer has served
13851386
// all update requests. This might create new PreambleRequests for the
13861387
// ASTWorker.
1387-
PreamblePeer.blockUntilIdle(Timeout);
1388+
if (!PreamblePeer.blockUntilIdle(Timeout))
1389+
return false;
13881390
assert(Requests.empty() &&
13891391
"No new normal tasks can be scheduled concurrently with "
13901392
"blockUntilIdle(): ASTWorker isn't threadsafe");

clang-tools-extra/clangd/Transport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_TRANSPORT_H_
1919
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_TRANSPORT_H_
2020

21+
#include "Features.h"
2122
#include "llvm/ADT/StringRef.h"
2223
#include "llvm/Support/JSON.h"
2324
#include "llvm/Support/raw_ostream.h"

clang-tools-extra/clangd/benchmarks/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../)
2-
31
add_subdirectory(CompletionModel)
42

53
add_benchmark(IndexBenchmark IndexBenchmark.cpp)

clang-tools-extra/clangd/benchmarks/CompletionModel/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../)
2-
31
add_benchmark(DecisionForestBenchmark DecisionForestBenchmark.cpp)
42

53
target_link_libraries(DecisionForestBenchmark

clang-tools-extra/clangd/fuzzer/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..
2-
${CMAKE_CURRENT_BINARY_DIR}/..)
3-
41
set(LLVM_LINK_COMPONENTS
52
FuzzMutate
63
Support

clang-tools-extra/clangd/index/dex/dexp/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../)
2-
include_directories(${CMAKE_CURRENT_BINARY_DIR}/../../../)
3-
41
set(LLVM_LINK_COMPONENTS
52
LineEditor
63
Support

clang-tools-extra/clangd/index/remote/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ if (CLANGD_ENABLE_REMOTE)
1313
MonitoringServiceProto
1414
)
1515
include_directories(${CMAKE_CURRENT_BINARY_DIR})
16-
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../)
17-
include_directories(${CMAKE_CURRENT_BINARY_DIR}/../../)
1816

1917
# FIXME(kirillbobyrev): target_compile_definitions is not working with
2018
# add_clang_library for some reason. Is there any way to make this

clang-tools-extra/clangd/indexer/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../)
2-
31
set(LLVM_LINK_COMPONENTS
42
Support
53
)

clang-tools-extra/clangd/support/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ if(NOT HAVE_CXX_ATOMICS_WITHOUT_LIB OR NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB)
1515
list(APPEND CLANGD_ATOMIC_LIB "atomic")
1616
endif()
1717

18-
include_directories(..)
1918
add_clang_library(clangdSupport
2019
Cancellation.cpp
2120
Context.cpp

clang-tools-extra/clangd/support/Threading.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "support/Context.h"
1313
#include "llvm/ADT/FunctionExtras.h"
1414
#include "llvm/ADT/Twine.h"
15+
#include <atomic>
1516
#include <cassert>
1617
#include <condition_variable>
1718
#include <future>

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
2-
include_directories(${CMAKE_CURRENT_BINARY_DIR}/..)
3-
41
add_clang_tool(clangd
52
ClangdMain.cpp
63
Check.cpp

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
// Must be before Transport.h include.
10-
#include "Features.h"
11-
129
#include "ClangdLSPServer.h"
1310
#include "CodeComplete.h"
1411
#include "Config.h"
1512
#include "ConfigProvider.h"
13+
#include "Features.h"
1614
#include "PathMapping.h"
1715
#include "Protocol.h"
1816
#include "TidyProvider.h"

clang-tools-extra/clangd/unittests/CMakeLists.txt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,6 @@ set(LLVM_LINK_COMPONENTS
44
FrontendOpenMP
55
)
66

7-
get_filename_component(CLANGD_SOURCE_DIR
8-
${CMAKE_CURRENT_SOURCE_DIR}/../../clangd REALPATH)
9-
get_filename_component(CLANGD_BINARY_DIR
10-
${CMAKE_CURRENT_BINARY_DIR}/../../clangd REALPATH)
11-
include_directories(
12-
${CLANGD_SOURCE_DIR}
13-
${CLANGD_BINARY_DIR}
14-
)
15-
167
if(CLANG_BUILT_STANDALONE)
178
# LLVMTestingSupport library is needed for clangd tests.
189
if (EXISTS ${LLVM_MAIN_SRC_DIR}/lib/Testing/Support

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

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -461,19 +461,70 @@ TEST(TypeHints, Lambda) {
461461
ExpectedHint{": int", "init"});
462462
}
463463

464-
TEST(TypeHints, StructuredBindings) {
465-
// FIXME: Not handled yet.
466-
// To handle it, we could print:
467-
// - the aggregate type next to the 'auto', or
468-
// - the individual types inside the brackets
469-
// The latter is probably more useful.
464+
// Structured bindings tests.
465+
// Note, we hint the individual bindings, not the aggregate.
466+
467+
TEST(TypeHints, StructuredBindings_PublicStruct) {
470468
assertTypeHints(R"cpp(
469+
// Struct with public fields.
471470
struct Point {
472471
int x;
473472
int y;
474473
};
475474
Point foo();
476-
auto [x, y] = foo();
475+
auto [$x[[x]], $y[[y]]] = foo();
476+
)cpp",
477+
ExpectedHint{": int", "x"}, ExpectedHint{": int", "y"});
478+
}
479+
480+
TEST(TypeHints, StructuredBindings_Array) {
481+
assertTypeHints(R"cpp(
482+
int arr[2];
483+
auto [$x[[x]], $y[[y]]] = arr;
484+
)cpp",
485+
ExpectedHint{": int", "x"}, ExpectedHint{": int", "y"});
486+
}
487+
488+
TEST(TypeHints, StructuredBindings_TupleLike) {
489+
assertTypeHints(R"cpp(
490+
// Tuple-like type.
491+
struct IntPair {
492+
int a;
493+
int b;
494+
};
495+
namespace std {
496+
template <typename T>
497+
struct tuple_size {};
498+
template <>
499+
struct tuple_size<IntPair> {
500+
constexpr static unsigned value = 2;
501+
};
502+
template <unsigned I, typename T>
503+
struct tuple_element {};
504+
template <unsigned I>
505+
struct tuple_element<I, IntPair> {
506+
using type = int;
507+
};
508+
}
509+
template <unsigned I>
510+
int get(const IntPair& p) {
511+
if constexpr (I == 0) {
512+
return p.a;
513+
} else if constexpr (I == 1) {
514+
return p.b;
515+
}
516+
}
517+
IntPair bar();
518+
auto [$x[[x]], $y[[y]]] = bar();
519+
)cpp",
520+
ExpectedHint{": int", "x"}, ExpectedHint{": int", "y"});
521+
}
522+
523+
TEST(TypeHints, StructuredBindings_NoInitializer) {
524+
assertTypeHints(R"cpp(
525+
// No initializer (ill-formed).
526+
// Do not show useless "NULL TYPE" hint.
527+
auto [x, y]; /*error-ok*/
477528
)cpp");
478529
}
479530

clang-tools-extra/clangd/unittests/xpc/CMakeLists.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@ set(LLVM_LINK_COMPONENTS
22
support
33
)
44

5-
get_filename_component(CLANGD_SOURCE_DIR
6-
${CMAKE_CURRENT_SOURCE_DIR}/../../clangd REALPATH)
7-
include_directories(
8-
${CLANGD_SOURCE_DIR}
9-
)
10-
115
add_custom_target(ClangdXpcUnitTests)
126
add_unittest(ClangdXpcUnitTests ClangdXpcTests
137
ConversionTests.cpp

clang-tools-extra/clangd/xpc/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ include(CreateClangdXPCFramework)
77
add_subdirectory(framework)
88
add_subdirectory(test-client)
99

10-
include_directories(
11-
${CMAKE_CURRENT_SOURCE_DIR}/../
12-
)
13-
1410
set(LLVM_LINK_COMPONENTS
1511
Support
1612
)

clang-tools-extra/clangd/xpc/test-client/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
include_directories(
2-
${CMAKE_CURRENT_SOURCE_DIR}/../../
3-
)
4-
51
add_clang_tool(
62
clangd-xpc-test-client
73
ClangdXPCTestClient.cpp

clang/include/clang/Lex/PPCallbacks.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ class PPCallbacks {
191191
StringRef Str) {
192192
}
193193

194+
/// Callback invoked when a \#pragma mark comment is read.
195+
virtual void PragmaMark(SourceLocation Loc, StringRef Trivia) {
196+
}
197+
194198
/// Callback invoked when a \#pragma detect_mismatch directive is
195199
/// read.
196200
virtual void PragmaDetectMismatch(SourceLocation Loc, StringRef Name,

clang/include/clang/Lex/Preprocessor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2365,7 +2365,7 @@ class Preprocessor {
23652365

23662366
public:
23672367
void HandlePragmaOnce(Token &OnceTok);
2368-
void HandlePragmaMark();
2368+
void HandlePragmaMark(Token &MarkTok);
23692369
void HandlePragmaPoison();
23702370
void HandlePragmaSystemHeader(Token &SysHeaderTok);
23712371
void HandlePragmaDependency(Token &DependencyTok);

clang/lib/AST/ASTImporter.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ namespace clang {
496496
ExpectedDecl VisitAccessSpecDecl(AccessSpecDecl *D);
497497
ExpectedDecl VisitStaticAssertDecl(StaticAssertDecl *D);
498498
ExpectedDecl VisitTranslationUnitDecl(TranslationUnitDecl *D);
499+
ExpectedDecl VisitBindingDecl(BindingDecl *D);
499500
ExpectedDecl VisitNamespaceDecl(NamespaceDecl *D);
500501
ExpectedDecl VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
501502
ExpectedDecl VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias);
@@ -2297,6 +2298,35 @@ ExpectedDecl ASTNodeImporter::VisitTranslationUnitDecl(TranslationUnitDecl *D) {
22972298
return ToD;
22982299
}
22992300

2301+
ExpectedDecl ASTNodeImporter::VisitBindingDecl(BindingDecl *D) {
2302+
DeclContext *DC, *LexicalDC;
2303+
DeclarationName Name;
2304+
SourceLocation Loc;
2305+
NamedDecl *ToND;
2306+
if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToND, Loc))
2307+
return std::move(Err);
2308+
if (ToND)
2309+
return ToND;
2310+
2311+
Error Err = Error::success();
2312+
QualType ToType = importChecked(Err, D->getType());
2313+
Expr *ToBinding = importChecked(Err, D->getBinding());
2314+
ValueDecl *ToDecomposedDecl = importChecked(Err, D->getDecomposedDecl());
2315+
if (Err)
2316+
return std::move(Err);
2317+
2318+
BindingDecl *ToD;
2319+
if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, Loc,
2320+
Name.getAsIdentifierInfo()))
2321+
return ToD;
2322+
2323+
ToD->setBinding(ToType, ToBinding);
2324+
ToD->setDecomposedDecl(ToDecomposedDecl);
2325+
addDeclToContexts(D, ToD);
2326+
2327+
return ToD;
2328+
}
2329+
23002330
ExpectedDecl ASTNodeImporter::VisitAccessSpecDecl(AccessSpecDecl *D) {
23012331
ExpectedSLoc LocOrErr = import(D->getLocation());
23022332
if (!LocOrErr)

clang/lib/Basic/Targets/OSTargets.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -948,8 +948,16 @@ class LLVM_LIBRARY_VISIBILITY EmscriptenTargetInfo
948948
}
949949

950950
public:
951-
explicit EmscriptenTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
952-
: WebAssemblyOSTargetInfo<Target>(Triple, Opts) {}
951+
explicit EmscriptenTargetInfo(const llvm::Triple &Triple,
952+
const TargetOptions &Opts)
953+
: WebAssemblyOSTargetInfo<Target>(Triple, Opts) {
954+
// Keeping the alignment of long double to 8 bytes even though its size is
955+
// 16 bytes allows emscripten to have an 8-byte-aligned max_align_t which
956+
// in turn gives is a 8-byte aligned malloc.
957+
// Emscripten's ABI is unstable and we may change this back to 128 to match
958+
// the WebAssembly default in the future.
959+
this->LongDoubleAlign = 64;
960+
}
953961
};
954962

955963
} // namespace targets

0 commit comments

Comments
 (0)