Skip to content

Commit af2faa8

Browse files
committed
Merge remote-tracking branch 'intel_llvm/sycl-web' into llvmspirv_pulldown
2 parents 57001ed + 1a729b9 commit af2faa8

File tree

1,023 files changed

+54861
-21821
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,023 files changed

+54861
-21821
lines changed

clang-tools-extra/clang-tidy/performance/NoAutomaticMoveCheck.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,22 @@ using namespace clang::ast_matchers;
1616

1717
namespace clang::tidy::performance {
1818

19+
namespace {
20+
21+
AST_MATCHER(VarDecl, isNRVOVariable) { return Node.isNRVOVariable(); }
22+
23+
} // namespace
24+
1925
NoAutomaticMoveCheck::NoAutomaticMoveCheck(StringRef Name,
2026
ClangTidyContext *Context)
2127
: ClangTidyCheck(Name, Context),
2228
AllowedTypes(
2329
utils::options::parseStringList(Options.get("AllowedTypes", ""))) {}
2430

2531
void NoAutomaticMoveCheck::registerMatchers(MatchFinder *Finder) {
26-
const auto ConstLocalVariable =
32+
const auto NonNrvoConstLocalVariable =
2733
varDecl(hasLocalStorage(), unless(hasType(lValueReferenceType())),
34+
unless(isNRVOVariable()),
2835
hasType(qualType(
2936
isConstQualified(),
3037
hasCanonicalType(matchers::isExpensiveToCopy()),
@@ -48,7 +55,7 @@ void NoAutomaticMoveCheck::registerMatchers(MatchFinder *Finder) {
4855
cxxConstructExpr(
4956
hasDeclaration(LValueRefCtor),
5057
hasArgument(0, ignoringParenImpCasts(declRefExpr(
51-
to(ConstLocalVariable)))))
58+
to(NonNrvoConstLocalVariable)))))
5259
.bind("ctor_call")))))),
5360
this);
5461
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,10 @@ void ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) {
262262
expr(anyOf(allOf(isMacroExpansion(), unless(isNULLMacroExpansion())),
263263
has(ignoringImplicit(
264264
memberExpr(hasDeclaration(fieldDecl(hasBitWidth(1)))))),
265-
hasParent(explicitCastExpr())));
265+
hasParent(explicitCastExpr()),
266+
expr(hasType(qualType().bind("type")),
267+
hasParent(initListExpr(hasParent(explicitCastExpr(
268+
hasType(qualType(equalsBoundNode("type"))))))))));
266269
auto ImplicitCastFromBool = implicitCastExpr(
267270
anyOf(hasCastKind(CK_IntegralCast), hasCastKind(CK_IntegralToFloating),
268271
// Prior to C++11 cast from bool literal to pointer was allowed.
@@ -290,7 +293,7 @@ void ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) {
290293
unless(ExceptionCases), unless(has(BoolXor)),
291294
// Retrieve also parent statement, to check if we need
292295
// additional parens in replacement.
293-
anyOf(hasParent(stmt().bind("parentStmt")), anything()),
296+
optionally(hasParent(stmt().bind("parentStmt"))),
294297
unless(isInTemplateInstantiation()),
295298
unless(hasAncestor(functionTemplateDecl())))
296299
.bind("implicitCastToBool")),

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ void StaticAccessedThroughInstanceCheck::check(
5959
if (isa<CXXOperatorCallExpr>(BaseExpr))
6060
return;
6161

62-
QualType BaseType =
62+
const QualType BaseType =
6363
BaseExpr->getType()->isPointerType()
6464
? BaseExpr->getType()->getPointeeType().getUnqualifiedType()
6565
: BaseExpr->getType().getUnqualifiedType();
@@ -75,6 +75,11 @@ void StaticAccessedThroughInstanceCheck::check(
7575
std::string BaseTypeName =
7676
BaseType.getAsString(PrintingPolicyWithSuppressedTag);
7777

78+
// Ignore anonymous structs/classes which will not have an identifier
79+
const RecordDecl *RecDecl = BaseType->getAsCXXRecordDecl();
80+
if (!RecDecl || RecDecl->getIdentifier() == nullptr)
81+
return;
82+
7883
// Do not warn for CUDA built-in variables.
7984
if (StringRef(BaseTypeName).startswith("__cuda_builtin_"))
8085
return;

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -537,17 +537,18 @@ ExceptionAnalyzer::analyzeImpl(const FunctionDecl *Func) {
537537
ExceptionInfo ExceptionList;
538538

539539
// Check if the function has already been analyzed and reuse that result.
540-
if (FunctionCache.count(Func) == 0) {
540+
const auto CacheEntry = FunctionCache.find(Func);
541+
if (CacheEntry == FunctionCache.end()) {
541542
llvm::SmallSet<const FunctionDecl *, 32> CallStack;
542543
ExceptionList = throwsException(Func, CallStack);
543544

544545
// Cache the result of the analysis. This is done prior to filtering
545546
// because it is best to keep as much information as possible.
546547
// The results here might be relevant to different analysis passes
547548
// with different needs as well.
548-
FunctionCache.insert(std::make_pair(Func, ExceptionList));
549+
FunctionCache.try_emplace(Func, ExceptionList);
549550
} else
550-
ExceptionList = FunctionCache[Func];
551+
ExceptionList = CacheEntry->getSecond();
551552

552553
return ExceptionList;
553554
}
@@ -579,8 +580,7 @@ ExceptionAnalyzer::analyze(const FunctionDecl *Func) {
579580
return analyzeDispatch(Func);
580581
}
581582

582-
ExceptionAnalyzer::ExceptionInfo
583-
ExceptionAnalyzer::analyze(const Stmt *Stmt) {
583+
ExceptionAnalyzer::ExceptionInfo ExceptionAnalyzer::analyze(const Stmt *Stmt) {
584584
return analyzeDispatch(Stmt);
585585
}
586586

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ namespace clang::tidy::utils {
2121
/// custom exception types.
2222
class ExceptionAnalyzer {
2323
public:
24-
enum class State : std::int8_t {
25-
Throwing = 0, ///< The function can definitely throw given an AST.
26-
NotThrowing = 1, ///< This function can not throw, given an AST.
27-
Unknown = 2, ///< This can happen for extern functions without available
28-
///< definition.
24+
enum class State {
25+
Throwing, ///< The function can definitely throw given an AST.
26+
NotThrowing, ///< This function can not throw, given an AST.
27+
Unknown, ///< This can happen for extern functions without available
28+
///< definition.
2929
};
3030

3131
/// Bundle the gathered information about an entity like a function regarding
@@ -144,7 +144,7 @@ class ExceptionAnalyzer {
144144

145145
bool IgnoreBadAlloc = true;
146146
llvm::StringSet<> IgnoredExceptions;
147-
std::map<const FunctionDecl *, ExceptionInfo> FunctionCache;
147+
llvm::DenseMap<const FunctionDecl *, ExceptionInfo> FunctionCache{32u};
148148
};
149149

150150
} // namespace clang::tidy::utils

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,17 @@ Changes in existing checks
175175
<clang-tidy/checks/bugprone/suspicious-include>` check.
176176
Global options of the same name should be used instead.
177177

178+
- Improved :doc:`bugprone-unchecked-optional-access
179+
<clang-tidy/checks/bugprone/unchecked-optional-access>` check to properly handle calls
180+
to ``std::forward``.
181+
178182
- Improved :doc:`bugprone-use-after-move
179183
<clang-tidy/checks/bugprone/use-after-move>` check to also cover constructor
180184
initializers.
181185

186+
- Deprecated :doc:`cert-dcl21-cpp
187+
<clang-tidy/checks/cert/dcl21-cpp>` check.
188+
182189
- Deprecated check-local options `HeaderFileExtensions`
183190
in :doc:`google-build-namespaces
184191
<clang-tidy/checks/google/build-namespaces>` check.
@@ -233,6 +240,10 @@ Changes in existing checks
233240
behavior of using `i` as the prefix for enum tags, set the `EnumConstantPrefix`
234241
option to `i` instead of using `EnumConstantHungarianPrefix`.
235242

243+
- Fixed a false positive in :doc:`readability-implicit-bool-conversion
244+
<clang-tidy/checks/readability/implicit-bool-conversion>` check warning would
245+
be unnecessarily emitted for explicit cast using direct list initialization.
246+
236247
- Added support to optionally ignore user-defined literals in
237248
:doc:`readability-magic-numbers<clang-tidy/checks/readability/magic-numbers>`.
238249

@@ -255,8 +266,9 @@ Changes in existing checks
255266
be unnecessarily emitted for template dependent ``if constexpr``.
256267

257268
- Improved :doc:`readability-static-accessed-through-instance
258-
<clang-tidy/checks/readability/static-accessed-through-instance>` check to
259-
support unscoped enumerations through instances.
269+
<clang-tidy/checks/readability/static-accessed-through-instance>` check to
270+
support unscoped enumerations through instances and fixed usage of anonymous
271+
structs or classes.
260272

261273
- Fixed a false positive in :doc:`cppcoreguidelines-slicing
262274
<clang-tidy/checks/cppcoreguidelines/slicing>` check when warning would be
@@ -275,6 +287,10 @@ Changes in existing checks
275287
<clang-tidy/checks/google/readability-avoid-underscore-in-googletest-name>` when using
276288
``DISABLED_`` in the test suite name.
277289

290+
- Fixed a false positive in :doc:`performance-no-automatic-move
291+
<clang-tidy/checks/performance/no-automatic-move>` when warning would be
292+
emitted for a const local variable to which NRVO is applied.
293+
278294
Removed checks
279295
^^^^^^^^^^^^^^
280296

clang-tools-extra/docs/clang-tidy/checks/cert/dcl21-cpp.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
cert-dcl21-cpp
44
==============
55

6+
.. note::
7+
This check is deprecated since it's no longer part of the CERT standard.
8+
It will be removed in :program:`clang-tidy` version 19.
9+
610
This check flags postfix ``operator++`` and ``operator--`` declarations
711
if the return type is not a const object. This also warns if the return type
812
is a reference type.

clang-tools-extra/include-cleaner/lib/FindHeaders.cpp

Lines changed: 58 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,21 @@
1010
#include "TypesInternal.h"
1111
#include "clang-include-cleaner/Record.h"
1212
#include "clang-include-cleaner/Types.h"
13+
#include "clang/AST/ASTContext.h"
1314
#include "clang/AST/Decl.h"
1415
#include "clang/AST/DeclBase.h"
16+
#include "clang/Basic/Builtins.h"
1517
#include "clang/Basic/FileEntry.h"
1618
#include "clang/Basic/SourceLocation.h"
1719
#include "clang/Basic/SourceManager.h"
1820
#include "clang/Tooling/Inclusions/StandardLibrary.h"
21+
#include "llvm/ADT/ArrayRef.h"
1922
#include "llvm/ADT/STLExtras.h"
2023
#include "llvm/ADT/SmallVector.h"
2124
#include "llvm/ADT/StringRef.h"
2225
#include "llvm/Support/Casting.h"
2326
#include "llvm/Support/ErrorHandling.h"
24-
#include <string>
27+
#include <optional>
2528
#include <utility>
2629

2730
namespace clang::include_cleaner {
@@ -106,37 +109,68 @@ hintedHeadersForStdHeaders(llvm::ArrayRef<tooling::stdlib::Header> Headers,
106109
return Results;
107110
}
108111

109-
// Special-case the ambiguous standard library symbols (e.g. std::move) which
110-
// are not supported by the tooling stdlib lib.
111-
llvm::SmallVector<Hinted<Header>>
112-
headersForSpecialSymbol(const Symbol &S, const SourceManager &SM,
113-
const PragmaIncludes *PI) {
114-
if (S.kind() != Symbol::Declaration || !S.declaration().isInStdNamespace())
112+
// Symbol to header mapping for std::move and std::remove, based on number of
113+
// parameters.
114+
std::optional<tooling::stdlib::Header>
115+
headerForAmbiguousStdSymbol(const NamedDecl *ND) {
116+
if (!ND->isInStdNamespace())
115117
return {};
116-
117-
const auto *FD = S.declaration().getAsFunction();
118+
const auto *FD = ND->getAsFunction();
118119
if (!FD)
119-
return {};
120-
121-
llvm::StringRef FName = symbolName(S);
122-
llvm::SmallVector<tooling::stdlib::Header> Headers;
120+
return std::nullopt;
121+
llvm::StringRef FName = symbolName(*ND);
123122
if (FName == "move") {
124123
if (FD->getNumParams() == 1)
125124
// move(T&& t)
126-
Headers.push_back(*tooling::stdlib::Header::named("<utility>"));
125+
return tooling::stdlib::Header::named("<utility>");
127126
if (FD->getNumParams() == 3)
128127
// move(InputIt first, InputIt last, OutputIt dest);
129-
Headers.push_back(*tooling::stdlib::Header::named("<algorithm>"));
128+
return tooling::stdlib::Header::named("<algorithm>");
130129
} else if (FName == "remove") {
131130
if (FD->getNumParams() == 1)
132131
// remove(const char*);
133-
Headers.push_back(*tooling::stdlib::Header::named("<cstdio>"));
132+
return tooling::stdlib::Header::named("<cstdio>");
134133
if (FD->getNumParams() == 3)
135134
// remove(ForwardIt first, ForwardIt last, const T& value);
136-
Headers.push_back(*tooling::stdlib::Header::named("<algorithm>"));
135+
return tooling::stdlib::Header::named("<algorithm>");
137136
}
138-
return applyHints(hintedHeadersForStdHeaders(Headers, SM, PI),
139-
Hints::CompleteSymbol);
137+
return std::nullopt;
138+
}
139+
140+
// Special-case symbols without proper locations, like the ambiguous standard
141+
// library symbols (e.g. std::move) or builtin declarations.
142+
std::optional<llvm::SmallVector<Hinted<Header>>>
143+
headersForSpecialSymbol(const Symbol &S, const SourceManager &SM,
144+
const PragmaIncludes *PI) {
145+
// Our special casing logic only deals with decls, so bail out early for
146+
// macros.
147+
if (S.kind() != Symbol::Declaration)
148+
return std::nullopt;
149+
const auto *ND = llvm::cast<NamedDecl>(&S.declaration());
150+
// We map based on names, so again bail out early if there are no names.
151+
if (!ND)
152+
return std::nullopt;
153+
auto *II = ND->getIdentifier();
154+
if (!II)
155+
return std::nullopt;
156+
157+
// Check first for symbols that are part of our stdlib mapping. As we have
158+
// header names for those.
159+
if (auto Header = headerForAmbiguousStdSymbol(ND)) {
160+
return applyHints(hintedHeadersForStdHeaders({*Header}, SM, PI),
161+
Hints::CompleteSymbol);
162+
}
163+
164+
// Now check for builtin symbols, we shouldn't suggest any headers for ones
165+
// without any headers.
166+
if (auto ID = II->getBuiltinID()) {
167+
const char *BuiltinHeader =
168+
ND->getASTContext().BuiltinInfo.getHeaderName(ID);
169+
if (!BuiltinHeader)
170+
return llvm::SmallVector<Hinted<Header>>{};
171+
// FIXME: Use the header mapping for builtins with a known header.
172+
}
173+
return std::nullopt;
140174
}
141175

142176
} // namespace
@@ -187,11 +221,13 @@ llvm::SmallVector<Header> headersForSymbol(const Symbol &S,
187221
// Get headers for all the locations providing Symbol. Same header can be
188222
// reached through different traversals, deduplicate those into a single
189223
// Header by merging their hints.
190-
llvm::SmallVector<Hinted<Header>> Headers =
191-
headersForSpecialSymbol(S, SM, PI);
192-
if (Headers.empty())
224+
llvm::SmallVector<Hinted<Header>> Headers;
225+
if (auto SpecialHeaders = headersForSpecialSymbol(S, SM, PI)) {
226+
Headers = std::move(*SpecialHeaders);
227+
} else {
193228
for (auto &Loc : locateSymbol(S))
194229
Headers.append(applyHints(findHeaders(Loc, SM, PI), Loc.Hint));
230+
}
195231
// If two Headers probably refer to the same file (e.g. Verbatim(foo.h) and
196232
// Physical(/path/to/foo.h), we won't deduplicate them or merge their hints
197233
llvm::stable_sort(

clang-tools-extra/include-cleaner/lib/WalkAST.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ class ASTWalker : public RecursiveASTVisitor<ASTWalker> {
3535
RefType RT = RefType::Explicit) {
3636
if (!ND || Loc.isInvalid())
3737
return;
38-
// Don't report builtin symbols.
39-
if (const auto *II = ND->getIdentifier(); II && II->getBuiltinID() > 0)
40-
return;
4138
Callback(Loc, *cast<NamedDecl>(ND->getCanonicalDecl()), RT);
4239
}
4340

@@ -91,14 +88,24 @@ class ASTWalker : public RecursiveASTVisitor<ASTWalker> {
9188
public:
9289
ASTWalker(DeclCallback Callback) : Callback(Callback) {}
9390

91+
// Operators are almost always ADL extension points and by design references
92+
// to them doesn't count as uses (generally the type should provide them, so
93+
// ignore them).
94+
// Unless we're using an operator defined as a member, in such cases treat
95+
// these as regular member references.
9496
bool TraverseCXXOperatorCallExpr(CXXOperatorCallExpr *S) {
9597
if (!WalkUpFromCXXOperatorCallExpr(S))
9698
return false;
97-
98-
// Operators are always ADL extension points, by design references to them
99-
// doesn't count as uses (generally the type should provide them).
100-
// Don't traverse the callee.
101-
99+
if (auto *CD = S->getCalleeDecl()) {
100+
if (llvm::isa<CXXMethodDecl>(CD)) {
101+
// Treat this as a regular member reference.
102+
report(S->getOperatorLoc(), getMemberProvider(S->getArg(0)->getType()),
103+
RefType::Implicit);
104+
} else {
105+
report(S->getOperatorLoc(), llvm::dyn_cast<NamedDecl>(CD),
106+
RefType::Implicit);
107+
}
108+
}
102109
for (auto *Arg : S->arguments())
103110
if (!TraverseStmt(Arg))
104111
return false;

clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,14 @@ TEST_F(WalkUsedTest, Basic) {
9393
void $bar^bar($private^Private $p^p) {
9494
$foo^foo();
9595
std::$vector^vector $vconstructor^$v^v;
96+
$builtin^__builtin_popcount(1);
97+
std::$move^move(3);
9698
}
9799
)cpp");
98100
Inputs.Code = Code.code();
99101
Inputs.ExtraFiles["header.h"] = guard(R"cpp(
100102
void foo();
101-
namespace std { class vector {}; }
103+
namespace std { class vector {}; int&& move(int&&); }
102104
)cpp");
103105
Inputs.ExtraFiles["private.h"] = guard(R"cpp(
104106
// IWYU pragma: private, include "path/public.h"
@@ -112,6 +114,7 @@ TEST_F(WalkUsedTest, Basic) {
112114
auto PublicFile = Header("\"path/public.h\"");
113115
auto MainFile = Header(SM.getFileEntryForID(SM.getMainFileID()));
114116
auto VectorSTL = Header(*tooling::stdlib::Header::named("<vector>"));
117+
auto UtilitySTL = Header(*tooling::stdlib::Header::named("<utility>"));
115118
EXPECT_THAT(
116119
offsetToProviders(AST, SM),
117120
UnorderedElementsAre(
@@ -122,8 +125,9 @@ TEST_F(WalkUsedTest, Basic) {
122125
Pair(Code.point("foo"), UnorderedElementsAre(HeaderFile)),
123126
Pair(Code.point("vector"), UnorderedElementsAre(VectorSTL)),
124127
Pair(Code.point("vconstructor"), UnorderedElementsAre(VectorSTL)),
125-
Pair(Code.point("v"), UnorderedElementsAre(MainFile))
126-
));
128+
Pair(Code.point("v"), UnorderedElementsAre(MainFile)),
129+
Pair(Code.point("builtin"), testing::IsEmpty()),
130+
Pair(Code.point("move"), UnorderedElementsAre(UtilitySTL))));
127131
}
128132

129133
TEST_F(WalkUsedTest, MultipleProviders) {

0 commit comments

Comments
 (0)