Skip to content

Commit e24ca96

Browse files
committed
Merge from 'master' to 'sycl-web' (#16)
2 parents 832dd0a + 979da9a commit e24ca96

Some content is hidden

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

49 files changed

+513
-119
lines changed

clang-tools-extra/clang-tidy/bugprone/MacroRepeatedSideEffectsCheck.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "MacroRepeatedSideEffectsCheck.h"
10+
#include "clang/Basic/Builtins.h"
1011
#include "clang/Frontend/CompilerInstance.h"
1112
#include "clang/Lex/MacroArgs.h"
1213
#include "clang/Lex/PPCallbacks.h"

clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ namespace modernize {
2020
UseOverrideCheck::UseOverrideCheck(StringRef Name, ClangTidyContext *Context)
2121
: ClangTidyCheck(Name, Context),
2222
IgnoreDestructors(Options.get("IgnoreDestructors", false)),
23+
AllowOverrideAndFinal(Options.get("AllowOverrideAndFinal", false)),
2324
OverrideSpelling(Options.get("OverrideSpelling", "override")),
2425
FinalSpelling(Options.get("FinalSpelling", "final")) {}
2526

2627
void UseOverrideCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
2728
Options.store(Opts, "IgnoreDestructors", IgnoreDestructors);
29+
Options.store(Opts, "AllowOverrideAndFinal", AllowOverrideAndFinal);
2830
Options.store(Opts, "OverrideSpelling", OverrideSpelling);
2931
Options.store(Opts, "FinalSpelling", FinalSpelling);
3032
}
@@ -103,7 +105,8 @@ void UseOverrideCheck::check(const MatchFinder::MatchResult &Result) {
103105
bool OnlyVirtualSpecified = HasVirtual && !HasOverride && !HasFinal;
104106
unsigned KeywordCount = HasVirtual + HasOverride + HasFinal;
105107

106-
if (!OnlyVirtualSpecified && KeywordCount == 1)
108+
if ((!OnlyVirtualSpecified && KeywordCount == 1) ||
109+
(!HasVirtual && HasOverride && HasFinal && AllowOverrideAndFinal))
107110
return; // Nothing to do.
108111

109112
std::string Message;
@@ -113,8 +116,9 @@ void UseOverrideCheck::check(const MatchFinder::MatchResult &Result) {
113116
Message = "annotate this function with '%0' or (rarely) '%1'";
114117
} else {
115118
StringRef Redundant =
116-
HasVirtual ? (HasOverride && HasFinal ? "'virtual' and '%0' are"
117-
: "'virtual' is")
119+
HasVirtual ? (HasOverride && HasFinal && !AllowOverrideAndFinal
120+
? "'virtual' and '%0' are"
121+
: "'virtual' is")
118122
: "'%0' is";
119123
StringRef Correct = HasFinal ? "'%1'" : "'%0'";
120124

@@ -211,7 +215,7 @@ void UseOverrideCheck::check(const MatchFinder::MatchResult &Result) {
211215
Diag << FixItHint::CreateInsertion(InsertLoc, ReplacementText);
212216
}
213217

214-
if (HasFinal && HasOverride) {
218+
if (HasFinal && HasOverride && !AllowOverrideAndFinal) {
215219
SourceLocation OverrideLoc = Method->getAttr<OverrideAttr>()->getLocation();
216220
Diag << FixItHint::CreateRemoval(
217221
CharSourceRange::getTokenRange(OverrideLoc, OverrideLoc));

clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class UseOverrideCheck : public ClangTidyCheck {
2626

2727
private:
2828
const bool IgnoreDestructors;
29+
const bool AllowOverrideAndFinal;
2930
const std::string OverrideSpelling;
3031
const std::string FinalSpelling;
3132
};

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

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "RedundantStringInitCheck.h"
1010
#include "../utils/Matchers.h"
11+
#include "../utils/OptionsUtils.h"
1112
#include "clang/ASTMatchers/ASTMatchers.h"
1213

1314
using namespace clang::ast_matchers;
@@ -17,19 +18,43 @@ namespace clang {
1718
namespace tidy {
1819
namespace readability {
1920

21+
const char DefaultStringNames[] = "::std::basic_string";
22+
23+
RedundantStringInitCheck::RedundantStringInitCheck(StringRef Name,
24+
ClangTidyContext *Context)
25+
: ClangTidyCheck(Name, Context),
26+
StringNames(utils::options::parseStringList(
27+
Options.get("StringNames", DefaultStringNames))) {}
28+
29+
void RedundantStringInitCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
30+
Options.store(Opts, "StringNames", DefaultStringNames);
31+
}
32+
2033
void RedundantStringInitCheck::registerMatchers(MatchFinder *Finder) {
2134
if (!getLangOpts().CPlusPlus)
2235
return;
36+
const auto hasStringTypeName = hasAnyName(
37+
SmallVector<StringRef, 3>(StringNames.begin(), StringNames.end()));
38+
39+
// Version of StringNames with namespaces removed
40+
std::vector<std::string> stringNamesNoNamespace;
41+
for (const std::string &name : StringNames) {
42+
std::string::size_type colonPos = name.rfind(':');
43+
stringNamesNoNamespace.push_back(
44+
name.substr(colonPos == std::string::npos ? 0 : colonPos + 1));
45+
}
46+
const auto hasStringCtorName = hasAnyName(SmallVector<StringRef, 3>(
47+
stringNamesNoNamespace.begin(), stringNamesNoNamespace.end()));
2348

2449
// Match string constructor.
25-
const auto StringConstructorExpr = expr(anyOf(
26-
cxxConstructExpr(argumentCountIs(1),
27-
hasDeclaration(cxxMethodDecl(hasName("basic_string")))),
28-
// If present, the second argument is the alloc object which must not
29-
// be present explicitly.
30-
cxxConstructExpr(argumentCountIs(2),
31-
hasDeclaration(cxxMethodDecl(hasName("basic_string"))),
32-
hasArgument(1, cxxDefaultArgExpr()))));
50+
const auto StringConstructorExpr = expr(
51+
anyOf(cxxConstructExpr(argumentCountIs(1),
52+
hasDeclaration(cxxMethodDecl(hasStringCtorName))),
53+
// If present, the second argument is the alloc object which must
54+
// not be present explicitly.
55+
cxxConstructExpr(argumentCountIs(2),
56+
hasDeclaration(cxxMethodDecl(hasStringCtorName)),
57+
hasArgument(1, cxxDefaultArgExpr()))));
3358

3459
// Match a string constructor expression with an empty string literal.
3560
const auto EmptyStringCtorExpr = cxxConstructExpr(
@@ -48,7 +73,7 @@ void RedundantStringInitCheck::registerMatchers(MatchFinder *Finder) {
4873
namedDecl(
4974
varDecl(
5075
hasType(hasUnqualifiedDesugaredType(recordType(
51-
hasDeclaration(cxxRecordDecl(hasName("basic_string")))))),
76+
hasDeclaration(cxxRecordDecl(hasStringTypeName))))),
5277
hasInitializer(expr(ignoringImplicit(anyOf(
5378
EmptyStringCtorExpr, EmptyStringCtorExprWithTemporaries)))))
5479
.bind("vardecl"),

clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANT_STRING_INIT_H
1111

1212
#include "../ClangTidyCheck.h"
13+
#include <string>
14+
#include <vector>
1315

1416
namespace clang {
1517
namespace tidy {
@@ -18,10 +20,13 @@ namespace readability {
1820
/// Finds unnecessary string initializations.
1921
class RedundantStringInitCheck : public ClangTidyCheck {
2022
public:
21-
RedundantStringInitCheck(StringRef Name, ClangTidyContext *Context)
22-
: ClangTidyCheck(Name, Context) {}
23+
RedundantStringInitCheck(StringRef Name, ClangTidyContext *Context);
24+
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
2325
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
2426
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
27+
28+
private:
29+
std::vector<std::string> StringNames;
2530
};
2631

2732
} // namespace readability

clang-tools-extra/clangd/index/FileIndex.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "index/Merge.h"
1717
#include "index/SymbolOrigin.h"
1818
#include "index/dex/Dex.h"
19+
#include "clang/AST/ASTContext.h"
1920
#include "clang/Index/IndexingAction.h"
2021
#include "clang/Index/IndexingOptions.h"
2122
#include "clang/Lex/MacroInfo.h"

clang-tools-extra/clangd/index/FileIndex.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <memory>
2626

2727
namespace clang {
28+
class ASTContext;
2829
namespace clangd {
2930
class ParsedAST;
3031

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,16 @@ Improvements to clang-tidy
164164
Finds non-static member functions that can be made ``const``
165165
because the functions don't use ``this`` in a non-const way.
166166

167+
- Improved :doc:`modernize-use-override
168+
<clang-tidy/checks/modernize-use-override>` check.
169+
170+
The check now supports the ``AllowOverrideAndFinal`` option to eliminate
171+
conflicts with ``gcc -Wsuggest-override`` or ``gcc -Werror=suggest-override``.
172+
173+
- The :doc:`readability-redundant-string-init
174+
<clang-tidy/checks/readability-redundant-string-init>` check now supports a
175+
`StringNames` option enabling its application to custom string classes.
176+
167177
Improvements to include-fixer
168178
-----------------------------
169179

clang-tools-extra/docs/clang-tidy/checks/modernize-use-override.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ Options
2727

2828
If set to non-zero, this check will not diagnose destructors. Default is `0`.
2929

30+
.. option:: AllowOverrideAndFinal
31+
32+
If set to non-zero, this check will not diagnose ``override`` as redundant
33+
with ``final``. This is useful when code will be compiled by a compiler with
34+
warning/error checking flags requiring ``override`` explicitly on overriden
35+
members, such as ``gcc -Wsuggest-override``/``gcc -Werror=suggest-override``.
36+
Default is `0`.
37+
3038
.. option:: OverrideSpelling
3139

3240
Specifies a macro to use instead of ``override``. This is useful when

clang-tools-extra/docs/clang-tidy/checks/readability-redundant-string-init.rst

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ readability-redundant-string-init
55

66
Finds unnecessary string initializations.
77

8-
Examples:
8+
Examples
9+
--------
910

1011
.. code-block:: c++
1112

@@ -17,3 +18,15 @@ Examples:
1718

1819
std::string a;
1920
std::string b;
21+
22+
Options
23+
-------
24+
25+
.. option:: StringNames
26+
27+
Default is `::std::basic_string`.
28+
29+
Semicolon-delimited list of class names to apply this check to.
30+
By default `::std::basic_string` applies to ``std::string`` and
31+
``std::wstring``. Set to e.g. `::std::basic_string;llvm::StringRef;QString`
32+
to perform this check on custom classes.

clang-tools-extra/test/clang-tidy/checkers/readability-redundant-string-init.cpp

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
// RUN: %check_clang_tidy %s readability-redundant-string-init %t
1+
// RUN: %check_clang_tidy -std=c++11,c++14 %s readability-redundant-string-init %t \
2+
// RUN: -config="{CheckOptions: \
3+
// RUN: [{key: readability-redundant-string-init.StringNames, \
4+
// RUN: value: '::std::basic_string;our::TestString'}] \
5+
// RUN: }"
6+
// FIXME: Fix the checker to work in C++17 mode.
27

38
namespace std {
49
template <typename T>
@@ -143,3 +148,82 @@ extern void Param2(const std::string& param = "");
143148
void Param3(std::string param = "") {}
144149
void Param4(STRING param = "") {}
145150

151+
namespace our {
152+
struct TestString {
153+
TestString();
154+
TestString(const TestString &);
155+
TestString(const char *);
156+
~TestString();
157+
};
158+
}
159+
160+
void ourTestStringTests() {
161+
our::TestString a = "";
162+
// CHECK-MESSAGES: [[@LINE-1]]:19: warning: redundant string initialization
163+
// CHECK-FIXES: our::TestString a;
164+
our::TestString b("");
165+
// CHECK-MESSAGES: [[@LINE-1]]:19: warning: redundant string initialization
166+
// CHECK-FIXES: our::TestString b;
167+
our::TestString c = R"()";
168+
// CHECK-MESSAGES: [[@LINE-1]]:19: warning: redundant string initialization
169+
// CHECK-FIXES: our::TestString c;
170+
our::TestString d(R"()");
171+
// CHECK-MESSAGES: [[@LINE-1]]:19: warning: redundant string initialization
172+
// CHECK-FIXES: our::TestString d;
173+
174+
our::TestString u = "u";
175+
our::TestString w("w");
176+
our::TestString x = R"(x)";
177+
our::TestString y(R"(y)");
178+
our::TestString z;
179+
}
180+
181+
namespace their {
182+
using TestString = our::TestString;
183+
}
184+
185+
// their::TestString is the same type so should warn / fix
186+
void theirTestStringTests() {
187+
their::TestString a = "";
188+
// CHECK-MESSAGES: [[@LINE-1]]:21: warning: redundant string initialization
189+
// CHECK-FIXES: their::TestString a;
190+
their::TestString b("");
191+
// CHECK-MESSAGES: [[@LINE-1]]:21: warning: redundant string initialization
192+
// CHECK-FIXES: their::TestString b;
193+
}
194+
195+
namespace other {
196+
// Identical declarations to above but different type
197+
struct TestString {
198+
TestString();
199+
TestString(const TestString &);
200+
TestString(const char *);
201+
~TestString();
202+
};
203+
204+
// Identical declarations to above but different type
205+
template <typename T>
206+
class allocator {};
207+
template <typename T>
208+
class char_traits {};
209+
template <typename C, typename T = std::char_traits<C>, typename A = std::allocator<C>>
210+
struct basic_string {
211+
basic_string();
212+
basic_string(const basic_string &);
213+
basic_string(const C *, const A &a = A());
214+
~basic_string();
215+
};
216+
typedef basic_string<char> string;
217+
typedef basic_string<wchar_t> wstring;
218+
}
219+
220+
// other::TestString, other::string, other::wstring are unrelated to the types
221+
// being checked. No warnings / fixes should be produced for these types.
222+
void otherTestStringTests() {
223+
other::TestString a = "";
224+
other::TestString b("");
225+
other::string c = "";
226+
other::string d("");
227+
other::wstring e = L"";
228+
other::wstring f(L"");
229+
}

clang/include/clang/Basic/Builtins.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
namespace clang {
2626
class TargetInfo;
2727
class IdentifierTable;
28-
class ASTContext;
29-
class QualType;
3028
class LangOptions;
3129

3230
enum LanguageID {

clang/include/clang/Basic/DebugInfoOptions.h

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,30 @@ enum DebugInfoFormat {
1818
};
1919

2020
enum DebugInfoKind {
21-
NoDebugInfo, /// Don't generate debug info.
22-
LocTrackingOnly, /// Emit location information but do not generate
23-
/// debug info in the output. This is useful in
24-
/// cases where the backend wants to track source
25-
/// locations for instructions without actually
26-
/// emitting debug info for them (e.g., when -Rpass
27-
/// is used).
28-
DebugDirectivesOnly, /// Emit only debug directives with the line numbers data
29-
DebugLineTablesOnly, /// Emit only debug info necessary for generating
30-
/// line number tables (-gline-tables-only).
31-
LimitedDebugInfo, /// Limit generated debug info to reduce size
32-
/// (-fno-standalone-debug). This emits
33-
/// forward decls for types that could be
34-
/// replaced with forward decls in the source
35-
/// code. For dynamic C++ classes type info
36-
/// is only emitted into the module that
37-
/// contains the classe's vtable.
38-
FullDebugInfo /// Generate complete debug info.
21+
/// Don't generate debug info.
22+
NoDebugInfo,
23+
24+
/// Emit location information but do not generate debug info in the output.
25+
/// This is useful in cases where the backend wants to track source
26+
/// locations for instructions without actually emitting debug info for them
27+
/// (e.g., when -Rpass is used).
28+
LocTrackingOnly,
29+
30+
/// Emit only debug directives with the line numbers data
31+
DebugDirectivesOnly,
32+
33+
/// Emit only debug info necessary for generating line number tables
34+
/// (-gline-tables-only).
35+
DebugLineTablesOnly,
36+
37+
/// Limit generated debug info to reduce size (-fno-standalone-debug). This
38+
/// emits forward decls for types that could be replaced with forward decls in
39+
/// the source code. For dynamic C++ classes type info is only emitted into
40+
/// the module that contains the classe's vtable.
41+
LimitedDebugInfo,
42+
43+
/// Generate complete debug info.
44+
FullDebugInfo
3945
};
4046

4147
} // end namespace codegenoptions

0 commit comments

Comments
 (0)