Skip to content

Commit 3e5a028

Browse files
committed
Merge from 'master' to 'sycl-web' (#156)
CONFLICT (content): Merge conflict in clang/lib/AST/TypePrinter.cpp
2 parents 7d548f2 + 869d17d commit 3e5a028

File tree

2,286 files changed

+244958
-6493
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,286 files changed

+244958
-6493
lines changed

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

clang-tools-extra/test/clang-tidy/checkers/readability-const-return-type.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ const T p32(T t) { return t; }
3737
template <typename T>
3838
typename std::add_const<T>::type n15(T v) { return v; }
3939

40+
template <bool B>
41+
struct MyStruct {};
42+
4043
template <typename A>
4144
class Klazz {
4245
public:
@@ -128,10 +131,46 @@ const Klazz<const int> p12() {}
128131
// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Klazz<const int>'
129132
// CHECK-FIXES: Klazz<const int> p12() {}
130133

134+
const Klazz<const Klazz<const int>> p33() {}
135+
// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Klazz<
136+
// CHECK-FIXES: Klazz<const Klazz<const int>> p33() {}
137+
131138
const Klazz<const int>* const p13() {}
132139
// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Klazz<const int> *
133140
// CHECK-FIXES: const Klazz<const int>* p13() {}
134141

142+
const Klazz<const int>* const volatile p14() {}
143+
// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Klazz<const int> *
144+
// CHECK-FIXES: const Klazz<const int>* volatile p14() {}
145+
146+
const MyStruct<0 < 1> p34() {}
147+
// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const MyStruct<0 < 1>'
148+
// CHECK-FIXES: MyStruct<0 < 1> p34() {}
149+
150+
MyStruct<0 < 1> const p35() {}
151+
// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const MyStruct<0 < 1>'
152+
// CHECK-FIXES: MyStruct<0 < 1> p35() {}
153+
154+
Klazz<MyStruct<0 < 1> const> const p36() {}
155+
// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Klazz<const MyStru
156+
// CHECK-FIXES: Klazz<MyStruct<0 < 1> const> p36() {}
157+
158+
const Klazz<MyStruct<0 < 1> const> *const p37() {}
159+
// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Klazz<const MyStru
160+
// CHECK-FIXES: const Klazz<MyStruct<0 < 1> const> *p37() {}
161+
162+
Klazz<const MyStruct<0 < 1>> const p38() {}
163+
// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Klazz<const MyStru
164+
// CHECK-FIXES: Klazz<const MyStruct<0 < 1>> p38() {}
165+
166+
const Klazz<const MyStruct<0 < 1>> p39() {}
167+
// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Klazz<
168+
// CHECK-FIXES: Klazz<const MyStruct<0 < 1>> p39() {}
169+
170+
const Klazz<const MyStruct<(0 > 1)>> p40() {}
171+
// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const Klazz<const MyStru
172+
// CHECK-FIXES: Klazz<const MyStruct<(0 > 1)>> p40() {}
173+
135174
// re-declaration of p15.
136175
const int p15();
137176
// CHECK-FIXES: int p15();
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %check_clang_tidy %s readability-magic-numbers %t --
2+
// XFAIL: *
3+
4+
int ProcessSomething(int input);
5+
6+
int DoWork()
7+
{
8+
if (((int)4) > ProcessSomething(10))
9+
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: 4 is a magic number; consider replacing it with a named constant [readability-magic-numbers]
10+
return 0;
11+
12+
return 0;
13+
}
14+
15+

clang-tools-extra/test/clang-tidy/checkers/readability-magic-numbers.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class TwoIntContainer {
5959
const int anotherConstant;
6060
};
6161

62-
int ValueArray[] = {3, 5};
62+
int ValueArray[] = {3, 5, 0, 0, 0};
6363
// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: 3 is a magic number; consider replacing it with a named constant [readability-magic-numbers]
6464
// CHECK-MESSAGES: :[[@LINE-2]]:24: warning: 5 is a magic number; consider replacing it with a named constant [readability-magic-numbers]
6565

@@ -183,7 +183,7 @@ struct Rectangle {
183183

184184
const geometry::Rectangle<double> mandelbrotCanvas{geometry::Point<double>{-2.5, -1}, geometry::Dimension<double>{3.5, 2}};
185185

186-
// Simulate the macro magic in Google Test internal headers
186+
// Simulate the macro magic in Google Test internal headers.
187187
class AssertionHelper {
188188
public:
189189
AssertionHelper(const char *Message, int LineNumber) : Message(Message), LineNumber(LineNumber) {}
@@ -201,7 +201,7 @@ void FunctionWithCompilerDefinedSymbol(void) {
201201
ASSERTION_HELPER("here and now");
202202
}
203203

204-
// prove that integer literals introduced by the compiler are accepted silently
204+
// Prove that integer literals introduced by the compiler are accepted silently.
205205
extern int ConsumeString(const char *Input);
206206

207207
const char *SomeStrings[] = {"alpha", "beta", "gamma"};
@@ -215,3 +215,14 @@ int TestCheckerOverreach() {
215215

216216
return Total;
217217
}
218+
219+
// Prove that using enumerations values don't produce warnings.
220+
enum class Letter : unsigned {
221+
A, B, C, D, E, F, G, H, I, J
222+
};
223+
224+
template<Letter x> struct holder { Letter letter = x; };
225+
template<Letter x> struct wrapper { using h_type = holder<x>; };
226+
227+
template struct wrapper<Letter::A>;
228+
template struct wrapper<Letter::J>;

clang/docs/OpenMPSupport.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ implementation.
165165
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
166166
| SIMD extension | atomic and simd constructs inside SIMD code | :good:`done` | |
167167
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
168-
| SIMD extension | SIMD nontemporal | :part:`claimed` | |
168+
| SIMD extension | SIMD nontemporal | :good:`done` | |
169169
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
170170
| device extension | infer target functions from initializers | :part:`worked on` | |
171171
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
@@ -227,7 +227,7 @@ implementation.
227227
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
228228
| misc extension | metadirectives | :none:`worked on` | |
229229
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
230-
| misc extension | conditional modifier for lastprivate clause | :none:`unclaimed` | |
230+
| misc extension | conditional modifier for lastprivate clause | :part:`worked on` | |
231231
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
232232
| misc extension | user-defined function variants | :part:`worked on` | D67294, D64095 |
233233
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+

clang/include/clang/AST/ASTContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class ObjCPropertyDecl;
113113
class ObjCPropertyImplDecl;
114114
class ObjCProtocolDecl;
115115
class ObjCTypeParamDecl;
116-
class ParsedTargetAttr;
116+
struct ParsedTargetAttr;
117117
class Preprocessor;
118118
class Stmt;
119119
class StoredDeclsMap;

clang/include/clang/AST/DeclCXX.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,8 @@ class CXXRecordDecl : public RecordDecl {
10461046

10471047
/// Get all conversion functions visible in current class,
10481048
/// including conversion function templates.
1049-
llvm::iterator_range<conversion_iterator> getVisibleConversionFunctions();
1049+
llvm::iterator_range<conversion_iterator>
1050+
getVisibleConversionFunctions() const;
10501051

10511052
/// Determine whether this class is an aggregate (C++ [dcl.init.aggr]),
10521053
/// which is a class with no user-declared constructors, no private

0 commit comments

Comments
 (0)