Skip to content

Commit 918f079

Browse files
committed
Merge remote-tracking branch 'origin/main' into lv-find-min-max-index
2 parents 87325fd + f4ba8e3 commit 918f079

File tree

481 files changed

+20824
-9537
lines changed

Some content is hidden

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

481 files changed

+20824
-9537
lines changed

clang-tools-extra/clang-tidy/objc/AssertEqualsCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ void AssertEqualsCheck::registerMatchers(MatchFinder *Finder) {
2525
for (const auto &[CurrName, _] : NameMap) {
2626
Finder->addMatcher(
2727
binaryOperator(anyOf(hasOperatorName("!="), hasOperatorName("==")),
28-
isExpandedFromMacro(CurrName),
28+
isExpandedFromMacro(std::string(CurrName)),
2929
anyOf(hasLHS(hasType(qualType(
3030
hasCanonicalType(asString("NSString *"))))),
3131
hasRHS(hasType(qualType(

clang-tools-extra/clangd/CompileCommands.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,7 @@ std::optional<std::string> detectSysroot() {
132132

133133
std::string detectStandardResourceDir() {
134134
static int StaticForMainAddr; // Just an address in this process.
135-
return CompilerInvocation::GetResourcesPath("clangd",
136-
(void *)&StaticForMainAddr);
135+
return GetResourcesPath("clangd", (void *)&StaticForMainAddr);
137136
}
138137

139138
// The path passed to argv[0] is important:

clang-tools-extra/clangd/Compiler.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "Compiler.h"
1010
#include "support/Logger.h"
1111
#include "clang/Basic/TargetInfo.h"
12+
#include "clang/Driver/CreateInvocationFromArgs.h"
1213
#include "clang/Frontend/CompilerInvocation.h"
1314
#include "clang/Lex/PreprocessorOptions.h"
1415
#include "clang/Serialization/PCHContainerOperations.h"

clang-tools-extra/clangd/SemanticSelection.cpp

Lines changed: 78 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@
1111
#include "Protocol.h"
1212
#include "Selection.h"
1313
#include "SourceCode.h"
14+
#include "support/Bracket.h"
15+
#include "support/DirectiveTree.h"
16+
#include "support/Token.h"
1417
#include "clang/AST/DeclBase.h"
1518
#include "clang/Basic/SourceLocation.h"
1619
#include "clang/Basic/SourceManager.h"
20+
#include "clang/Basic/TokenKinds.h"
1721
#include "clang/Tooling/Syntax/BuildTree.h"
1822
#include "clang/Tooling/Syntax/Nodes.h"
1923
#include "clang/Tooling/Syntax/TokenBufferTokenManager.h"
@@ -22,9 +26,6 @@
2226
#include "llvm/ADT/StringRef.h"
2327
#include "llvm/Support/Casting.h"
2428
#include "llvm/Support/Error.h"
25-
#include "support/Bracket.h"
26-
#include "support/DirectiveTree.h"
27-
#include "support/Token.h"
2829
#include <optional>
2930
#include <queue>
3031
#include <vector>
@@ -163,6 +164,69 @@ llvm::Expected<SelectionRange> getSemanticRanges(ParsedAST &AST, Position Pos) {
163164
return std::move(Head);
164165
}
165166

167+
class PragmaRegionFinder {
168+
// Record the token range of a region:
169+
//
170+
// #pragma region name[[
171+
// ...
172+
// ]]#pragma endregion
173+
std::vector<Token::Range> &Ranges;
174+
const TokenStream &Code;
175+
// Stack of starting token (the name of the region) indices for nested #pragma
176+
// region.
177+
std::vector<unsigned> Stack;
178+
179+
public:
180+
PragmaRegionFinder(std::vector<Token::Range> &Ranges, const TokenStream &Code)
181+
: Ranges(Ranges), Code(Code) {}
182+
183+
void walk(const DirectiveTree &T) {
184+
for (const auto &C : T.Chunks)
185+
std::visit(*this, C);
186+
}
187+
188+
void operator()(const DirectiveTree::Code &C) {}
189+
190+
void operator()(const DirectiveTree::Directive &D) {
191+
// Get the tokens that make up this directive.
192+
auto Tokens = Code.tokens(D.Tokens);
193+
if (Tokens.empty())
194+
return;
195+
const Token &HashToken = Tokens.front();
196+
assert(HashToken.Kind == tok::hash);
197+
const Token &Pragma = HashToken.nextNC();
198+
if (Pragma.text() != "pragma")
199+
return;
200+
const Token &Value = Pragma.nextNC();
201+
202+
// Handle "#pragma region name"
203+
if (Value.text() == "region") {
204+
// Find the last token at the same line.
205+
const Token *T = &Value.next();
206+
while (T < Tokens.end() && T->Line == Pragma.Line)
207+
T = &T->next();
208+
--T;
209+
Stack.push_back(T->OriginalIndex);
210+
return;
211+
}
212+
213+
// Handle "#pragma endregion"
214+
if (Value.text() == "endregion") {
215+
if (Stack.empty())
216+
return; // unmatched end region; ignore.
217+
218+
unsigned StartIdx = Stack.back();
219+
Stack.pop_back();
220+
Ranges.push_back(Token::Range{StartIdx, HashToken.OriginalIndex});
221+
}
222+
}
223+
224+
void operator()(const DirectiveTree::Conditional &C) {
225+
for (const auto &[_, SubTree] : C.Branches)
226+
walk(SubTree);
227+
}
228+
};
229+
166230
// FIXME(kirillbobyrev): Collect comments, PP conditional regions, includes and
167231
// other code regions (e.g. public/private/protected sections of classes,
168232
// control flow statement bodies).
@@ -286,6 +350,17 @@ getFoldingRanges(const std::string &Code, bool LineFoldingOnly) {
286350
}
287351
AddFoldingRange(Start, End, FoldingRange::COMMENT_KIND);
288352
}
353+
354+
// #pragma region
355+
std::vector<Token::Range> Ranges;
356+
PragmaRegionFinder(Ranges, OrigStream).walk(DirectiveStructure);
357+
auto Ts = OrigStream.tokens();
358+
for (const auto &R : Ranges) {
359+
auto End = StartPosition(Ts[R.End]);
360+
if (LineFoldingOnly)
361+
End.line--;
362+
AddFoldingRange(EndPosition(Ts[R.Begin]), End, FoldingRange::REGION_KIND);
363+
}
289364
return Result;
290365
}
291366

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,22 @@ TEST(FoldingRanges, PseudoParserWithoutLineFoldings) {
410410
Variable = 3;
411411
#
412412
)cpp",
413+
R"cpp(
414+
#pragma region R1[[
415+
416+
#pragma region R2[[
417+
constexpr int a = 2;
418+
]]#pragma endregion
419+
420+
]]#pragma endregion
421+
)cpp",
422+
R"cpp(
423+
#pragma region[[
424+
]]#pragma endregion
425+
426+
#pragma /*comment1*/ region /*comment2*/name[[
427+
]]#pragma endregion
428+
)cpp",
413429
};
414430
for (const char *Test : Tests) {
415431
auto T = Annotations(Test);
@@ -470,6 +486,12 @@ TEST(FoldingRanges, PseudoParserLineFoldingsOnly) {
470486
//[[ foo
471487
/* bar */]]
472488
)cpp",
489+
R"cpp(
490+
#pragma region abc[[
491+
constexpr int a = 2;
492+
]]
493+
#pragma endregion
494+
)cpp",
473495
// FIXME: Support folding template arguments.
474496
// R"cpp(
475497
// template <[[typename foo, class bar]]> struct baz {};

clang/docs/LibASTMatchersReference.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4222,7 +4222,7 @@ <h2 id="narrowing-matchers">Narrowing Matchers</h2>
42224222
</pre></td></tr>
42234223

42244224

4225-
<tr><td>Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt;</td><td class="name" onclick="toggle('isExpandedFromMacro0')"><a name="isExpandedFromMacro0Anchor">isExpandedFromMacro</a></td><td>StringRef MacroName</td></tr>
4225+
<tr><td>Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt;</td><td class="name" onclick="toggle('isExpandedFromMacro0')"><a name="isExpandedFromMacro0Anchor">isExpandedFromMacro</a></td><td>std::string MacroName</td></tr>
42264226
<tr><td colspan="4" class="doc" id="isExpandedFromMacro0"><pre>Matches statements that are (transitively) expanded from the named macro.
42274227
Does not match if only part of the statement is expanded from that macro or
42284228
if different parts of the statement are expanded from different
@@ -5643,7 +5643,7 @@ <h2 id="narrowing-matchers">Narrowing Matchers</h2>
56435643
</pre></td></tr>
56445644

56455645

5646-
<tr><td>Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('isExpandedFromMacro1')"><a name="isExpandedFromMacro1Anchor">isExpandedFromMacro</a></td><td>StringRef MacroName</td></tr>
5646+
<tr><td>Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('isExpandedFromMacro1')"><a name="isExpandedFromMacro1Anchor">isExpandedFromMacro</a></td><td>std::string MacroName</td></tr>
56475647
<tr><td colspan="4" class="doc" id="isExpandedFromMacro1"><pre>Matches statements that are (transitively) expanded from the named macro.
56485648
Does not match if only part of the statement is expanded from that macro or
56495649
if different parts of the statement are expanded from different
@@ -5843,7 +5843,7 @@ <h2 id="narrowing-matchers">Narrowing Matchers</h2>
58435843
</pre></td></tr>
58445844

58455845

5846-
<tr><td>Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>&gt;</td><td class="name" onclick="toggle('isExpandedFromMacro2')"><a name="isExpandedFromMacro2Anchor">isExpandedFromMacro</a></td><td>StringRef MacroName</td></tr>
5846+
<tr><td>Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html">TypeLoc</a>&gt;</td><td class="name" onclick="toggle('isExpandedFromMacro2')"><a name="isExpandedFromMacro2Anchor">isExpandedFromMacro</a></td><td>std::string MacroName</td></tr>
58475847
<tr><td colspan="4" class="doc" id="isExpandedFromMacro2"><pre>Matches statements that are (transitively) expanded from the named macro.
58485848
Does not match if only part of the statement is expanded from that macro or
58495849
if different parts of the statement are expanded from different

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ Potentially Breaking Changes
8484
- Downstream projects that previously linked only against ``clangDriver`` may
8585
now (also) need to link against the new ``clangOptions`` library, since
8686
options-related code has been moved out of the Driver into a separate library.
87+
- The ``clangFrontend`` library no longer depends on ``clangDriver``, which may
88+
break downstream projects that relied on this transitive dependency.
8789

8890
C/C++ Language Potentially Breaking Changes
8991
-------------------------------------------
@@ -557,6 +559,7 @@ Bug Fixes to C++ Support
557559
- Diagnose unresolved overload sets in non-dependent compound requirements. (#GH51246) (#GH97753)
558560
- Fix a crash when extracting unavailable member type from alias in template deduction. (#GH165560)
559561
- Fix incorrect diagnostics for lambdas with init-captures inside braced initializers. (#GH163498)
562+
- Fixed spurious diagnoses of certain nested lambda expressions. (#GH149121) (#GH156579)
560563

561564
Bug Fixes to AST Handling
562565
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/AST/ASTImporter.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,16 @@ class TypeSourceInfo;
190190
llvm::SmallDenseMap<Decl *, int, 32> Aux;
191191
};
192192

193+
class FunctionDeclImportCycleDetector {
194+
public:
195+
auto makeScopedCycleDetection(const FunctionDecl *D);
196+
197+
bool isCycle(const FunctionDecl *D) const;
198+
199+
private:
200+
llvm::DenseSet<const FunctionDecl *> FunctionDeclsWithImportInProgress;
201+
};
202+
193203
private:
194204
std::shared_ptr<ASTImporterSharedState> SharedState = nullptr;
195205

@@ -254,6 +264,12 @@ class TypeSourceInfo;
254264
/// Declaration (from, to) pairs that are known not to be equivalent
255265
/// (which we have already complained about).
256266
NonEquivalentDeclSet NonEquivalentDecls;
267+
/// A FunctionDecl can have properties that have a reference to the
268+
/// function itself and are imported before the function is created. This
269+
/// can come for example from auto return type or when template parameters
270+
/// are used in the return type or parameters. This member is used to detect
271+
/// cyclic import of FunctionDecl objects to avoid infinite recursion.
272+
FunctionDeclImportCycleDetector FindFunctionDeclImportCycle;
257273

258274
using FoundDeclsTy = SmallVector<NamedDecl *, 2>;
259275
FoundDeclsTy findDeclsInToCtx(DeclContext *DC, DeclarationName Name);

0 commit comments

Comments
 (0)