Skip to content

Commit 5c7b28f

Browse files
committed
Merge from 'master' to 'sycl-web' (#1)
2 parents 1dd9d9b + 8b16e45 commit 5c7b28f

File tree

1,085 files changed

+22050
-5633
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,085 files changed

+22050
-5633
lines changed

clang-tools-extra/clangd/Selection.cpp

+16-4
Original file line numberDiff line numberDiff line change
@@ -220,14 +220,26 @@ class SelectionTester {
220220
SelFirst, AllSpelledTokens.end(), [&](const syntax::Token &Tok) {
221221
return SM.getFileOffset(Tok.location()) < SelEnd;
222222
});
223+
auto Sel = llvm::makeArrayRef(SelFirst, SelLimit);
224+
// Find which of these are preprocessed to nothing and should be ignored.
225+
std::vector<bool> PPIgnored(Sel.size(), false);
226+
for (const syntax::TokenBuffer::Expansion &X :
227+
Buf.expansionsOverlapping(Sel)) {
228+
if (X.Expanded.empty()) {
229+
for (const syntax::Token &Tok : X.Spelled) {
230+
if (&Tok >= SelFirst && &Tok < SelLimit)
231+
PPIgnored[&Tok - SelFirst] = true;
232+
}
233+
}
234+
}
223235
// Precompute selectedness and offset for selected spelled tokens.
224-
for (const syntax::Token *T = SelFirst; T < SelLimit; ++T) {
225-
if (shouldIgnore(*T))
236+
for (unsigned I = 0; I < Sel.size(); ++I) {
237+
if (shouldIgnore(Sel[I]) || PPIgnored[I])
226238
continue;
227239
SpelledTokens.emplace_back();
228240
Tok &S = SpelledTokens.back();
229-
S.Offset = SM.getFileOffset(T->location());
230-
if (S.Offset >= SelBegin && S.Offset + T->length() <= SelEnd)
241+
S.Offset = SM.getFileOffset(Sel[I].location());
242+
if (S.Offset >= SelBegin && S.Offset + Sel[I].length() <= SelEnd)
231243
S.Selected = SelectionTree::Complete;
232244
else
233245
S.Selected = SelectionTree::Partial;

clang-tools-extra/clangd/XRefs.cpp

+18-22
Original file line numberDiff line numberDiff line change
@@ -1183,23 +1183,24 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const LocatedSymbol &S) {
11831183

11841184
// FIXME(nridge): Reduce duplication between this function and declToSym().
11851185
static llvm::Optional<TypeHierarchyItem>
1186-
declToTypeHierarchyItem(ASTContext &Ctx, const NamedDecl &ND,
1187-
const syntax::TokenBuffer &TB) {
1186+
declToTypeHierarchyItem(ASTContext &Ctx, const NamedDecl &ND) {
11881187
auto &SM = Ctx.getSourceManager();
11891188
SourceLocation NameLoc = nameLocation(ND, Ctx.getSourceManager());
1189+
SourceLocation BeginLoc = SM.getSpellingLoc(SM.getFileLoc(ND.getBeginLoc()));
1190+
SourceLocation EndLoc = SM.getSpellingLoc(SM.getFileLoc(ND.getEndLoc()));
1191+
const auto DeclRange =
1192+
toHalfOpenFileRange(SM, Ctx.getLangOpts(), {BeginLoc, EndLoc});
1193+
if (!DeclRange)
1194+
return llvm::None;
11901195
auto FilePath =
11911196
getCanonicalPath(SM.getFileEntryForID(SM.getFileID(NameLoc)), SM);
11921197
auto TUPath = getCanonicalPath(SM.getFileEntryForID(SM.getMainFileID()), SM);
11931198
if (!FilePath || !TUPath)
11941199
return llvm::None; // Not useful without a uri.
11951200

1196-
auto DeclToks = TB.spelledForExpanded(TB.expandedTokens(ND.getSourceRange()));
1197-
if (!DeclToks || DeclToks->empty())
1198-
return llvm::None;
1199-
1200-
auto NameToks = TB.spelledForExpanded(TB.expandedTokens(NameLoc));
1201-
if (!NameToks || NameToks->empty())
1202-
return llvm::None;
1201+
Position NameBegin = sourceLocToPosition(SM, NameLoc);
1202+
Position NameEnd = sourceLocToPosition(
1203+
SM, Lexer::getLocForEndOfToken(NameLoc, 0, SM, Ctx.getLangOpts()));
12031204

12041205
index::SymbolInfo SymInfo = index::getSymbolInfo(&ND);
12051206
// FIXME: this is not classifying constructors, destructors and operators
@@ -1210,12 +1211,9 @@ declToTypeHierarchyItem(ASTContext &Ctx, const NamedDecl &ND,
12101211
THI.name = printName(Ctx, ND);
12111212
THI.kind = SK;
12121213
THI.deprecated = ND.isDeprecated();
1213-
THI.range = halfOpenToRange(
1214-
SM, syntax::Token::range(SM, DeclToks->front(), DeclToks->back())
1215-
.toCharRange(SM));
1216-
THI.selectionRange = halfOpenToRange(
1217-
SM, syntax::Token::range(SM, NameToks->front(), NameToks->back())
1218-
.toCharRange(SM));
1214+
THI.range = Range{sourceLocToPosition(SM, DeclRange->getBegin()),
1215+
sourceLocToPosition(SM, DeclRange->getEnd())};
1216+
THI.selectionRange = Range{NameBegin, NameEnd};
12191217
if (!THI.range.contains(THI.selectionRange)) {
12201218
// 'selectionRange' must be contained in 'range', so in cases where clang
12211219
// reports unrelated ranges we need to reconcile somehow.
@@ -1282,8 +1280,7 @@ using RecursionProtectionSet = llvm::SmallSet<const CXXRecordDecl *, 4>;
12821280

12831281
static void fillSuperTypes(const CXXRecordDecl &CXXRD, ASTContext &ASTCtx,
12841282
std::vector<TypeHierarchyItem> &SuperTypes,
1285-
RecursionProtectionSet &RPSet,
1286-
const syntax::TokenBuffer &TB) {
1283+
RecursionProtectionSet &RPSet) {
12871284
// typeParents() will replace dependent template specializations
12881285
// with their class template, so to avoid infinite recursion for
12891286
// certain types of hierarchies, keep the templates encountered
@@ -1298,9 +1295,9 @@ static void fillSuperTypes(const CXXRecordDecl &CXXRD, ASTContext &ASTCtx,
12981295

12991296
for (const CXXRecordDecl *ParentDecl : typeParents(&CXXRD)) {
13001297
if (Optional<TypeHierarchyItem> ParentSym =
1301-
declToTypeHierarchyItem(ASTCtx, *ParentDecl, TB)) {
1298+
declToTypeHierarchyItem(ASTCtx, *ParentDecl)) {
13021299
ParentSym->parents.emplace();
1303-
fillSuperTypes(*ParentDecl, ASTCtx, *ParentSym->parents, RPSet, TB);
1300+
fillSuperTypes(*ParentDecl, ASTCtx, *ParentSym->parents, RPSet);
13041301
SuperTypes.emplace_back(std::move(*ParentSym));
13051302
}
13061303
}
@@ -1404,7 +1401,7 @@ getTypeHierarchy(ParsedAST &AST, Position Pos, int ResolveLevels,
14041401
return llvm::None;
14051402

14061403
Optional<TypeHierarchyItem> Result =
1407-
declToTypeHierarchyItem(AST.getASTContext(), *CXXRD, AST.getTokens());
1404+
declToTypeHierarchyItem(AST.getASTContext(), *CXXRD);
14081405
if (!Result)
14091406
return Result;
14101407

@@ -1413,8 +1410,7 @@ getTypeHierarchy(ParsedAST &AST, Position Pos, int ResolveLevels,
14131410
Result->parents.emplace();
14141411

14151412
RecursionProtectionSet RPSet;
1416-
fillSuperTypes(*CXXRD, AST.getASTContext(), *Result->parents, RPSet,
1417-
AST.getTokens());
1413+
fillSuperTypes(*CXXRD, AST.getASTContext(), *Result->parents, RPSet);
14181414
}
14191415

14201416
if ((Direction == TypeHierarchyDirection::Children ||

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

+22-3
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,29 @@ TEST(SelectionTest, CommonAncestor) {
177177
{
178178
R"cpp(
179179
void foo();
180-
#define CALL_FUNCTION(X) X^()^
180+
#^define CALL_FUNCTION(X) X(^)
181181
void bar() { CALL_FUNCTION(foo); }
182182
)cpp",
183183
nullptr,
184184
},
185+
{
186+
R"cpp(
187+
void foo();
188+
#define CALL_FUNCTION(X) X()
189+
void bar() { CALL_FUNCTION(foo^)^; }
190+
)cpp",
191+
nullptr,
192+
},
193+
{
194+
R"cpp(
195+
namespace ns {
196+
#if 0
197+
void fo^o() {}
198+
#endif
199+
}
200+
)cpp",
201+
nullptr,
202+
},
185203
{
186204
R"cpp(
187205
struct S { S(const char*); };
@@ -388,7 +406,8 @@ TEST(SelectionTest, CommonAncestor) {
388406
void test(S2 s2) {
389407
s2[[-^>]]f();
390408
}
391-
)cpp", "DeclRefExpr"} // DeclRefExpr to the "operator->" method.
409+
)cpp",
410+
"DeclRefExpr"} // DeclRefExpr to the "operator->" method.
392411
};
393412
for (const Case &C : Cases) {
394413
trace::TestTracer Tracer;
@@ -538,7 +557,7 @@ TEST(SelectionTest, IncludedFile) {
538557
auto AST = TU.build();
539558
auto T = makeSelectionTree(Case, AST);
540559

541-
EXPECT_EQ("WhileStmt", T.commonAncestor()->kind());
560+
EXPECT_EQ(nullptr, T.commonAncestor());
542561
}
543562

544563
TEST(SelectionTest, MacroArgExpansion) {

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

+27
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,33 @@ TEST(TypeHierarchy, DeriveFromTemplate) {
523523
WithKind(SymbolKind::Struct), Children()))));
524524
}
525525

526+
TEST(TypeHierarchy, Preamble) {
527+
Annotations SourceAnnotations(R"cpp(
528+
struct Ch^ild : Parent {
529+
int b;
530+
};)cpp");
531+
532+
Annotations HeaderInPreambleAnnotations(R"cpp(
533+
struct [[Parent]] {
534+
int a;
535+
};)cpp");
536+
537+
TestTU TU = TestTU::withCode(SourceAnnotations.code());
538+
TU.HeaderCode = HeaderInPreambleAnnotations.code().str();
539+
auto AST = TU.build();
540+
541+
llvm::Optional<TypeHierarchyItem> Result = getTypeHierarchy(
542+
AST, SourceAnnotations.point(), 1, TypeHierarchyDirection::Parents);
543+
544+
ASSERT_TRUE(Result);
545+
EXPECT_THAT(
546+
*Result,
547+
AllOf(WithName("Child"),
548+
Parents(AllOf(WithName("Parent"),
549+
SelectionRangeIs(HeaderInPreambleAnnotations.range()),
550+
Parents()))));
551+
}
552+
526553
SymbolID findSymbolIDByName(SymbolIndex *Index, llvm::StringRef Name,
527554
llvm::StringRef TemplateArgs = "") {
528555
SymbolID Result;

clang/docs/ClangFormatStyleOptions.rst

+37
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,43 @@ the configuration (without a prefix: ``Auto``).
794794
int aaaaaaaaaaaaaaaaaaaa,
795795
int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
796796

797+
**BitFieldColonSpacing** (``BitFieldColonSpacingStyle``)
798+
The BitFieldColonSpacingStyle to use for bitfields.
799+
800+
Possible values:
801+
802+
* ``BFCS_Both`` (in configuration: ``Both``)
803+
Add one space on each side of the ``:``
804+
805+
.. code-block:: c++
806+
807+
unsigned bf : 2;
808+
809+
* ``BFCS_None`` (in configuration: ``None``)
810+
Add no space around the ``:`` (except when needed for
811+
``AlignConsecutiveBitFields``).
812+
813+
.. code-block:: c++
814+
815+
unsigned bf:2;
816+
817+
* ``BFCS_Before`` (in configuration: ``Before``)
818+
Add space before the ``:`` only
819+
820+
.. code-block:: c++
821+
822+
unsigned bf :2;
823+
824+
* ``BFCS_After`` (in configuration: ``After``)
825+
Add space after the ``:`` only (space may be added before if
826+
needed for ``AlignConsecutiveBitFields``).
827+
828+
.. code-block:: c++
829+
830+
unsigned bf: 2;
831+
832+
833+
797834
**BraceWrapping** (``BraceWrappingFlags``)
798835
Control of individual brace wrapping cases.
799836

clang/docs/ReleaseNotes.rst

+27-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,33 @@ AST Matchers
149149
clang-format
150150
------------
151151

152-
- ...
152+
- Option ``BitFieldColonSpacing`` has been added that decides how
153+
space should be added around identifier, colon and bit-width in
154+
bitfield definitions.
155+
156+
.. code-block:: c++
157+
158+
// Both (default)
159+
struct F {
160+
unsigned dscp : 6;
161+
unsigned ecn : 2; // AlignConsecutiveBitFields=true
162+
};
163+
// None
164+
struct F {
165+
unsigned dscp:6;
166+
unsigned ecn :2;
167+
};
168+
// Before
169+
struct F {
170+
unsigned dscp :6;
171+
unsigned ecn :2;
172+
};
173+
// After
174+
struct F {
175+
unsigned dscp: 6;
176+
unsigned ecn : 2;
177+
};
178+
153179

154180
libclang
155181
--------

clang/include/clang/AST/DeclarationName.h

+10
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,16 @@ struct DenseMapInfo<clang::DeclarationName> {
857857
}
858858
};
859859

860+
template <> struct PointerLikeTypeTraits<clang::DeclarationName> {
861+
static inline void *getAsVoidPointer(clang::DeclarationName P) {
862+
return P.getAsOpaquePtr();
863+
}
864+
static inline clang::DeclarationName getFromVoidPointer(void *P) {
865+
return clang::DeclarationName::getFromOpaquePtr(P);
866+
}
867+
static constexpr int NumLowBitsAvailable = 0;
868+
};
869+
860870
} // namespace llvm
861871

862872
// The definition of AssumedTemplateStorage is factored out of TemplateName to

clang/include/clang/AST/Redeclarable.h

+15
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ template <typename decl_type> class CanonicalDeclPtr {
370370

371371
private:
372372
friend struct llvm::DenseMapInfo<CanonicalDeclPtr<decl_type>>;
373+
friend struct llvm::PointerLikeTypeTraits<CanonicalDeclPtr<decl_type>>;
373374

374375
decl_type *Ptr = nullptr;
375376
};
@@ -407,6 +408,20 @@ struct DenseMapInfo<clang::CanonicalDeclPtr<decl_type>> {
407408
}
408409
};
409410

411+
template <typename decl_type>
412+
struct PointerLikeTypeTraits<clang::CanonicalDeclPtr<decl_type>> {
413+
static inline void *getAsVoidPointer(clang::CanonicalDeclPtr<decl_type> P) {
414+
return P.Ptr;
415+
}
416+
static inline clang::CanonicalDeclPtr<decl_type> getFromVoidPointer(void *P) {
417+
clang::CanonicalDeclPtr<decl_type> C;
418+
C.Ptr = PointerLikeTypeTraits<decl_type *>::getFromVoidPtr(P);
419+
return C;
420+
}
421+
static constexpr int NumLowBitsAvailable =
422+
PointerLikeTypeTraits<decl_type *>::NumLowBitsAvailable;
423+
};
424+
410425
} // namespace llvm
411426

412427
#endif // LLVM_CLANG_AST_REDECLARABLE_H

clang/include/clang/Basic/DiagnosticDriverKinds.td

+3
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,9 @@ def warn_drv_msvc_not_found : Warning<
480480
"try running Clang from a developer command prompt">,
481481
InGroup<DiagGroup<"msvc-not-found">>;
482482

483+
def warn_drv_use_ld_non_word : Warning<
484+
"'-fuse-ld=' taking a path is deprecated. Use '--ld-path=' instead">;
485+
483486
def warn_drv_fine_grained_bitfield_accesses_ignored : Warning<
484487
"option '-ffine-grained-bitfield-accesses' cannot be enabled together with a sanitizer; flag ignored">,
485488
InGroup<OptionIgnored>;

clang/include/clang/Basic/DiagnosticSemaKinds.td

+2-1
Original file line numberDiff line numberDiff line change
@@ -2853,7 +2853,8 @@ def err_attribute_bad_sve_vector_size : Error<
28532853
"invalid SVE vector size '%0', must match value set by "
28542854
"'-msve-vector-bits' ('%1')">;
28552855
def err_attribute_arm_feature_sve_bits_unsupported : Error<
2856-
"%0 is not supported when '-msve-vector-bits=<bits>' is not specified">;
2856+
"%0 is only supported when '-msve-vector-bits=<bits>' is specified with a "
2857+
"value of 128, 256, 512, 1024 or 2048.">;
28572858
def err_attribute_requires_positive_integer : Error<
28582859
"%0 attribute requires a %select{positive|non-negative}1 "
28592860
"integral compile time constant expression">;

clang/include/clang/Driver/Options.td

+5-2
Original file line numberDiff line numberDiff line change
@@ -2406,8 +2406,9 @@ foreach i = {8-15,18} in
24062406

24072407
def msve_vector_bits_EQ : Joined<["-"], "msve-vector-bits=">,
24082408
Group<m_aarch64_Features_Group>, Flags<[DriverOption,CC1Option]>,
2409-
HelpText<"Set the size of fixed-length SVE vectors in bits.">,
2410-
Values<"128,256,512,1024,2048">;
2409+
HelpText<"Specify the size in bits of an SVE vector register. Defaults to the"
2410+
" vector length agnostic value of \"scalable\". (AArch64 only)">,
2411+
Values<"128,256,512,1024,2048,scalable">;
24112412

24122413
def msign_return_address_EQ : Joined<["-"], "msign-return-address=">,
24132414
Flags<[CC1Option]>, Group<m_Group>, Values<"none,all,non-leaf">,
@@ -3341,6 +3342,7 @@ defm : BooleanFFlag<"keep-inline-functions">, Group<clang_ignored_gcc_optimizati
33413342
def fprofile_dir : Joined<["-"], "fprofile-dir=">, Group<f_Group>;
33423343

33433344
def fuse_ld_EQ : Joined<["-"], "fuse-ld=">, Group<f_Group>, Flags<[CoreOption]>;
3345+
def ld_path_EQ : Joined<["--"], "ld-path=">;
33443346

33453347
defm align_labels : BooleanFFlag<"align-labels">, Group<clang_ignored_gcc_optimization_f_Group>;
33463348
def falign_labels_EQ : Joined<["-"], "falign-labels=">, Group<clang_ignored_gcc_optimization_f_Group>;
@@ -4757,6 +4759,7 @@ def _SLASH_FI : CLJoinedOrSeparate<"FI">,
47574759
def _SLASH_Fe : CLJoined<"Fe">,
47584760
HelpText<"Set output executable file name">,
47594761
MetaVarName<"<file or dir/>">;
4762+
def _SLASH_Fe_COLON : CLJoined<"Fe:">, Alias<_SLASH_Fe>;
47604763
def _SLASH_Fi : CLCompileJoined<"Fi">,
47614764
HelpText<"Set preprocess output file name (with /P)">,
47624765
MetaVarName<"<file>">;

0 commit comments

Comments
 (0)