Skip to content

Commit 9b73b3a

Browse files
committed
Merge from 'main' to 'sycl-web' (#5)
CONFLICT (content): Merge conflict in clang/lib/Sema/SemaDecl.cpp
2 parents 3b790e9 + d238b60 commit 9b73b3a

File tree

695 files changed

+18326
-7343
lines changed

Some content is hidden

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

695 files changed

+18326
-7343
lines changed

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

+3-3
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

+6-6
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

+19
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

+4
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

+1-1
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

+1-1
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/CompileCommands.cpp

+35-15
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

+1-1
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

+2-2
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

+6-3
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

clang-tools-extra/clangd/Hover.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "support/Markup.h"
2020
#include "clang/AST/ASTContext.h"
2121
#include "clang/AST/ASTTypeTraits.h"
22+
#include "clang/AST/Attr.h"
2223
#include "clang/AST/Decl.h"
2324
#include "clang/AST/DeclBase.h"
2425
#include "clang/AST/DeclCXX.h"
@@ -720,6 +721,20 @@ llvm::Optional<HoverInfo> getHoverContents(const Expr *E, ParsedAST &AST,
720721
return llvm::None;
721722
}
722723

724+
// Generates hover info for attributes.
725+
llvm::Optional<HoverInfo> getHoverContents(const Attr *A, ParsedAST &AST) {
726+
HoverInfo HI;
727+
HI.Name = A->getSpelling();
728+
if (A->hasScope())
729+
HI.LocalScope = A->getScopeName()->getName().str();
730+
{
731+
llvm::raw_string_ostream OS(HI.Definition);
732+
A->printPretty(OS, AST.getASTContext().getPrintingPolicy());
733+
}
734+
// FIXME: attributes have documentation, can we get at that?
735+
return HI;
736+
}
737+
723738
bool isParagraphBreak(llvm::StringRef Rest) {
724739
return Rest.ltrim(" \t").startswith("\n");
725740
}
@@ -960,6 +975,8 @@ llvm::Optional<HoverInfo> getHover(ParsedAST &AST, Position Pos,
960975
maybeAddCalleeArgInfo(N, *HI, PP);
961976
} else if (const Expr *E = N->ASTNode.get<Expr>()) {
962977
HI = getHoverContents(E, AST, PP, Index);
978+
} else if (const Attr *A = N->ASTNode.get<Attr>()) {
979+
HI = getHoverContents(A, AST);
963980
}
964981
// FIXME: support hovers for other nodes?
965982
// - built-in types

clang-tools-extra/clangd/ParsedAST.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
#include "Compiler.h"
1515
#include "Config.h"
1616
#include "Diagnostics.h"
17+
#include "Feature.h"
1718
#include "FeatureModule.h"
18-
#include "Features.h"
1919
#include "Headers.h"
2020
#include "HeuristicResolver.h"
2121
#include "IncludeFixer.h"

clang-tools-extra/clangd/Selection.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "Selection.h"
10+
#include "AST.h"
1011
#include "SourceCode.h"
1112
#include "support/Logger.h"
1213
#include "support/Trace.h"
@@ -490,7 +491,6 @@ class SelectionVisitor : public RecursiveASTVisitor<SelectionVisitor> {
490491
// Two categories of nodes are not "well-behaved":
491492
// - those without source range information, we don't record those
492493
// - those that can't be stored in DynTypedNode.
493-
// We're missing some interesting things like Attr due to the latter.
494494
bool TraverseDecl(Decl *X) {
495495
if (X && isa<TranslationUnitDecl>(X))
496496
return Base::TraverseDecl(X); // Already pushed by constructor.
@@ -517,6 +517,9 @@ class SelectionVisitor : public RecursiveASTVisitor<SelectionVisitor> {
517517
bool TraverseCXXBaseSpecifier(const CXXBaseSpecifier &X) {
518518
return traverseNode(&X, [&] { return Base::TraverseCXXBaseSpecifier(X); });
519519
}
520+
bool TraverseAttr(Attr *X) {
521+
return traverseNode(X, [&] { return Base::TraverseAttr(X); });
522+
}
520523
// Stmt is the same, but this form allows the data recursion optimization.
521524
bool dataTraverseStmtPre(Stmt *X) {
522525
if (!X || isImplicit(X))
@@ -651,6 +654,11 @@ class SelectionVisitor : public RecursiveASTVisitor<SelectionVisitor> {
651654
if (auto AT = TL->getAs<AttributedTypeLoc>())
652655
S = AT.getModifiedLoc().getSourceRange();
653656
}
657+
// SourceRange often doesn't manage to accurately cover attributes.
658+
// Fortunately, attributes are rare.
659+
if (llvm::any_of(getAttributes(N),
660+
[](const Attr *A) { return !A->isImplicit(); }))
661+
return false;
654662
if (!SelChecker.mayHit(S)) {
655663
dlog("{1}skip: {0}", printNodeToString(N, PrintPolicy), indent());
656664
dlog("{1}skipped range = {0}", S.printToString(SM), indent(1));

clang-tools-extra/clangd/Transport.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +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"
21+
#include "Feature.h"
2222
#include "llvm/ADT/StringRef.h"
2323
#include "llvm/Support/JSON.h"
2424
#include "llvm/Support/raw_ostream.h"

clang-tools-extra/clangd/XRefs.cpp

+14-14
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,12 @@ getDeclAtPositionWithRelations(ParsedAST &AST, SourceLocation Pos,
183183
if (const SelectionTree::Node *N = ST.commonAncestor()) {
184184
if (NodeKind)
185185
*NodeKind = N->ASTNode.getNodeKind();
186+
// Attributes don't target decls, look at the
187+
// thing it's attached to.
188+
// We still report the original NodeKind!
189+
// This makes the `override` hack work.
190+
if (N->ASTNode.get<Attr>() && N->Parent)
191+
N = N->Parent;
186192
llvm::copy_if(allTargetDecls(N->ASTNode, AST.getHeuristicResolver()),
187193
std::back_inserter(Result),
188194
[&](auto &Entry) { return !(Entry.second & ~Relations); });
@@ -343,7 +349,7 @@ std::vector<LocatedSymbol> findImplementors(llvm::DenseSet<SymbolID> IDs,
343349
std::vector<LocatedSymbol>
344350
locateASTReferent(SourceLocation CurLoc, const syntax::Token *TouchedIdentifier,
345351
ParsedAST &AST, llvm::StringRef MainFilePath,
346-
const SymbolIndex *Index, ASTNodeKind *NodeKind) {
352+
const SymbolIndex *Index, ASTNodeKind &NodeKind) {
347353
const SourceManager &SM = AST.getSourceManager();
348354
// Results follow the order of Symbols.Decls.
349355
std::vector<LocatedSymbol> Result;
@@ -376,7 +382,7 @@ locateASTReferent(SourceLocation CurLoc, const syntax::Token *TouchedIdentifier,
376382
DeclRelationSet Relations =
377383
DeclRelation::TemplatePattern | DeclRelation::Alias;
378384
auto Candidates =
379-
getDeclAtPositionWithRelations(AST, CurLoc, Relations, NodeKind);
385+
getDeclAtPositionWithRelations(AST, CurLoc, Relations, &NodeKind);
380386
llvm::DenseSet<SymbolID> VirtualMethods;
381387
for (const auto &E : Candidates) {
382388
const NamedDecl *D = E.first;
@@ -392,13 +398,8 @@ locateASTReferent(SourceLocation CurLoc, const syntax::Token *TouchedIdentifier,
392398
}
393399
}
394400
// Special case: void foo() ^override: jump to the overridden method.
395-
const InheritableAttr *Attr = D->getAttr<OverrideAttr>();
396-
if (!Attr)
397-
Attr = D->getAttr<FinalAttr>();
398-
if (Attr && TouchedIdentifier &&
399-
SM.getSpellingLoc(Attr->getLocation()) ==
400-
TouchedIdentifier->location()) {
401-
LocateASTReferentMetric.record(1, "method-to-base");
401+
if (NodeKind.isSame(ASTNodeKind::getFromNodeKind<OverrideAttr>()) ||
402+
NodeKind.isSame(ASTNodeKind::getFromNodeKind<FinalAttr>())) {
402403
// We may be overridding multiple methods - offer them all.
403404
for (const NamedDecl *ND : CMD->overridden_methods())
404405
AddResultDecl(ND);
@@ -800,7 +801,7 @@ std::vector<LocatedSymbol> locateSymbolAt(ParsedAST &AST, Position Pos,
800801

801802
ASTNodeKind NodeKind;
802803
auto ASTResults = locateASTReferent(*CurLoc, TouchedIdentifier, AST,
803-
*MainFilePath, Index, &NodeKind);
804+
*MainFilePath, Index, NodeKind);
804805
if (!ASTResults.empty())
805806
return ASTResults;
806807

@@ -816,9 +817,8 @@ std::vector<LocatedSymbol> locateSymbolAt(ParsedAST &AST, Position Pos,
816817
Word->Text);
817818
return {*std::move(Macro)};
818819
}
819-
ASTResults =
820-
locateASTReferent(NearbyIdent->location(), NearbyIdent, AST,
821-
*MainFilePath, Index, /*NodeKind=*/nullptr);
820+
ASTResults = locateASTReferent(NearbyIdent->location(), NearbyIdent, AST,
821+
*MainFilePath, Index, NodeKind);
822822
if (!ASTResults.empty()) {
823823
log("Found definition heuristically using nearby identifier {0}",
824824
NearbyIdent->text(SM));
@@ -1987,4 +1987,4 @@ llvm::DenseSet<const Decl *> getNonLocalDeclRefs(ParsedAST &AST,
19871987
}
19881988

19891989
} // namespace clangd
1990-
} // namespace clang
1990+
} // namespace clang

clang-tools-extra/clangd/index/remote/Client.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <grpc++/grpc++.h>
1010

1111
#include "Client.h"
12-
#include "Features.h"
12+
#include "Feature.h"
1313
#include "Service.grpc.pb.h"
1414
#include "index/Index.h"
1515
#include "marshalling/Marshalling.h"

0 commit comments

Comments
 (0)