Skip to content

Commit 20eb2a9

Browse files
authored
Merge pull request #981
LLVM pulldown
2 parents 0aabe7e + cd51318 commit 20eb2a9

File tree

2,318 files changed

+246018
-6706
lines changed

Some content is hidden

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

2,318 files changed

+246018
-6706
lines changed

clang-tools-extra/clang-query/Query.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,24 @@ bool MatchQuery::run(llvm::raw_ostream &OS, QuerySession &QS) const {
101101
Finder.matchAST(AST->getASTContext());
102102

103103
if (QS.PrintMatcher) {
104-
std::string prefixText = "Matcher: ";
105-
OS << "\n " << prefixText << Source << "\n";
106-
OS << " " << std::string(prefixText.size() + Source.size(), '=') << '\n';
104+
SmallVector<StringRef, 4> Lines;
105+
Source.split(Lines, "\n");
106+
auto FirstLine = Lines[0];
107+
Lines.erase(Lines.begin(), Lines.begin() + 1);
108+
while (!Lines.empty() && Lines.back().empty()) {
109+
Lines.resize(Lines.size() - 1);
110+
}
111+
unsigned MaxLength = FirstLine.size();
112+
std::string PrefixText = "Matcher: ";
113+
OS << "\n " << PrefixText << FirstLine;
114+
115+
for (auto Line : Lines) {
116+
OS << "\n" << std::string(PrefixText.size() + 2, ' ') << Line;
117+
MaxLength = std::max<int>(MaxLength, Line.rtrim().size());
118+
}
119+
120+
OS << "\n"
121+
<< " " << std::string(PrefixText.size() + MaxLength, '=') << "\n\n";
107122
}
108123

109124
for (auto MI = Matches.begin(), ME = Matches.end(); MI != ME; ++MI) {

clang-tools-extra/clang-query/Query.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ struct Query : llvm::RefCountedBase<Query> {
4444
/// \return false if an error occurs, otherwise return true.
4545
virtual bool run(llvm::raw_ostream &OS, QuerySession &QS) const = 0;
4646

47+
StringRef RemainingContent;
4748
const QueryKind Kind;
4849
};
4950

clang-tools-extra/clang-query/QueryParser.cpp

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,23 @@ namespace query {
2626
// is found before End, return StringRef(). Begin is adjusted to exclude the
2727
// lexed region.
2828
StringRef QueryParser::lexWord() {
29-
Line = Line.ltrim();
29+
Line = Line.drop_while([](char c) {
30+
// Don't trim newlines.
31+
return StringRef(" \t\v\f\r").contains(c);
32+
});
3033

3134
if (Line.empty())
3235
// Even though the Line is empty, it contains a pointer and
3336
// a (zero) length. The pointer is used in the LexOrCompleteWord
3437
// code completion.
3538
return Line;
3639

37-
if (Line.front() == '#') {
38-
Line = {};
39-
return StringRef();
40-
}
40+
StringRef Word;
41+
if (Line.front() == '#')
42+
Word = Line.substr(0, 1);
43+
else
44+
Word = Line.take_until(isWhitespace);
4145

42-
StringRef Word = Line.take_until(isWhitespace);
4346
Line = Line.drop_front(Word.size());
4447
return Word;
4548
}
@@ -125,9 +128,25 @@ template <typename QueryType> QueryRef QueryParser::parseSetOutputKind() {
125128
}
126129

127130
QueryRef QueryParser::endQuery(QueryRef Q) {
128-
const StringRef Extra = Line;
129-
if (!lexWord().empty())
130-
return new InvalidQuery("unexpected extra input: '" + Extra + "'");
131+
StringRef Extra = Line;
132+
StringRef ExtraTrimmed = Extra.drop_while(
133+
[](char c) { return StringRef(" \t\v\f\r").contains(c); });
134+
135+
if ((!ExtraTrimmed.empty() && ExtraTrimmed[0] == '\n') ||
136+
(ExtraTrimmed.size() >= 2 && ExtraTrimmed[0] == '\r' &&
137+
ExtraTrimmed[1] == '\n'))
138+
Q->RemainingContent = Extra;
139+
else {
140+
StringRef TrailingWord = lexWord();
141+
if (!TrailingWord.empty() && TrailingWord.front() == '#') {
142+
Line = Line.drop_until([](char c) { return c == '\n'; });
143+
Line = Line.drop_while([](char c) { return c == '\n'; });
144+
return endQuery(Q);
145+
}
146+
if (!TrailingWord.empty()) {
147+
return new InvalidQuery("unexpected extra input: '" + Extra + "'");
148+
}
149+
}
131150
return Q;
132151
}
133152

@@ -193,7 +212,11 @@ QueryRef QueryParser::doParse() {
193212
switch (QKind) {
194213
case PQK_Comment:
195214
case PQK_NoOp:
196-
return new NoOpQuery;
215+
Line = Line.drop_until([](char c) { return c == '\n'; });
216+
Line = Line.drop_while([](char c) { return c == '\n'; });
217+
if (Line.empty())
218+
return new NoOpQuery;
219+
return doParse();
197220

198221
case PQK_Help:
199222
return endQuery(new HelpQuery);
@@ -217,7 +240,9 @@ QueryRef QueryParser::doParse() {
217240
return makeInvalidQueryFromDiagnostics(Diag);
218241
}
219242

220-
return new LetQuery(Name, Value);
243+
auto *Q = new LetQuery(Name, Value);
244+
Q->RemainingContent = Line;
245+
return Q;
221246
}
222247

223248
case PQK_Match: {
@@ -226,12 +251,17 @@ QueryRef QueryParser::doParse() {
226251

227252
Diagnostics Diag;
228253
auto MatcherSource = Line.trim();
254+
auto OrigMatcherSource = MatcherSource;
229255
Optional<DynTypedMatcher> Matcher = Parser::parseMatcherExpression(
230256
MatcherSource, nullptr, &QS.NamedValues, &Diag);
231257
if (!Matcher) {
232258
return makeInvalidQueryFromDiagnostics(Diag);
233259
}
234-
return new MatchQuery(MatcherSource, *Matcher);
260+
auto ActualSource = OrigMatcherSource.slice(0, OrigMatcherSource.size() -
261+
MatcherSource.size());
262+
auto *Q = new MatchQuery(ActualSource, *Matcher);
263+
Q->RemainingContent = MatcherSource;
264+
return Q;
235265
}
236266

237267
case PQK_Set: {

clang-tools-extra/clang-query/tool/ClangQuery.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,16 @@ bool runCommandsInFile(const char *ExeName, std::string const &FileName,
6969
llvm::errs() << ExeName << ": cannot open " << FileName << "\n";
7070
return 1;
7171
}
72-
while (Input.good()) {
73-
std::string Line;
74-
std::getline(Input, Line);
7572

76-
QueryRef Q = QueryParser::parse(Line, QS);
73+
std::string FileContent((std::istreambuf_iterator<char>(Input)),
74+
std::istreambuf_iterator<char>());
75+
76+
StringRef FileContentRef(FileContent);
77+
while (!FileContentRef.empty()) {
78+
QueryRef Q = QueryParser::parse(FileContentRef, QS);
7779
if (!Q->run(llvm::outs(), QS))
7880
return true;
81+
FileContentRef = Q->RemainingContent;
7982
}
8083
return false;
8184
}

clang-tools-extra/clang-tidy/readability/ConstReturnTypeCheck.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ findConstToRemove(const FunctionDecl *Def,
4747
if (FileRange.isInvalid())
4848
return None;
4949

50-
return utils::lexer::getConstQualifyingToken(FileRange, *Result.Context,
51-
*Result.SourceManager);
50+
return utils::lexer::getQualifyingToken(
51+
tok::kw_const, FileRange, *Result.Context, *Result.SourceManager);
5252
}
5353

5454
namespace {

clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ static bool isUsedToInitializeAConstant(const MatchFinder::MatchResult &Result,
3434
return AsDecl->isImplicit();
3535
}
3636

37-
if (Node.get<EnumConstantDecl>() != nullptr)
37+
if (Node.get<EnumConstantDecl>())
3838
return true;
3939

4040
return llvm::any_of(Result.Context->getParents(Node),
@@ -125,8 +125,20 @@ bool MagicNumbersCheck::isConstant(const MatchFinder::MatchResult &Result,
125125
if (isUsedToInitializeAConstant(Result, Parent))
126126
return true;
127127

128-
// Ignore this instance, because this match reports the location
129-
// where the template is defined, not where it is instantiated.
128+
// Ignore this instance, because this matches an
129+
// expanded class enumeration value.
130+
if (Parent.get<CStyleCastExpr>() &&
131+
llvm::any_of(
132+
Result.Context->getParents(Parent),
133+
[](const DynTypedNode &GrandParent) {
134+
return GrandParent.get<SubstNonTypeTemplateParmExpr>() !=
135+
nullptr;
136+
}))
137+
return true;
138+
139+
// Ignore this instance, because this match reports the
140+
// location where the template is defined, not where it
141+
// is instantiated.
130142
if (Parent.get<SubstNonTypeTemplateParmExpr>())
131143
return true;
132144

clang-tools-extra/clang-tidy/utils/LexerUtils.cpp

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,20 @@ bool rangeContainsExpansionsOrDirectives(SourceRange Range,
102102
return false;
103103
}
104104

105-
llvm::Optional<Token> getConstQualifyingToken(CharSourceRange Range,
106-
const ASTContext &Context,
107-
const SourceManager &SM) {
105+
llvm::Optional<Token> getQualifyingToken(tok::TokenKind TK,
106+
CharSourceRange Range,
107+
const ASTContext &Context,
108+
const SourceManager &SM) {
109+
assert((TK == tok::kw_const || TK == tok::kw_volatile ||
110+
TK == tok::kw_restrict) &&
111+
"TK is not a qualifier keyword");
108112
std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(Range.getBegin());
109113
StringRef File = SM.getBufferData(LocInfo.first);
110114
Lexer RawLexer(SM.getLocForStartOfFile(LocInfo.first), Context.getLangOpts(),
111115
File.begin(), File.data() + LocInfo.second, File.end());
112-
llvm::Optional<Token> FirstConstTok;
113-
Token LastTokInRange;
116+
llvm::Optional<Token> LastMatchBeforeTemplate;
117+
llvm::Optional<Token> LastMatchAfterTemplate;
118+
bool SawTemplate = false;
114119
Token Tok;
115120
while (!RawLexer.LexFromRawLexer(Tok) &&
116121
Range.getEnd() != Tok.getLocation() &&
@@ -121,13 +126,19 @@ llvm::Optional<Token> getConstQualifyingToken(CharSourceRange Range,
121126
Tok.setIdentifierInfo(&Info);
122127
Tok.setKind(Info.getTokenID());
123128
}
124-
if (Tok.is(tok::kw_const) && !FirstConstTok)
125-
FirstConstTok = Tok;
126-
LastTokInRange = Tok;
129+
if (Tok.is(tok::less))
130+
SawTemplate = true;
131+
else if (Tok.isOneOf(tok::greater, tok::greatergreater))
132+
LastMatchAfterTemplate = None;
133+
else if (Tok.is(TK)) {
134+
if (SawTemplate)
135+
LastMatchAfterTemplate = Tok;
136+
else
137+
LastMatchBeforeTemplate = Tok;
138+
}
127139
}
128-
// If the last token in the range is a `const`, then it const qualifies the
129-
// type. Otherwise, the first `const` token, if any, is the qualifier.
130-
return LastTokInRange.is(tok::kw_const) ? LastTokInRange : FirstConstTok;
140+
return LastMatchAfterTemplate != None ? LastMatchAfterTemplate
141+
: LastMatchBeforeTemplate;
131142
}
132143
} // namespace lexer
133144
} // namespace utils

clang-tools-extra/clang-tidy/utils/LexerUtils.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,15 @@ bool rangeContainsExpansionsOrDirectives(SourceRange Range,
9292
const SourceManager &SM,
9393
const LangOptions &LangOpts);
9494

95-
/// Assuming that ``Range`` spans a const-qualified type, returns the ``const``
96-
/// token in ``Range`` that is responsible for const qualification. ``Range``
97-
/// must be valid with respect to ``SM``. Returns ``None`` if no ``const``
95+
/// Assuming that ``Range`` spans a CVR-qualified type, returns the
96+
/// token in ``Range`` that is responsible for the qualification. ``Range``
97+
/// must be valid with respect to ``SM``. Returns ``None`` if no qualifying
9898
/// tokens are found.
99-
llvm::Optional<Token> getConstQualifyingToken(CharSourceRange Range,
100-
const ASTContext &Context,
101-
const SourceManager &SM);
99+
/// \note: doesn't support member function qualifiers.
100+
llvm::Optional<Token> getQualifyingToken(tok::TokenKind TK,
101+
CharSourceRange Range,
102+
const ASTContext &Context,
103+
const SourceManager &SM);
102104

103105
} // namespace lexer
104106
} // namespace utils

clang-tools-extra/clangd/Hover.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ const NamedDecl *getDeclForComment(const NamedDecl *D) {
195195
return VTSD->getTemplateInstantiationPattern();
196196
if (auto *FD = D->getAsFunction())
197197
if (FD->isTemplateInstantiation())
198-
return FD->getTemplateSpecializationInfo()->getTemplate();
198+
return FD->getTemplateInstantiationPattern();
199199
return D;
200200
}
201201

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,6 +1455,24 @@ TEST(Hover, All) {
14551455
HI.Kind = index::SymbolKind::Struct;
14561456
HI.Documentation = "auto on alias";
14571457
}},
1458+
{
1459+
R"cpp(// should not crash.
1460+
template <class T> struct cls {
1461+
int method();
1462+
};
1463+
1464+
auto test = cls<int>().[[m^ethod]]();
1465+
)cpp",
1466+
[](HoverInfo &HI) {
1467+
HI.Definition = "int method()";
1468+
HI.Kind = index::SymbolKind::InstanceMethod;
1469+
HI.NamespaceScope = "";
1470+
HI.LocalScope = "cls<int>::";
1471+
HI.Name = "method";
1472+
HI.Parameters.emplace();
1473+
HI.ReturnType = "int";
1474+
HI.Type = "int ()";
1475+
}},
14581476
};
14591477

14601478
// Create a tiny index, so tests above can verify documentation is fetched.

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ Improvements to clang-tidy
185185
The check now supports the ``IgnoreBitFieldsWidths`` option to suppress
186186
the warning for numbers used to specify bit field widths.
187187

188+
The check was updated to eliminate some false positives (such as using
189+
class enumeration as non-type template parameters, or the synthetically
190+
computed lengh of a static user string literal.)
191+
188192
- New :doc:`readability-make-member-function-const
189193
<clang-tidy/checks/readability-make-member-function-const>` check.
190194

clang-tools-extra/docs/clang-doc.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ Clang-Doc
77
.. toctree::
88
:maxdepth: 1
99

10-
:program:`clang-doc` is a tool for generating C and C++ documentation from
11-
source code and comments.
10+
:program:`clang-doc` is a tool for generating C and C++ documentation from
11+
source code and comments.
1212

1313
The tool is in a very early development stage, so you might encounter bugs and
1414
crashes. Submitting reports with information about how to reproduce the issue
@@ -21,7 +21,7 @@ Use
2121

2222
:program:`clang-doc` is a `LibTooling
2323
<https://clang.llvm.org/docs/LibTooling.html>`_-based tool, and so requires a
24-
compile command database for your project (for an example of how to do this
24+
compile command database for your project (for an example of how to do this
2525
see `How To Setup Tooling For LLVM
2626
<https://clang.llvm.org/docs/HowToSetupToolingForLLVM.html>`_).
2727

@@ -81,7 +81,9 @@ Options
8181
8282
--doxygen - Use only doxygen-style comments to generate docs.
8383
--extra-arg=<string> - Additional argument to append to the compiler command line
84+
Can be used several times.
8485
--extra-arg-before=<string> - Additional argument to prepend to the compiler command line
86+
Can be used several times.
8587
--format=<value> - Format for outputted docs.
8688
=yaml - Documentation in YAML format.
8789
=md - Documentation in MD format.

clang-tools-extra/docs/clang-rename.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ That way you can avoid spelling out all the names as command line arguments:
123123
124124
-export-fixes=<filename> - YAML file to store suggested fixes in.
125125
-extra-arg=<string> - Additional argument to append to the compiler command line
126+
Can be used several times.
126127
-extra-arg-before=<string> - Additional argument to prepend to the compiler command line
128+
Can be used several times.
127129
-force - Ignore nonexistent qualified names.
128130
-i - Overwrite edited <file>s.
129131
-input=<string> - YAML file to load oldname-newname pairs from.

clang-tools-extra/docs/clang-tidy/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@ An overview of all the command-line options:
155155
stored fixes can be applied to the input source
156156
code with clang-apply-replacements.
157157
--extra-arg=<string> - Additional argument to append to the compiler command line
158+
Can be used several times.
158159
--extra-arg-before=<string> - Additional argument to prepend to the compiler command line
160+
Can be used several times.
159161
--fix -
160162
Apply suggested fixes. Without -fix-errors
161163
clang-tidy will bail out if any compilation

0 commit comments

Comments
 (0)