Skip to content

Commit 84f4398

Browse files
committed
Merge from 'master' to 'sycl-web' (#1)
CONFLICT (content): Merge conflict in clang/lib/Sema/SemaDeclAttr.cpp
2 parents 533dffc + fa0320d commit 84f4398

File tree

1,220 files changed

+44064
-16203
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,220 files changed

+44064
-16203
lines changed

clang-tools-extra/clang-tidy/ClangTidyForceLinker.h

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@
1515
namespace clang {
1616
namespace tidy {
1717

18-
// This anchor is used to force the linker to link the CERTModule.
19-
extern volatile int CERTModuleAnchorSource;
20-
static int LLVM_ATTRIBUTE_UNUSED CERTModuleAnchorDestination =
21-
CERTModuleAnchorSource;
22-
2318
// This anchor is used to force the linker to link the AbseilModule.
2419
extern volatile int AbseilModuleAnchorSource;
2520
static int LLVM_ATTRIBUTE_UNUSED AbseilModuleAnchorDestination =
2621
AbseilModuleAnchorSource;
2722

23+
// This anchor is used to force the linker to link the AndroidModule.
24+
extern volatile int AndroidModuleAnchorSource;
25+
static int LLVM_ATTRIBUTE_UNUSED AndroidModuleAnchorDestination =
26+
AndroidModuleAnchorSource;
27+
2828
// This anchor is used to force the linker to link the BoostModule.
2929
extern volatile int BoostModuleAnchorSource;
3030
static int LLVM_ATTRIBUTE_UNUSED BoostModuleAnchorDestination =
@@ -35,20 +35,10 @@ extern volatile int BugproneModuleAnchorSource;
3535
static int LLVM_ATTRIBUTE_UNUSED BugproneModuleAnchorDestination =
3636
BugproneModuleAnchorSource;
3737

38-
// This anchor is used to force the linker to link the LinuxKernelModule.
39-
extern volatile int LinuxKernelModuleAnchorSource;
40-
static int LLVM_ATTRIBUTE_UNUSED LinuxKernelModuleAnchorDestination =
41-
LinuxKernelModuleAnchorSource;
42-
43-
// This anchor is used to force the linker to link the LLVMModule.
44-
extern volatile int LLVMModuleAnchorSource;
45-
static int LLVM_ATTRIBUTE_UNUSED LLVMModuleAnchorDestination =
46-
LLVMModuleAnchorSource;
47-
48-
// This anchor is used to force the linker to link the LLVMLibcModule.
49-
extern volatile int LLVMLibcModuleAnchorSource;
50-
static int LLVM_ATTRIBUTE_UNUSED LLVMLibcModuleAnchorDestination =
51-
LLVMLibcModuleAnchorSource;
38+
// This anchor is used to force the linker to link the CERTModule.
39+
extern volatile int CERTModuleAnchorSource;
40+
static int LLVM_ATTRIBUTE_UNUSED CERTModuleAnchorDestination =
41+
CERTModuleAnchorSource;
5242

5343
// This anchor is used to force the linker to link the CppCoreGuidelinesModule.
5444
extern volatile int CppCoreGuidelinesModuleAnchorSource;
@@ -70,10 +60,25 @@ extern volatile int GoogleModuleAnchorSource;
7060
static int LLVM_ATTRIBUTE_UNUSED GoogleModuleAnchorDestination =
7161
GoogleModuleAnchorSource;
7262

73-
// This anchor is used to force the linker to link the AndroidModule.
74-
extern volatile int AndroidModuleAnchorSource;
75-
static int LLVM_ATTRIBUTE_UNUSED AndroidModuleAnchorDestination =
76-
AndroidModuleAnchorSource;
63+
// This anchor is used to force the linker to link the HICPPModule.
64+
extern volatile int HICPPModuleAnchorSource;
65+
static int LLVM_ATTRIBUTE_UNUSED HICPPModuleAnchorDestination =
66+
HICPPModuleAnchorSource;
67+
68+
// This anchor is used to force the linker to link the LinuxKernelModule.
69+
extern volatile int LinuxKernelModuleAnchorSource;
70+
static int LLVM_ATTRIBUTE_UNUSED LinuxKernelModuleAnchorDestination =
71+
LinuxKernelModuleAnchorSource;
72+
73+
// This anchor is used to force the linker to link the LLVMModule.
74+
extern volatile int LLVMModuleAnchorSource;
75+
static int LLVM_ATTRIBUTE_UNUSED LLVMModuleAnchorDestination =
76+
LLVMModuleAnchorSource;
77+
78+
// This anchor is used to force the linker to link the LLVMLibcModule.
79+
extern volatile int LLVMLibcModuleAnchorSource;
80+
static int LLVM_ATTRIBUTE_UNUSED LLVMLibcModuleAnchorDestination =
81+
LLVMLibcModuleAnchorSource;
7782

7883
// This anchor is used to force the linker to link the MiscModule.
7984
extern volatile int MiscModuleAnchorSource;
@@ -93,6 +98,11 @@ static int LLVM_ATTRIBUTE_UNUSED MPIModuleAnchorDestination =
9398
MPIModuleAnchorSource;
9499
#endif
95100

101+
// This anchor is used to force the linker to link the ObjCModule.
102+
extern volatile int ObjCModuleAnchorSource;
103+
static int LLVM_ATTRIBUTE_UNUSED ObjCModuleAnchorDestination =
104+
ObjCModuleAnchorSource;
105+
96106
// This anchor is used to force the linker to link the OpenMPModule.
97107
extern volatile int OpenMPModuleAnchorSource;
98108
static int LLVM_ATTRIBUTE_UNUSED OpenMPModuleAnchorDestination =
@@ -113,16 +123,6 @@ extern volatile int ReadabilityModuleAnchorSource;
113123
static int LLVM_ATTRIBUTE_UNUSED ReadabilityModuleAnchorDestination =
114124
ReadabilityModuleAnchorSource;
115125

116-
// This anchor is used to force the linker to link the ObjCModule.
117-
extern volatile int ObjCModuleAnchorSource;
118-
static int LLVM_ATTRIBUTE_UNUSED ObjCModuleAnchorDestination =
119-
ObjCModuleAnchorSource;
120-
121-
// This anchor is used to force the linker to link the HICPPModule.
122-
extern volatile int HICPPModuleAnchorSource;
123-
static int LLVM_ATTRIBUTE_UNUSED HICPPModuleAnchorDestination =
124-
HICPPModuleAnchorSource;
125-
126126
// This anchor is used to force the linker to link the ZirconModule.
127127
extern volatile int ZirconModuleAnchorSource;
128128
static int LLVM_ATTRIBUTE_UNUSED ZirconModuleAnchorDestination =

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "SignedCharMisuseCheck.h"
4242
#include "SizeofContainerCheck.h"
4343
#include "SizeofExpressionCheck.h"
44+
#include "SpuriouslyWakeUpFunctionsCheck.h"
4445
#include "StringConstructorCheck.h"
4546
#include "StringIntegerAssignmentCheck.h"
4647
#include "StringLiteralWithEmbeddedNulCheck.h"
@@ -133,6 +134,8 @@ class BugproneModule : public ClangTidyModule {
133134
"bugprone-sizeof-container");
134135
CheckFactories.registerCheck<SizeofExpressionCheck>(
135136
"bugprone-sizeof-expression");
137+
CheckFactories.registerCheck<SpuriouslyWakeUpFunctionsCheck>(
138+
"bugprone-spuriously-wake-up-functions");
136139
CheckFactories.registerCheck<StringConstructorCheck>(
137140
"bugprone-string-constructor");
138141
CheckFactories.registerCheck<StringIntegerAssignmentCheck>(

clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ add_clang_library(clangTidyBugproneModule
3333
SignedCharMisuseCheck.cpp
3434
SizeofContainerCheck.cpp
3535
SizeofExpressionCheck.cpp
36+
SpuriouslyWakeUpFunctionsCheck.cpp
3637
StringConstructorCheck.cpp
3738
StringIntegerAssignmentCheck.cpp
3839
StringLiteralWithEmbeddedNulCheck.cpp
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
//===--- SpuriouslyWakeUpFunctionsCheck.cpp - clang-tidy ------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "SpuriouslyWakeUpFunctionsCheck.h"
10+
#include "clang/AST/ASTContext.h"
11+
#include "clang/ASTMatchers/ASTMatchFinder.h"
12+
13+
using namespace clang::ast_matchers;
14+
15+
namespace clang {
16+
namespace tidy {
17+
namespace bugprone {
18+
19+
void SpuriouslyWakeUpFunctionsCheck::registerMatchers(MatchFinder *Finder) {
20+
21+
auto hasUniqueLock = hasDescendant(declRefExpr(
22+
hasDeclaration(varDecl(hasType(recordDecl(classTemplateSpecializationDecl(
23+
hasName("::std::unique_lock"),
24+
hasTemplateArgument(
25+
0, templateArgument(refersToType(qualType(hasDeclaration(
26+
cxxRecordDecl(hasName("::std::mutex"))))))))))))));
27+
28+
auto hasWaitDescendantCPP = hasDescendant(
29+
cxxMemberCallExpr(
30+
anyOf(
31+
allOf(hasDescendant(memberExpr(hasDeclaration(functionDecl(
32+
allOf(hasName("::std::condition_variable::wait"),
33+
parameterCountIs(1)))))),
34+
onImplicitObjectArgument(
35+
declRefExpr(to(varDecl(hasType(references(recordDecl(
36+
hasName("::std::condition_variable")))))))),
37+
hasUniqueLock),
38+
allOf(hasDescendant(memberExpr(hasDeclaration(functionDecl(
39+
allOf(hasName("::std::condition_variable::wait_for"),
40+
parameterCountIs(2)))))),
41+
onImplicitObjectArgument(
42+
declRefExpr(to(varDecl(hasType(references(recordDecl(
43+
hasName("::std::condition_variable")))))))),
44+
hasUniqueLock),
45+
allOf(hasDescendant(memberExpr(hasDeclaration(functionDecl(
46+
allOf(hasName("::std::condition_variable::wait_until"),
47+
parameterCountIs(2)))))),
48+
onImplicitObjectArgument(
49+
declRefExpr(to(varDecl(hasType(references(recordDecl(
50+
hasName("::std::condition_variable")))))))),
51+
hasUniqueLock)
52+
53+
))
54+
.bind("wait"));
55+
56+
auto hasWaitDescendantC = hasDescendant(
57+
callExpr(callee(functionDecl(
58+
anyOf(hasName("cnd_wait"), hasName("cnd_timedwait")))))
59+
.bind("wait"));
60+
if (getLangOpts().CPlusPlus) {
61+
// Check for `CON54-CPP`
62+
Finder->addMatcher(
63+
ifStmt(
64+
65+
allOf(hasWaitDescendantCPP,
66+
unless(anyOf(hasDescendant(ifStmt(hasWaitDescendantCPP)),
67+
hasDescendant(whileStmt(hasWaitDescendantCPP)),
68+
hasDescendant(forStmt(hasWaitDescendantCPP)),
69+
hasDescendant(doStmt(hasWaitDescendantCPP)))))
70+
71+
),
72+
this);
73+
} else {
74+
// Check for `CON36-C`
75+
Finder->addMatcher(
76+
77+
ifStmt(
78+
allOf(hasWaitDescendantC,
79+
unless(anyOf(hasDescendant(ifStmt(hasWaitDescendantC)),
80+
hasDescendant(whileStmt(hasWaitDescendantC)),
81+
hasDescendant(forStmt(hasWaitDescendantC)),
82+
hasDescendant(doStmt(hasWaitDescendantC)),
83+
hasParent(whileStmt()),
84+
hasParent(compoundStmt(hasParent(whileStmt()))),
85+
hasParent(forStmt()),
86+
hasParent(compoundStmt(hasParent(forStmt()))),
87+
hasParent(doStmt()),
88+
hasParent(compoundStmt(hasParent(doStmt())))))
89+
90+
))
91+
92+
,
93+
this);
94+
}
95+
}
96+
97+
void SpuriouslyWakeUpFunctionsCheck::check(
98+
const MatchFinder::MatchResult &Result) {
99+
const auto *MatchedWait = Result.Nodes.getNodeAs<CallExpr>("wait");
100+
StringRef WaitName = MatchedWait->getDirectCallee()->getName();
101+
diag(MatchedWait->getExprLoc(),
102+
"'%0' should be placed inside a while statement %select{|or used with a "
103+
"conditional parameter}1")
104+
<< WaitName << (WaitName != "cnd_wait" && WaitName != "cnd_timedwait");
105+
}
106+
} // namespace bugprone
107+
} // namespace tidy
108+
} // namespace clang
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//===--- SpuriouslyWakeUpFunctionsCheck.h - clang-tidy ----------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SPURIOUSLYWAKEUPFUNCTIONSCHECK_H
10+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SPURIOUSLYWAKEUPFUNCTIONSCHECK_H
11+
12+
#include "../ClangTidyCheck.h"
13+
14+
namespace clang {
15+
namespace tidy {
16+
namespace bugprone {
17+
18+
/// Finds ``cnd_wait``, ``cnd_timedwait``, ``wait``, ``wait_for``, or
19+
/// ``wait_until`` function calls when the function is not invoked from a loop
20+
/// that checks whether a condition predicate holds or the function has a
21+
/// condition parameter.
22+
///
23+
/// For the user-facing documentation see:
24+
/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone-spuriously-wake-up-functions.html
25+
class SpuriouslyWakeUpFunctionsCheck : public ClangTidyCheck {
26+
public:
27+
SpuriouslyWakeUpFunctionsCheck(StringRef Name, ClangTidyContext *Context)
28+
: ClangTidyCheck(Name, Context) {}
29+
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
30+
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
31+
};
32+
33+
} // namespace bugprone
34+
} // namespace tidy
35+
} // namespace clang
36+
37+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SPURIOUSLYWAKEUPFUNCTIONSCHECK_H

clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "../ClangTidyModuleRegistry.h"
1212
#include "../bugprone/BadSignalToKillThreadCheck.h"
1313
#include "../bugprone/ReservedIdentifierCheck.h"
14+
#include "../bugprone/SpuriouslyWakeUpFunctionsCheck.h"
1415
#include "../bugprone/UnhandledSelfAssignmentCheck.h"
1516
#include "../google/UnnamedNamespaceInHeaderCheck.h"
1617
#include "../misc/NewDeleteOverloadsCheck.h"
@@ -42,6 +43,9 @@ class CERTModule : public ClangTidyModule {
4243
public:
4344
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
4445
// C++ checkers
46+
// CON
47+
CheckFactories.registerCheck<bugprone::SpuriouslyWakeUpFunctionsCheck>(
48+
"cert-con54-cpp");
4549
// DCL
4650
CheckFactories.registerCheck<PostfixOperatorCheck>(
4751
"cert-dcl21-cpp");
@@ -80,6 +84,9 @@ class CERTModule : public ClangTidyModule {
8084
"cert-oop58-cpp");
8185

8286
// C checkers
87+
// CON
88+
CheckFactories.registerCheck<bugprone::SpuriouslyWakeUpFunctionsCheck>(
89+
"cert-con36-c");
8390
// DCL
8491
CheckFactories.registerCheck<misc::StaticAssertCheck>("cert-dcl03-c");
8592
CheckFactories.registerCheck<readability::UppercaseLiteralSuffixCheck>(

clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ add_clang_library(clangTidyLLVMLibcModule
1010
clangBasic
1111
clangLex
1212
clangTidy
13+
clangTidyPortabilityModule
1314
clangTidyUtils
1415
clangTooling
1516
)

clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ namespace llvm_libc {
1818

1919
namespace {
2020

21-
class RestrictedIncludesPPCallbacks : public PPCallbacks {
21+
class RestrictedIncludesPPCallbacks
22+
: public portability::RestrictedIncludesPPCallbacks {
2223
public:
2324
explicit RestrictedIncludesPPCallbacks(
2425
RestrictSystemLibcHeadersCheck &Check, const SourceManager &SM,
2526
const SmallString<128> CompilerIncudeDir)
26-
: Check(Check), SM(SM), CompilerIncudeDir(CompilerIncudeDir) {}
27+
: portability::RestrictedIncludesPPCallbacks(Check, SM),
28+
CompilerIncudeDir(CompilerIncudeDir) {}
2729

2830
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
2931
StringRef FileName, bool IsAngled,
@@ -33,8 +35,6 @@ class RestrictedIncludesPPCallbacks : public PPCallbacks {
3335
SrcMgr::CharacteristicKind FileType) override;
3436

3537
private:
36-
RestrictSystemLibcHeadersCheck &Check;
37-
const SourceManager &SM;
3838
const SmallString<128> CompilerIncudeDir;
3939
};
4040

@@ -45,18 +45,12 @@ void RestrictedIncludesPPCallbacks::InclusionDirective(
4545
bool IsAngled, CharSourceRange FilenameRange, const FileEntry *File,
4646
StringRef SearchPath, StringRef RelativePath, const Module *Imported,
4747
SrcMgr::CharacteristicKind FileType) {
48-
if (SrcMgr::isSystem(FileType)) {
49-
// Compiler provided headers are allowed (e.g stddef.h).
50-
if (SearchPath == CompilerIncudeDir) return;
51-
if (!SM.isInMainFile(HashLoc)) {
52-
Check.diag(
53-
HashLoc,
54-
"system libc header %0 not allowed, transitively included from %1")
55-
<< FileName << SM.getFilename(HashLoc);
56-
} else {
57-
Check.diag(HashLoc, "system libc header %0 not allowed") << FileName;
58-
}
59-
}
48+
// Compiler provided headers are allowed (e.g stddef.h).
49+
if (SrcMgr::isSystem(FileType) && SearchPath == CompilerIncudeDir)
50+
return;
51+
portability::RestrictedIncludesPPCallbacks::InclusionDirective(
52+
HashLoc, IncludeTok, FileName, IsAngled, FilenameRange, File, SearchPath,
53+
RelativePath, Imported, FileType);
6054
}
6155

6256
void RestrictSystemLibcHeadersCheck::registerPPCallbacks(

clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.h

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

1212
#include "../ClangTidyCheck.h"
13+
#include "../portability/RestrictSystemIncludesCheck.h"
1314

1415
namespace clang {
1516
namespace tidy {
@@ -20,10 +21,11 @@ namespace llvm_libc {
2021
///
2122
/// For the user-facing documentation see:
2223
/// http://clang.llvm.org/extra/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.html
23-
class RestrictSystemLibcHeadersCheck : public ClangTidyCheck {
24+
class RestrictSystemLibcHeadersCheck
25+
: public portability::RestrictSystemIncludesCheck {
2426
public:
2527
RestrictSystemLibcHeadersCheck(StringRef Name, ClangTidyContext *Context)
26-
: ClangTidyCheck(Name, Context) {}
28+
: portability::RestrictSystemIncludesCheck(Name, Context, "-*") {}
2729
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
2830
Preprocessor *ModuleExpanderPP) override;
2931
};

clang-tools-extra/clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ void UnconventionalAssignOperatorCheck::check(
7575
} else {
7676
static const char *const Messages[][2] = {
7777
{"ReturnType", "operator=() should return '%0&'"},
78-
{"ArgumentType", "operator=() should take '%0 const&', '%0&&' or '%0'"},
78+
{"ArgumentType",
79+
getLangOpts().CPlusPlus11
80+
? "operator=() should take '%0 const&', '%0&&' or '%0'"
81+
: "operator=() should take '%0 const&' or '%0'"},
7982
{"cv", "operator=() should not be marked '%1'"}};
8083

8184
const auto *Method = Result.Nodes.getNodeAs<CXXMethodDecl>("method");

0 commit comments

Comments
 (0)