Skip to content

Commit 98ebbb7

Browse files
authored
LLVM and SPIRV-LLVM-Translator pulldown (WW33) #4300
LLVM: llvm/llvm-project@b978df4 SPIRV-LLVM-Translator: KhronosGroup/SPIRV-LLVM-Translator@a6ca745
2 parents 66276bd + 5c4c4c6 commit 98ebbb7

File tree

1,387 files changed

+41257
-15852
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,387 files changed

+41257
-15852
lines changed

clang-tools-extra/clang-change-namespace/ChangeNamespace.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ void ChangeNamespaceTool::registerMatchers(ast_matchers::MatchFinder *Finder) {
442442
hasDeclaration(DeclMatcher),
443443
unless(templateSpecializationType()))))),
444444
hasParent(nestedNameSpecifierLoc()),
445-
hasAncestor(isImplicit()),
445+
hasAncestor(decl(isImplicit())),
446446
hasAncestor(UsingShadowDeclInClass),
447447
hasAncestor(functionDecl(isDefaulted())))),
448448
hasAncestor(decl().bind("dc")))
@@ -466,7 +466,7 @@ void ChangeNamespaceTool::registerMatchers(ast_matchers::MatchFinder *Finder) {
466466
hasAncestor(decl(IsInMovedNs).bind("dc")),
467467
loc(nestedNameSpecifier(
468468
specifiesType(hasDeclaration(DeclMatcher.bind("from_decl"))))),
469-
unless(anyOf(hasAncestor(isImplicit()),
469+
unless(anyOf(hasAncestor(decl(isImplicit())),
470470
hasAncestor(UsingShadowDeclInClass),
471471
hasAncestor(functionDecl(isDefaulted())),
472472
hasAncestor(typeLoc(loc(qualType(hasDeclaration(
@@ -495,7 +495,7 @@ void ChangeNamespaceTool::registerMatchers(ast_matchers::MatchFinder *Finder) {
495495
hasAncestor(cxxRecordDecl()))),
496496
hasParent(namespaceDecl()));
497497
Finder->addMatcher(expr(hasAncestor(decl().bind("dc")), IsInMovedNs,
498-
unless(hasAncestor(isImplicit())),
498+
unless(hasAncestor(decl(isImplicit()))),
499499
anyOf(callExpr(callee(FuncMatcher)).bind("call"),
500500
declRefExpr(to(FuncMatcher.bind("func_decl")))
501501
.bind("func_ref"))),

clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ void ProBoundsConstantArrayIndexCheck::registerPPCallbacks(
3838
void ProBoundsConstantArrayIndexCheck::registerMatchers(MatchFinder *Finder) {
3939
// Note: if a struct contains an array member, the compiler-generated
4040
// constructor has an arraySubscriptExpr.
41-
Finder->addMatcher(
42-
arraySubscriptExpr(
43-
hasBase(ignoringImpCasts(hasType(constantArrayType().bind("type")))),
44-
hasIndex(expr().bind("index")), unless(hasAncestor(isImplicit())))
45-
.bind("expr"),
46-
this);
41+
Finder->addMatcher(arraySubscriptExpr(hasBase(ignoringImpCasts(hasType(
42+
constantArrayType().bind("type")))),
43+
hasIndex(expr().bind("index")),
44+
unless(hasAncestor(decl(isImplicit()))))
45+
.bind("expr"),
46+
this);
4747

4848
Finder->addMatcher(
4949
cxxOperatorCallExpr(

clang-tools-extra/clangd/AST.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
#include "clang/AST/NestedNameSpecifier.h"
2121
#include "clang/AST/PrettyPrinter.h"
2222
#include "clang/AST/RecursiveASTVisitor.h"
23+
#include "clang/AST/Stmt.h"
2324
#include "clang/AST/TemplateBase.h"
25+
#include "clang/AST/TypeLoc.h"
2426
#include "clang/Basic/SourceLocation.h"
2527
#include "clang/Basic/SourceManager.h"
2628
#include "clang/Basic/Specifiers.h"
@@ -481,6 +483,23 @@ llvm::Optional<QualType> getDeducedType(ASTContext &ASTCtx,
481483
return V.DeducedType;
482484
}
483485

486+
std::vector<const Attr *> getAttributes(const DynTypedNode &N) {
487+
std::vector<const Attr *> Result;
488+
if (const auto *TL = N.get<TypeLoc>()) {
489+
for (AttributedTypeLoc ATL = TL->getAs<AttributedTypeLoc>(); !ATL.isNull();
490+
ATL = ATL.getModifiedLoc().getAs<AttributedTypeLoc>()) {
491+
Result.push_back(ATL.getAttr());
492+
assert(!ATL.getModifiedLoc().isNull());
493+
}
494+
}
495+
if (const auto *S = N.get<AttributedStmt>())
496+
for (; S != nullptr; S = dyn_cast<AttributedStmt>(S->getSubStmt()))
497+
llvm::copy(S->getAttrs(), std::back_inserter(Result));
498+
if (const auto *D = N.get<Decl>())
499+
llvm::copy(D->attrs(), std::back_inserter(Result));
500+
return Result;
501+
}
502+
484503
std::string getQualification(ASTContext &Context,
485504
const DeclContext *DestContext,
486505
SourceLocation InsertionPoint,

clang-tools-extra/clangd/AST.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
namespace clang {
2828
class SourceManager;
2929
class Decl;
30+
class DynTypedNode;
3031

3132
namespace clangd {
3233

@@ -121,6 +122,9 @@ QualType declaredType(const TypeDecl *D);
121122
/// If the type is an undeduced auto, returns the type itself.
122123
llvm::Optional<QualType> getDeducedType(ASTContext &, SourceLocation Loc);
123124

125+
/// Return attributes attached directly to a node.
126+
std::vector<const Attr *> getAttributes(const DynTypedNode &);
127+
124128
/// Gets the nested name specifier necessary for spelling \p ND in \p
125129
/// DestContext, at \p InsertionPoint. It selects the shortest suffix of \p ND
126130
/// such that it is visible in \p DestContext.

clang-tools-extra/clangd/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ add_clang_library(clangDaemon
7171
DumpAST.cpp
7272
ExpectedTypes.cpp
7373
FeatureModule.cpp
74-
Features.cpp
74+
Feature.cpp
7575
FindSymbols.cpp
7676
FindTarget.cpp
7777
FileDistance.cpp

clang-tools-extra/clangd/ClangdLSPServer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "Diagnostics.h"
1313
#include "DraftStore.h"
1414
#include "DumpAST.h"
15-
#include "Features.h"
15+
#include "Feature.h"
1616
#include "GlobalCompilationDatabase.h"
1717
#include "LSPBinder.h"
1818
#include "Protocol.h"

clang-tools-extra/clangd/CollectMacros.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,33 @@ void CollectMainFileMacros::add(const Token &MacroNameTok, const MacroInfo *MI,
3030
else
3131
Out.UnknownMacros.push_back({Range, IsDefinition});
3232
}
33+
34+
class CollectPragmaMarks : public PPCallbacks {
35+
public:
36+
explicit CollectPragmaMarks(const SourceManager &SM,
37+
std::vector<clangd::PragmaMark> &Out)
38+
: SM(SM), Out(Out) {}
39+
40+
void PragmaMark(SourceLocation Loc, StringRef Trivia) override {
41+
if (isInsideMainFile(Loc, SM)) {
42+
// FIXME: This range should just cover `XX` in `#pragma mark XX` and
43+
// `- XX` in `#pragma mark - XX`.
44+
Position Start = sourceLocToPosition(SM, Loc);
45+
Position End = {Start.line + 1, 0};
46+
Out.emplace_back(clangd::PragmaMark{{Start, End}, Trivia.str()});
47+
}
48+
}
49+
50+
private:
51+
const SourceManager &SM;
52+
std::vector<clangd::PragmaMark> &Out;
53+
};
54+
55+
std::unique_ptr<PPCallbacks>
56+
collectPragmaMarksCallback(const SourceManager &SM,
57+
std::vector<PragmaMark> &Out) {
58+
return std::make_unique<CollectPragmaMarks>(SM, Out);
59+
}
60+
3361
} // namespace clangd
3462
} // namespace clang

clang-tools-extra/clangd/CollectMacros.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,18 @@ class CollectMainFileMacros : public PPCallbacks {
9999
MainFileMacros &Out;
100100
};
101101

102+
/// Represents a `#pragma mark` in the main file.
103+
///
104+
/// There can be at most one pragma mark per line.
105+
struct PragmaMark {
106+
Range Rng;
107+
std::string Trivia;
108+
};
109+
110+
/// Collect all pragma marks from the main file.
111+
std::unique_ptr<PPCallbacks>
112+
collectPragmaMarksCallback(const SourceManager &, std::vector<PragmaMark> &Out);
113+
102114
} // namespace clangd
103115
} // namespace clang
104116

clang-tools-extra/clangd/CompileCommands.cpp

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -222,22 +222,42 @@ void CommandMangler::adjust(std::vector<std::string> &Cmd,
222222
/*FlagsToExclude=*/driver::options::NoDriverOption |
223223
(IsCLMode ? 0 : driver::options::CLOption));
224224

225-
// Move the inputs to the end, separated via `--` from flags. This ensures
226-
// modifications done in the following steps apply in more cases (like setting
227-
// -x, which only affects inputs that come after it).
228-
if (!ArgList.hasArgNoClaim(driver::options::OPT__DASH_DASH)) {
229-
// Drop all the inputs and only add one for the current file.
230-
llvm::SmallVector<unsigned, 1> IndicesToDrop;
231-
for (auto *Input : ArgList.filtered(driver::options::OPT_INPUT))
232-
IndicesToDrop.push_back(Input->getIndex());
233-
llvm::sort(IndicesToDrop);
234-
llvm::for_each(llvm::reverse(IndicesToDrop),
235-
// +1 to account for the executable name in Cmd[0] that
236-
// doesn't exist in ArgList.
237-
[&Cmd](unsigned Idx) { Cmd.erase(Cmd.begin() + Idx + 1); });
238-
Cmd.push_back("--");
239-
Cmd.push_back(File.str());
225+
llvm::SmallVector<unsigned, 1> IndicesToDrop;
226+
// Having multiple architecture options (e.g. when building fat binaries)
227+
// results in multiple compiler jobs, which clangd cannot handle. In such
228+
// cases strip all the `-arch` options and fallback to default architecture.
229+
// As there are no signals to figure out which one user actually wants. They
230+
// can explicitly specify one through `CompileFlags.Add` if need be.
231+
unsigned ArchOptCount = 0;
232+
for (auto *Input : ArgList.filtered(driver::options::OPT_arch)) {
233+
++ArchOptCount;
234+
for (auto I = 0U; I <= Input->getNumValues(); ++I)
235+
IndicesToDrop.push_back(Input->getIndex() + I);
240236
}
237+
// If there is a single `-arch` option, keep it.
238+
if (ArchOptCount < 2)
239+
IndicesToDrop.clear();
240+
241+
// Strip all the inputs and `--`. We'll put the input for the requested file
242+
// explicitly at the end of the flags. This ensures modifications done in the
243+
// following steps apply in more cases (like setting -x, which only affects
244+
// inputs that come after it).
245+
for (auto *Input : ArgList.filtered(driver::options::OPT_INPUT))
246+
IndicesToDrop.push_back(Input->getIndex());
247+
// Anything after `--` is also treated as input, drop them as well.
248+
if (auto *DashDash =
249+
ArgList.getLastArgNoClaim(driver::options::OPT__DASH_DASH)) {
250+
Cmd.resize(DashDash->getIndex() + 1); // +1 to account for Cmd[0].
251+
}
252+
llvm::sort(IndicesToDrop);
253+
llvm::for_each(llvm::reverse(IndicesToDrop),
254+
// +1 to account for the executable name in Cmd[0] that
255+
// doesn't exist in ArgList.
256+
[&Cmd](unsigned Idx) { Cmd.erase(Cmd.begin() + Idx + 1); });
257+
// All the inputs are stripped, append the name for the requested file. Rest
258+
// of the modifications should respect `--`.
259+
Cmd.push_back("--");
260+
Cmd.push_back(File.str());
241261

242262
for (auto &Edit : Config::current().CompileFlags.Edits)
243263
Edit(Cmd);

clang-tools-extra/clangd/ConfigCompile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include "ConfigFragment.h"
2929
#include "ConfigProvider.h"
3030
#include "Diagnostics.h"
31-
#include "Features.h"
31+
#include "Feature.h"
3232
#include "TidyProvider.h"
3333
#include "support/Logger.h"
3434
#include "support/Path.h"

clang-tools-extra/clangd/Features.cpp renamed to clang-tools-extra/clangd/Feature.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
//===--- Features.cpp - Compile-time configuration ------------------------===//
1+
//===--- Feature.cpp - Compile-time configuration ------------------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "Features.h"
9+
#include "Feature.h"
1010
#include "clang/Basic/Version.h"
1111
#include "llvm/Support/Compiler.h"
1212
#include "llvm/Support/Host.h"

clang-tools-extra/clangd/Features.h renamed to clang-tools-extra/clangd/Feature.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
//===--- Features.h - Compile-time configuration ------------------*-C++-*-===//
1+
//===--- Feature.h - Compile-time configuration ------------------*-C++-*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
8+
// This file is not named "Features.h" because of a conflict with libstdc++:
9+
// https://github.com/clangd/clangd/issues/835
10+
//===----------------------------------------------------------------------===//
811

9-
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_FEATURES_H
10-
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_FEATURES_H
12+
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_FEATURE_H
13+
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_FEATURE_H
1114
#include <string>
1215

1316
// Export constants like CLANGD_BUILD_XPC

0 commit comments

Comments
 (0)